Created
September 2, 2014 18:58
-
-
Save cplaisier/22490da8e7a81f84c0c8 to your computer and use it in GitHub Desktop.
Converting Files from htseq-count to Matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from subprocess import * | |
| from shutil import move | |
| import os | |
| # Read in manifest of samples to process | |
| samples = [] | |
| inFile = open('manifest.csv','r') | |
| while 1: | |
| line = inFile.readline() | |
| if not line: | |
| break | |
| splitUp = line.strip().split(',') | |
| samples.append(splitUp[0]) | |
| inFile.close() | |
| # Read in all *.transcripts.gtf files | |
| gexpMatrix = {} # gexpMatrix[transcript][sample] = {'coverage':<>, 'FPKM':<>} | |
| for sample in samples: | |
| print 'Reading',sample,'...' | |
| inFile = open('output/'+sample+'Aligned.out.counts','r') | |
| while 1: | |
| line = inFile.readline() | |
| if not line: | |
| break | |
| splitUp = line.strip().split('\t') | |
| if not splitUp[0] in gexpMatrix: | |
| gexpMatrix[splitUp[0]] = {} | |
| gexpMatrix[splitUp[0]][sample] = splitUp[1] | |
| inFile.close() | |
| print 'Done reading files.' | |
| print 'Starting writing coverage...' | |
| # Dump out matrix of coverages | |
| outFile = open('output/gexp_counts.csv','w') | |
| outFile.write('UCSC_transcript_id,'+','.join(samples)+'\n') | |
| outFile.write('\n'.join([transcript+','+','.join([gexpMatrix[transcript][sample] for sample in samples]) for transcript in gexpMatrix])) | |
| outFile.close() | |
| print 'Done.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment