Mercurial > repos > drosofff > msp_sr_bowtie_parser
comparison sRbowtieParser.py @ 0:b996480cd604 draft
planemo upload for repository https://bitbucket.org/drosofff/gedtools/
| author | drosofff |
|---|---|
| date | Wed, 27 May 2015 17:19:15 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:b996480cd604 |
|---|---|
| 1 #!/usr/bin/python | |
| 2 # python parser module to analyse sRbowtie alignments | |
| 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> | |
| 5 | |
| 6 import sys, argparse | |
| 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) | |
| 12 | |
| 13 def Parser(): | |
| 14 the_parser = argparse.ArgumentParser() | |
| 15 the_parser.add_argument('--IndexSource', action="store", type=str, help="Path to the index source") | |
| 16 the_parser.add_argument('--ExtractDirective', action="store", type=str, choices=["fastaSource", "bowtieIndex"], help="Extract info from fasta or bowtie index") | |
| 17 the_parser.add_argument('--output', action="store", type=str, help="path to the output") | |
| 18 the_parser.add_argument('--polarity', choices=["forward", "reverse", "both"], help="forward, reverse or both forward an reverse reads are counted") | |
| 19 the_parser.add_argument('--alignmentSource',nargs='+', help="paths to alignments files") | |
| 20 the_parser.add_argument('--alignmentFormat',nargs='+', help="Format of the bowtie alignment (tabular, sam or bam)") | |
| 21 the_parser.add_argument('--alignmentLabel',nargs='+', help="Label of the alignment") | |
| 22 args = the_parser.parse_args() | |
| 23 return args | |
| 24 | |
| 25 args = Parser() | |
| 26 | |
| 27 IndexSource = args.IndexSource | |
| 28 genomeRefFormat = args.ExtractDirective | |
| 29 Output = args.output | |
| 30 Polarity = args.polarity | |
| 31 header = ["gene"] | |
| 32 | |
| 33 | |
| 34 FileLabelList=[label for label in args.alignmentLabel] | |
| 35 header.extend(FileLabelList) | |
| 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 | |
| 48 | |
| 49 F = open (args.output, "w") | |
| 50 # print >>F, args | |
| 51 print >> F, "\t".join(header) | |
| 52 | |
| 53 for item in sorted(gene_count_dict.keys()): | |
| 54 line=[item] | |
| 55 line.extend(gene_count_dict[item]) | |
| 56 print >> F, "\t".join(line ) | |
| 57 F.close() |
