Esempio n. 1
0
if unfiltered == 't':
    print('Saving CoGe-formatted unfiltered file to:\n',
          coge_unfiltered_path)

# Create an output for CoGe upload

if min_coverage:
    coge_filtered_csv = open(coge_filtered_path, 'w')
    coge_formatted_filtered = csv.writer(coge_filtered_csv)
if unfiltered == 't':
    coge_unfiltered_csv = open(coge_unfiltered_path, 'w')
    coge_formatted_unfiltered = csv.writer(coge_unfiltered_csv)

# Iterate over the dictionary for file-outputs

for chrm in bismark_data:
    for pos in bismark_data[chrm]:
        chrm_key = fix_chromosome_id(chrm)
        pos_key = int(pos) - 1  # Subtract 1 from position to fix alignment with sequence in CoGe
        dec_met = bismark_data[chrm][pos]['dec_met']
        total = bismark_data[chrm][pos]['total']
        strand = bismark_data[chrm][pos]['strand']
        if min_coverage and total >= min_coverage:
            coge_formatted_filtered.writerow(
                [chrm_key, pos_key, pos_key, strand, dec_met, total])  # Output as filtered .csv file
        if unfiltered == 't':
            coge_formatted_unfiltered.writerow(
                [chrm_key, pos_key, pos_key, strand, dec_met, total])  # Output as unfiltered .csv file

print('\nDone!')
Esempio n. 2
0
methylKit_formatted = open(methyl_path, 'r')
methylation_summary = csv.reader(methylKit_formatted, delimiter='\t')

if min_coverage:
    coge_filtered_csv = open(coge_filtered_path, 'w')
    coge_formatted_filtered = csv.writer(coge_filtered_csv)
if unfiltered == 't':
    coge_unfiltered_csv = open(coge_unfiltered_path, 'w')
    coge_formatted_unfiltered = csv.writer(coge_unfiltered_csv)

# Write to output files depending on coverage filtered or not

next(methylation_summary)  # Skip header

for row in methylation_summary:
    chrm = fix_chromosome_id(row[1])
    pos = int(row[2]) - 1
    strand = row[3]
    if strand == 'F':
        strand = '1'
    elif strand == 'R':
        strand = '-1'
    coverage = int(row[4])
    dec_met = row[5]
    if min_coverage and coverage >= min_coverage:
        coge_formatted_filtered.writerow(
                [chrm, pos, pos, strand, dec_met, coverage])  # Output as filtered .csv file
    if unfiltered == 't':
        coge_formatted_unfiltered.writerow(
                [chrm, pos, pos, strand, dec_met, coverage])  # Output as unfiltered .csv file