Skip to content

Instantly share code, notes, and snippets.

@afrendeiro
Created June 18, 2013 22:36
Show Gist options
  • Save afrendeiro/5810116 to your computer and use it in GitHub Desktop.
Save afrendeiro/5810116 to your computer and use it in GitHub Desktop.
Parses output from Cufflinks' cuffdiff averaging two samples. Outputs tab-delimited csv files (log2 transformed and not).
#!/usr/bin/python
from sys import argv
import csv,StringIO
import math
expr = open(argv[1], 'r')
output = open(argv[1] + '.bed','w')
output_log = open(argv[1] + '_log2.bed','w')
for i, line in enumerate(expr):
if i == 0:
print "Doing...."
else:
row = line.split('\t')
gene_id = row[1]
locus = row[3]
value_1 = row[7]
value_2 = row[8]
ave = ((float(value_1) + float(value_2)) / 2)
ave_log = (math.log(1+(float(value_1) + float(value_2)) / 2,2))
chrom, coord = locus.split(':')
start, end = coord.split('-')
out = [chrom, start, end, gene_id, ave]
out_log = [chrom, start, end, gene_id, ave_log]
wr = csv.writer(output, delimiter='\t')
wr.writerow(out)
output.close()
print """Done.
Created .bed files in current directory.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment