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