Mercurial > repos > drosofff > msp_sr_bowtie_parser
comparison sRbowtieParser.py @ 2:70193ce0540e draft
planemo upload for repository https://bitbucket.org/drosofff/gedtools/
author | mvdbeek |
---|---|
date | Thu, 11 Jun 2015 10:15:20 -0400 |
parents | 3a510730e3fc |
children |
comparison
equal
deleted
inserted
replaced
1:f5388910d083 | 2:70193ce0540e |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # python parser module to analyse sRbowtie alignments | 2 # python parser module to analyse sRbowtie alignments |
3 # version 1.0.0 - argparse implementation | 3 # version 1.0.2 - argparse implementation |
4 # Usage sRbowtieParser.py <1:index source> <2:extraction directive> <3:outputL> <4:polarity> <5:6:7 filePath:FileExt:FileLabel> <.. ad lib> | 4 # Usage sRbowtieParser.py <1:index source> <2:extraction directive> <3:outputL> <4:polarity> <5:6:7 filePath:FileExt:FileLabel> <.. ad lib> |
5 | 5 |
6 import sys, argparse | 6 import sys, argparse |
7 from smRtools import * | 7 from smRtools import * |
8 | |
9 def masterListGenerator(data_source): | |
10 for filePath, FileExt, FileLabel in data_source: | |
11 yield HandleSmRNAwindows (filePath, FileExt, IndexSource, genomeRefFormat) | |
8 | 12 |
9 def Parser(): | 13 def Parser(): |
10 the_parser = argparse.ArgumentParser() | 14 the_parser = argparse.ArgumentParser() |
11 the_parser.add_argument('--IndexSource', action="store", type=str, help="Path to the index source") | 15 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") | 16 the_parser.add_argument('--ExtractDirective', action="store", type=str, choices=["fastaSource", "bowtieIndex"], help="Extract info from fasta or bowtie index") |
22 | 26 |
23 IndexSource = args.IndexSource | 27 IndexSource = args.IndexSource |
24 genomeRefFormat = args.ExtractDirective | 28 genomeRefFormat = args.ExtractDirective |
25 Output = args.output | 29 Output = args.output |
26 Polarity = args.polarity | 30 Polarity = args.polarity |
27 MasterListOfGenomes = {} | 31 header = ["gene"] |
28 | 32 |
29 for filePath, FileExt, FileLabel in zip (args.alignmentSource, args.alignmentFormat, args.alignmentLabel): | |
30 MasterListOfGenomes[FileLabel] = HandleSmRNAwindows (filePath, FileExt, IndexSource, genomeRefFormat) | |
31 | 33 |
32 header = ["gene"] | 34 FileLabelList=[label for label in args.alignmentLabel] |
33 for filePath, FileExt, FileLabel in zip (args.alignmentSource, args.alignmentFormat, args.alignmentLabel): | 35 header.extend(FileLabelList) |
34 header.append(FileLabel) | 36 assert (len(FileLabelList)==len(set(FileLabelList))),"You have supplied a non-unique label. Please make sure that your input files have unique names" |
37 | |
38 data_source=zip (args.alignmentSource, args.alignmentFormat, args.alignmentLabel) | |
39 master_generator=masterListGenerator(data_source) | |
40 | |
41 for i,window in enumerate(master_generator): | |
42 window=window | |
43 if i==0: | |
44 gene_count_dict={gene:[str(item.readcount(polarity=Polarity))] for gene,item in window.instanceDict.items()} | |
45 else: | |
46 [gene_count_dict[gene].append(str(item.readcount(polarity=Polarity))) for gene,item in window.instanceDict.items()] | |
47 | |
35 | 48 |
36 F = open (args.output, "w") | 49 F = open (args.output, "w") |
37 # print >>F, args | 50 # print >>F, args |
38 print >> F, "\t".join(header) | 51 print >> F, "\t".join(header) |
39 for item in sorted (MasterListOfGenomes[header[1]].instanceDict.keys() ): | 52 |
53 for item in sorted(gene_count_dict.keys()): | |
40 line=[item] | 54 line=[item] |
41 for sample in header[1:]: | 55 line.extend(gene_count_dict[item]) |
42 count = str (MasterListOfGenomes[sample].instanceDict[item].readcount(polarity=Polarity)) | |
43 line.append(count) | |
44 print >> F, "\t".join(line ) | 56 print >> F, "\t".join(line ) |
45 F.close() | 57 F.close() |