# HG changeset patch # User mvdbeek # Date 1454508493 18000 # Node ID 70f4385534f96a63fcb9f1b7bb7f218219c0ab55 # Parent 16d0811f7a091bf6d20ae336eff361b39d99f2e9 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_sr_readmap_and_size_histograms commit c400846f3ef40a5cbaa373d2ca7c93fb05ecd20c-dirty diff -r 16d0811f7a09 -r 70f4385534f9 readmap.py --- a/readmap.py Tue Feb 02 15:28:12 2016 -0500 +++ b/readmap.py Wed Feb 03 09:08:13 2016 -0500 @@ -66,6 +66,35 @@ filtered_list.append(line) return filtered_list + +def listify_plottable_item(item): + """ + plottable is a list of strings: + 'FBti0020401\t78\t-1.0\tR' + split on tab and return gene, coordinate, count and orientation + """ + gene, coordinate, count, orientation = item.split("\t") + return gene, coordinate, count, orientation + +def lookup_gene_length(gene, readDict): + return readDict[readDict.keys()[0]].instanceDict["size"] + +def handle_start_stop_coordinates(plottable, readDict): + """ + To ensure that the plot area always includes the correct start and end coordinates, + we add an entry at start [coordinate 0] and end [last coordinate] of count 0, if these do not exist. + """ + first_line = plottable[0] + last_line = plottable[-1] + gene, coordinate, count, orientation = listify_plottable_item(first_line) + if not coordinate == "0": + new_line = "\t".join([gene, "0", "0", "F"]) + plottable = new_line + plottable + gene_length = str(lookup_gene_length(gene, readDict)) + if not coordinate == gene_length: + last_line = "\t".join([gene, gene_length, "0", "F"]) + plottable = plottable + last_line + def write_readplot_dataframe(readDict, readmap_file): listoflines = [] with open(readmap_file, 'w') as readmap: @@ -77,6 +106,7 @@ dict=readDict[sample].instanceDict for gene in dict.keys(): plottable = dict[gene].readplot() + handle_start_stop_coordinates(plottable, readDict) for line in plottable: #print >>readmap, "%s\t%s" % (line, sample) listoflines.append ("%s\t%s" % (line, sample)) diff -r 16d0811f7a09 -r 70f4385534f9 readmap.xml --- a/readmap.xml Tue Feb 02 15:28:12 2016 -0500 +++ b/readmap.xml Wed Feb 03 09:08:13 2016 -0500 @@ -1,4 +1,4 @@ - + from sRbowtie aligment bowtie diff -r 16d0811f7a09 -r 70f4385534f9 smRtools.pyc Binary file smRtools.pyc has changed