Mercurial > repos > drosofff > msp_sr_readmap_and_size_histograms
comparison readmap.py @ 18:893560ece89f draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit 9237338d798251fb2667280d597746e852f3ffcc-dirty
author | mvdbeek |
---|---|
date | Wed, 03 Feb 2016 11:34:35 -0500 |
parents | a118d511a27c |
children | f75315939afe |
comparison
equal
deleted
inserted
replaced
17:a118d511a27c | 18:893560ece89f |
---|---|
75 """ | 75 """ |
76 gene, coordinate, count, orientation = item.split("\t") | 76 gene, coordinate, count, orientation = item.split("\t") |
77 return gene, coordinate, count, orientation | 77 return gene, coordinate, count, orientation |
78 | 78 |
79 def lookup_gene_length(gene, readDict): | 79 def lookup_gene_length(gene, readDict): |
80 return readDict[readDict.keys()[0]].instanceDict["size"] | 80 return readDict[readDict.keys()[0]].instanceDict.values()[0].size |
81 | 81 |
82 def handle_start_stop_coordinates(plottable, readDict): | 82 def handle_start_stop_coordinates(plottable, readDict): |
83 """ | 83 """ |
84 To ensure that the plot area always includes the correct start and end coordinates, | 84 To ensure that the plot area always includes the correct start and end coordinates, |
85 we add an entry at start [coordinate 0] and end [last coordinate] of count 0, if these do not exist. | 85 we add an entry at start [coordinate 0] and end [last coordinate] of count 0, if these do not exist. |
89 gene, coordinate, count, orientation = listify_plottable_item(first_line) | 89 gene, coordinate, count, orientation = listify_plottable_item(first_line) |
90 if not coordinate == "0": | 90 if not coordinate == "0": |
91 new_line = "\t".join([gene, "0", "0", "F"]) | 91 new_line = "\t".join([gene, "0", "0", "F"]) |
92 plottable = [new_line] + plottable | 92 plottable = [new_line] + plottable |
93 gene_length = str(lookup_gene_length(gene, readDict)) | 93 gene_length = str(lookup_gene_length(gene, readDict)) |
94 gene, coordinate, count, orientation = listify_plottable_item(last_line) | |
94 if not coordinate == gene_length: | 95 if not coordinate == gene_length: |
95 last_line = "\t".join([gene, gene_length, "0", "F"]) | 96 last_line = "\t".join([gene, gene_length, "0", "F"]) |
96 plottable = plottable + [last_line] | 97 plottable = plottable + [last_line] |
98 return plottable | |
97 | 99 |
98 def write_readplot_dataframe(readDict, readmap_file): | 100 def write_readplot_dataframe(readDict, readmap_file): |
99 listoflines = [] | 101 listoflines = [] |
100 with open(readmap_file, 'w') as readmap: | 102 with open(readmap_file, 'w') as readmap: |
101 print >>readmap, "gene\tcoord\tcount\tpolarity\tsample" | 103 print >>readmap, "gene\tcoord\tcount\tpolarity\tsample" |
104 dict=readDict[sample] | 106 dict=readDict[sample] |
105 else: | 107 else: |
106 dict=readDict[sample].instanceDict | 108 dict=readDict[sample].instanceDict |
107 for gene in dict.keys(): | 109 for gene in dict.keys(): |
108 plottable = dict[gene].readplot() | 110 plottable = dict[gene].readplot() |
109 handle_start_stop_coordinates(plottable, readDict) | 111 plottable = handle_start_stop_coordinates(plottable, readDict) |
110 for line in plottable: | 112 for line in plottable: |
111 #print >>readmap, "%s\t%s" % (line, sample) | 113 #print >>readmap, "%s\t%s" % (line, sample) |
112 listoflines.append ("%s\t%s" % (line, sample)) | 114 listoflines.append ("%s\t%s" % (line, sample)) |
113 listoflines = dataframe_sanityzer(listoflines) | 115 listoflines = dataframe_sanityzer(listoflines) |
114 for line in listoflines: | 116 for line in listoflines: |