annotate sRbowtieParser.py @ 0:3a510730e3fc draft

Imported from capsule None
author drosofff
date Mon, 03 Nov 2014 10:27:20 -0500
parents
children 70193ce0540e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
1 #!/usr/bin/python
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
2 # python parser module to analyse sRbowtie alignments
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
3 # version 1.0.0 - argparse implementation
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
4 # Usage sRbowtieParser.py <1:index source> <2:extraction directive> <3:outputL> <4:polarity> <5:6:7 filePath:FileExt:FileLabel> <.. ad lib>
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
5
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
6 import sys, argparse
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
7 from smRtools import *
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
8
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
9 def Parser():
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
10 the_parser = argparse.ArgumentParser()
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
11 the_parser.add_argument('--IndexSource', action="store", type=str, help="Path to the index source")
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
12 the_parser.add_argument('--ExtractDirective', action="store", type=str, choices=["fastaSource", "bowtieIndex"], help="Extract info from fasta or bowtie index")
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
13 the_parser.add_argument('--output', action="store", type=str, help="path to the output")
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
14 the_parser.add_argument('--polarity', choices=["forward", "reverse", "both"], help="forward, reverse or both forward an reverse reads are counted")
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
15 the_parser.add_argument('--alignmentSource',nargs='+', help="paths to alignments files")
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
16 the_parser.add_argument('--alignmentFormat',nargs='+', help="Format of the bowtie alignment (tabular, sam or bam)")
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
17 the_parser.add_argument('--alignmentLabel',nargs='+', help="Label of the alignment")
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
18 args = the_parser.parse_args()
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
19 return args
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
20
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
21 args = Parser()
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
22
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
23 IndexSource = args.IndexSource
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
24 genomeRefFormat = args.ExtractDirective
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
25 Output = args.output
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
26 Polarity = args.polarity
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
27 MasterListOfGenomes = {}
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
28
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
29 for filePath, FileExt, FileLabel in zip (args.alignmentSource, args.alignmentFormat, args.alignmentLabel):
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
30 MasterListOfGenomes[FileLabel] = HandleSmRNAwindows (filePath, FileExt, IndexSource, genomeRefFormat)
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
31
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
32 header = ["gene"]
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
33 for filePath, FileExt, FileLabel in zip (args.alignmentSource, args.alignmentFormat, args.alignmentLabel):
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
34 header.append(FileLabel)
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
35
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
36 F = open (args.output, "w")
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
37 # print >>F, args
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
38 print >> F, "\t".join(header)
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
39 for item in sorted (MasterListOfGenomes[header[1]].instanceDict.keys() ):
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
40 line=[item]
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
41 for sample in header[1:]:
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
42 count = str (MasterListOfGenomes[sample].instanceDict[item].readcount(polarity=Polarity))
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
43 line.append(count)
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
44 print >> F, "\t".join(line )
3a510730e3fc Imported from capsule None
drosofff
parents:
diff changeset
45 F.close()