def cycles_vs_align_len(classData, blastPath, floworder): pylab.clf() l = [] c = [] for rowcol,leng,dif,seq in classData: t = template.deseqify(remove_spaces(seq), floworder) l.append(dif) c.append(len(t)/4) pylab.scatter(l,c) if "/" in blastPath: p = blastPath.strip().split("/")[-1] path = p.strip().split(".")[0] else: path = blastPath.strip().split(",")[0] if 'blastn' in path: pretitle = 'Relaxed Blast' if 'megablast' in path: pretitle = 'Strict Blast' pylab.title("%s Number of Flows vs. Alignment Length" % pretitle) pylab.xlabel("Length") pylab.ylabel("Flows") pylab.gcf().set_size_inches((8,4)) pylab.axis([0,max(l)+10,0,max(c)+10]) #x = [2.2*i for i in range(max(l))] #pylab.plot(x) pylab.savefig("alignment_vs_cycles_%s.png" % path) pylab.clf()
def get_ionograms(rowCollist, outfolder, alignmenthtml, sffIn, alignstringfill, byLength, space_string, key, floworder): filelist = {} alignhtml = {} for i in rowCollist: rowcol = i[0] row = rowcol[0] col = rowcol[1] fin = Popen("SFFRead %s -C %s -R %s" % (sffIn,col,row), shell=True, stdout=PIPE) ionogram = fin.stdout.read() ionogram = ionogram.strip() ionogram = ionogram.split(" ") ionogram = [float(i) for i in ionogram] s = alignstringfill[rowcol][0] expected = [] lenOfIon = len(ionogram) l = length(str(s.strip())) alignhtml[rowcol] = check_for_alignment(ionogram, alignstringfill, rowcol, floworder, key) fskey = template.deseqify(key, floworder) expected = fskey + list(pylab.zeros(lenOfIon-len(fskey))) intexp = [] for i in expected: intexp.append(int(i)) expected = intexp titleString = 'Single-Well Ionogram for (%s,%s) Length=%s Bases' % (int(row), int(col), l) it = plotters.IonogramJMR(floworder, expected[:len(ionogram)],ionogram,titleString) it.render() filelist[rowcol] = ("Well_(%s,%s).png" % (int(row),int(col))) pylab.savefig(outfolder + "/Well_(%s,%s).png" % (int(row),int(col))) generateWeb(alignhtml, filelist, outfolder, space_string, rowCollist)
def plot(self): num = 1 numGraphs = math.ceil(math.sqrt(self.get_num_graphs())) Rows = int(numGraphs) Cols = int(numGraphs) pylab.clf() fig = pylab.figure(1, figsize=(Rows, Cols)) flowspacekey = template.deseqify(self.key[: len(self.key) - 1], self.floworder) flowspacekey = flowspacekey[: len(flowspacekey) - 1] for region, data in self.data.iteritems(): # ATCG 01001011 trace = {} flowstring = [self.floworder[n % len(self.floworder)] for n in range(len(flowspacekey))] flowstring = "".join(flowstring) flowstring = flowstring for n, base in enumerate(list(self.floworder)): baseIndexs = self.getindex(base, flowstring) min = None max = [] for i in baseIndexs: mer = flowspacekey[i] if mer == 0: if min == None: # only take first zero of any nuc for subtraction min = data[i] if mer == 1: max.append(data[i]) if len(max) > 0 and len(min) > 0: trace[base] = [float(i - j) for i, j in zip(max[0], min)] atrace = [] for base in list(trace.keys()): atrace.append(trace[base]) ax = fig.add_subplot(Rows, Cols, num) pylab.subplots_adjust(wspace=0.5, hspace=0.5) pylab.title("Region %s" % str(region)) pylab.setp(ax.get_yticklabels(), visible=True) pylab.setp(ax.get_xticklabels(), visible=False) for label in ax.get_yticklabels(): label.set_fontsize(8) pylab.gcf().set_size_inches((Rows + Cols, Rows + Cols)) for t in atrace: pylab.plot(t) num += 1 pylab.savefig(self.savepath)
def get_ionograms(top, sffIn, outfolder, key, floworder, metricKey): nameMap = {'q20Len':'Q20', 'q17Len':'Q17', 'q10Len':'Q10', 'q7Len':'Q7', 'perfect_length':'Perfect' } filelist = {} alignhtml = {} space_string = {} for align in top: alignstring = generate_align_html(align) row, col = get_row_col(align.get('name')) fin = Popen("SFFRead %s -C %s -R %s" % (sffIn,col,row), shell=True, stdout=PIPE) ionogram = fin.stdout.read() ionogram = ionogram.strip() ionogram = ionogram.split(" ") ionogram = [float(i) for i in ionogram] s = alignstring[1] expected = [] lenOfIon = len(ionogram) l = align.get(metricKey) fskey = template.deseqify(key, floworder) expected = fskey + list(pylab.zeros(lenOfIon-len(fskey))) intexp = [] for i in expected: intexp.append(int(i)) expected = intexp titleString = 'Single-Well Ionogram for (%s,%s) %s Length=%s Bases' % (int(row), int(col), nameMap.get(metricKey), l) it = plotters.IonogramJMR(floworder, expected[:len(ionogram)],ionogram,titleString) it.render() filelist[align.get('name')] = ("Well_(%s,%s).png" % (int(row),int(col))) alignhtml[align.get('name')] = alignstring countLen = math.floor(len(align.get('qDNA.a'))) space_string[align.get('name')] = "".join(get_align_num(countLen)) pylab.savefig(outfolder + "/Well_(%s,%s).png" % (int(row),int(col))) generateWeb(alignhtml, filelist, outfolder, top, space_string)#space_string, rowCollist)