annotate readmap.py @ 23:d6b93af0da55 draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit 89caea4594db1ae6d6bb9c651bc6019bb6dd3ce6-dirty
author mvdbeek
date Sun, 24 Apr 2016 09:23:44 -0400
parents f75315939afe
children bf7388df53cf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
1 #!/usr/bin/python
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
2 # python parser module for for readmaps and size distributions, guided by GFF3
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
3 # version 0.9.1 (1-6-2014)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
4 # Usage readmap.py <1:index source> <2:extraction directive> <3:output pre-mir> <4: output mature miRs> <5:mirbase GFF3>
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
5 # <6:pathToLatticeDataframe or "dummy_dataframe_path"> <7:Rcode or "dummy_plotCode"> <8:latticePDF or "dummy_latticePDF">
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
6 # <9:10:11 filePath:FileExt:FileLabel> <.. ad lib>
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
7
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
8 import sys, subprocess, argparse
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
9 from smRtools import *
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
10 from collections import OrderedDict, defaultdict
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
11 import os
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
12
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
13 def Parser():
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
14 the_parser = argparse.ArgumentParser()
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
15 the_parser.add_argument('--output_readmap', action="store", type=str, help="readmap dataframe")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
16 the_parser.add_argument('--output_size_distribution', action="store", type=str, help="size distribution dataframe")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
17 the_parser.add_argument('--reference_fasta', action="store", type=str, help="output file")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
18 the_parser.add_argument('--reference_bowtie_index',action='store', help="paths to indexed or fasta references")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
19 the_parser.add_argument('--input',nargs='+', help="paths to multiple input files")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
20 the_parser.add_argument('--ext',nargs='+', help="input file type")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
21 the_parser.add_argument('--label',nargs='+', help="labels of multiple input files")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
22 the_parser.add_argument('--normalization_factor',nargs='+', type=float, help="Normalization factor for input file")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
23 the_parser.add_argument('--gff', type=str, help="GFF containing regions of interest")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
24 the_parser.add_argument('--minquery', type=int, help="Minimum readsize")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
25 the_parser.add_argument('--maxquery', type=int, help="Maximum readsize")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
26 args = the_parser.parse_args()
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
27 return args
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
28
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
29 args=Parser()
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
30 if args.reference_fasta:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
31 genomeRefFormat = "fastaSource"
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
32 genomeRefFile = args.reference_fasta
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
33 if args.reference_bowtie_index:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
34 genomeRefFormat = "bowtieIndex"
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
35 genomeRefFile = args.reference_bowtie_index
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
36 readmap_file=args.output_readmap
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
37 size_distribution_file=args.output_size_distribution
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
38 minquery=args.minquery
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
39 maxquery=args.maxquery
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
40 filePath=args.input
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
41 fileExt=args.ext
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
42 fileLabel=args.label
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
43 normalization_factor=args.normalization_factor
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
44
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
45 MasterListOfGenomes = OrderedDict()
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
46
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
47 def process_samples(filePath):
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
48 for i, filePath in enumerate(filePath):
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
49 norm=normalization_factor[i]
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
50 print fileLabel[i]
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
51 MasterListOfGenomes[fileLabel[i]] = HandleSmRNAwindows (alignmentFile=filePath, alignmentFileFormat=fileExt[i], genomeRefFile=genomeRefFile, genomeRefFormat=genomeRefFormat,\
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
52 biosample=fileLabel[i], size_inf=minquery, size_sup=maxquery, norm=norm)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
53 return MasterListOfGenomes
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
54
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
55 def dataframe_sanityzer (listofdatalines):
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
56 Dict = defaultdict(float)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
57 for line in listofdatalines:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
58 fields= line.split("\t")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
59 Dict[fields[0]] += float (fields[2])
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
60 filtered_list = []
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
61 for line in listofdatalines:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
62 fields= line.split("\t")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
63 if Dict[fields[0]] != 0:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
64 filtered_list.append(line)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
65 return filtered_list
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
66
16
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
67
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
68 def listify_plottable_item(item):
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
69 """
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
70 plottable is a list of strings:
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
71 'FBti0020401\t78\t-1.0\tR'
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
72 split on tab and return gene, coordinate, count and orientation
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
73 """
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
74 gene, coordinate, count, orientation = item.split("\t")
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
75 return gene, coordinate, count, orientation
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
76
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
77 def lookup_gene_length(gene, readDict):
19
f75315939afe planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit 9237338d798251fb2667280d597746e852f3ffcc-dirty
drosofff
parents: 18
diff changeset
78 return readDict[readDict.keys()[0]].instanceDict[gene].size
16
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
79
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
80 def handle_start_stop_coordinates(plottable, readDict):
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
81 """
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
82 To ensure that the plot area always includes the correct start and end coordinates,
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
83 we add an entry at start [coordinate 0] and end [last coordinate] of count 0, if these do not exist.
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
84 """
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
85 first_line = plottable[0]
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
86 last_line = plottable[-1]
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
87 gene, coordinate, count, orientation = listify_plottable_item(first_line)
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
88 if not coordinate == "0":
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
89 new_line = "\t".join([gene, "0", "0", "F"])
17
a118d511a27c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit 032b3f084f3b2a6d42ba476ef55f4de593b58606-dirty
mvdbeek
parents: 16
diff changeset
90 plottable = [new_line] + plottable
16
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
91 gene_length = str(lookup_gene_length(gene, readDict))
18
893560ece89f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit 9237338d798251fb2667280d597746e852f3ffcc-dirty
mvdbeek
parents: 17
diff changeset
92 gene, coordinate, count, orientation = listify_plottable_item(last_line)
16
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
93 if not coordinate == gene_length:
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
94 last_line = "\t".join([gene, gene_length, "0", "F"])
17
a118d511a27c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit 032b3f084f3b2a6d42ba476ef55f4de593b58606-dirty
mvdbeek
parents: 16
diff changeset
95 plottable = plottable + [last_line]
18
893560ece89f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit 9237338d798251fb2667280d597746e852f3ffcc-dirty
mvdbeek
parents: 17
diff changeset
96 return plottable
16
70f4385534f9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty
mvdbeek
parents: 0
diff changeset
97
0
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
98 def write_readplot_dataframe(readDict, readmap_file):
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
99 listoflines = []
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
100 with open(readmap_file, 'w') as readmap:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
101 print >>readmap, "gene\tcoord\tcount\tpolarity\tsample"
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
102 for sample in readDict.keys():
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
103 if args.gff:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
104 dict=readDict[sample]
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
105 else:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
106 dict=readDict[sample].instanceDict
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
107 for gene in dict.keys():
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
108 plottable = dict[gene].readplot()
18
893560ece89f planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit 9237338d798251fb2667280d597746e852f3ffcc-dirty
mvdbeek
parents: 17
diff changeset
109 plottable = handle_start_stop_coordinates(plottable, readDict)
0
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
110 for line in plottable:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
111 #print >>readmap, "%s\t%s" % (line, sample)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
112 listoflines.append ("%s\t%s" % (line, sample))
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
113 listoflines = dataframe_sanityzer(listoflines)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
114 for line in listoflines:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
115 print >>readmap, line
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
116
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
117 def write_size_distribution_dataframe(readDict, size_distribution_file):
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
118 listoflines = []
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
119 with open(size_distribution_file, 'w') as size_distrib:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
120 print >>size_distrib, "gene\tsize\tcount\tpolarity\tsample" # test before was "gene\tpolarity\tsize\tcount\tsample"
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
121 for sample in readDict.keys():
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
122 if args.gff:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
123 dict=readDict[sample]
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
124 else:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
125 dict=readDict[sample].instanceDict
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
126 for gene in dict.keys():
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
127 histogram = dict[gene].size_histogram(minquery=args.minquery, maxquery=args.maxquery)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
128 for polarity in histogram.keys():
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
129 if polarity=='both':
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
130 continue
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
131 #for size in xrange(args.minquery, args.maxquery):
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
132 # if not size in histogram[polarity].keys():
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
133 # histogram[size]=0
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
134 for size, count in histogram[polarity].iteritems():
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
135 #print >>size_distrib, "%s\t%s\t%s\t%s\t%s" % (gene, size, count, polarity, sample) # test, changed the order accordingly
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
136 listoflines.append ("%s\t%s\t%s\t%s\t%s" % (gene, size, count, polarity, sample) )
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
137 listoflines = dataframe_sanityzer(listoflines)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
138 for line in listoflines:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
139 print >>size_distrib, line
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
140
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
141 def gff_item_subinstances(readDict, gff3):
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
142 GFFinstanceDict=OrderedDict()
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
143 for sample in readDict.keys():
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
144 GFFinstanceDict[sample]={} # to implement the 2nd level of directionary in an OrderedDict Class object (would not be required with defaultdict Class)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
145 with open(gff3) as gff:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
146 for line in gff:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
147 if line[0] == "#": continue
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
148 gff_fields = line[:-1].split("\t")
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
149 chrom = gff_fields[0]
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
150 gff_name = gff_fields[-1].split("Name=")[-1].split(";")[0] # to isolate the GFF Name
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
151 item_upstream_coordinate = int(gff_fields[3])
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
152 item_downstream_coordinate = int(gff_fields[4])
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
153 item_polarity = gff_fields[6]
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
154 for sample in readDict.keys():
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
155 subinstance=extractsubinstance(item_upstream_coordinate, item_downstream_coordinate, readDict[sample].instanceDict[chrom])
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
156 if item_polarity == '-':
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
157 subinstance.readDict={key*-1:value for key, value in subinstance.readDict.iteritems()}
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
158 subinstance.gene=gff_name
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
159 GFFinstanceDict[sample][gff_name]=subinstance
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
160 return GFFinstanceDict
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
161
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
162 MasterListOfGenomes=process_samples(filePath)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
163
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
164 if args.gff:
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
165 MasterListOfGenomes=gff_item_subinstances(MasterListOfGenomes, args.gff)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
166
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
167 write_readplot_dataframe(MasterListOfGenomes, readmap_file)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
168 write_size_distribution_dataframe(MasterListOfGenomes, size_distribution_file)
9af9983dcd02 Imported from capsule None
drosofff
parents:
diff changeset
169