def loadExpFile(self, fullpath): name = transit_tools.basename(fullpath) (density, meanrd, nzmeanrd, nzmedianrd, maxrd, totalrd, skew, kurtosis) = tnseq_tools.get_wig_stats(fullpath) if WX_VERSION > 3: self.list_exp.InsertItem(self.index_exp, name) self.list_exp.SetItem(self.index_exp, 1, "%1.1f" % (totalrd)) self.list_exp.SetItem(self.index_exp, 2, "%2.1f" % (density * 100)) self.list_exp.SetItem(self.index_exp, 3, "%1.1f" % (meanrd)) self.list_exp.SetItem(self.index_exp, 4, "%d" % (maxrd)) self.list_exp.SetItem(self.index_exp, 5, "%s" % (fullpath)) else: self.list_exp.InsertStringItem(self.index_exp, name) self.list_exp.SetStringItem(self.index_exp, 1, "%1.1f" % (totalrd)) self.list_exp.SetStringItem(self.index_exp, 2, "%2.1f" % (density * 100)) self.list_exp.SetStringItem(self.index_exp, 3, "%1.1f" % (meanrd)) self.list_exp.SetStringItem(self.index_exp, 4, "%d" % (maxrd)) self.list_exp.SetStringItem(self.index_exp, 5, "%s" % (fullpath)) self.list_exp.Select(self.index_exp) self.index_exp += 1
def fromGUI(self, wxobj): """ """ # Get Annotation file annotationPath = wxobj.annotation if not transit_tools.validate_annotation(annotationPath): return None # Get selected files ctrldata = wxobj.ctrlSelected() if not transit_tools.validate_control_datasets(ctrldata): return None # Validate transposon types types = tnseq_tools.get_file_types(ctrldata) if "himar1" in types: answer = transit_tools.ShowAskWarning( "Warning: One of the selected wig files looks like a Himar1 dataset. This method is designed to work on Tn5 wig files. Proceeding will fill in missing data with zeroes. Click OK to continue." ) if answer == wx.ID_CANCEL: return None # Read the parameters from the wxPython widgets ignoreCodon = True minread = int( wxobj.tn5GapsReadChoice.GetString( wxobj.tn5GapsReadChoice.GetCurrentSelection())) NTerminus = float(wxobj.globalNTerminusText.GetValue()) CTerminus = float(wxobj.globalCTerminusText.GetValue()) replicates = wxobj.tn5GapsRepChoice.GetString( wxobj.tn5GapsRepChoice.GetCurrentSelection()) normalization = None LOESS = False # Get output path name = transit_tools.basename(ctrldata[0]) defaultFileName = "tn5_gaps_output_m%d_r%s.dat" % (minread, replicates) defaultDir = os.getcwd() output_path = wxobj.SaveFile(defaultDir, defaultFileName) if not output_path: return None output_file = open(output_path, "w") return self( ctrldata, annotationPath, output_file, replicates, normalization, LOESS, ignoreCodon, minread, NTerminus, CTerminus, wxobj, )
def loadExpFile(self, fullpath): name = transit_tools.basename(fullpath) (density, meanrd, nzmeanrd, nzmedianrd, maxrd, totalrd, skew, kurtosis) = tnseq_tools.get_wig_stats(fullpath) self.list_exp.InsertItem(self.index_exp, name) self.list_exp.SetItem(self.index_exp, 1, "%1.1f" % (totalrd)) self.list_exp.SetItem(self.index_exp, 2, "%2.1f" % (density*100)) self.list_exp.SetItem(self.index_exp, 3, "%1.1f" % (meanrd)) self.list_exp.SetItem(self.index_exp, 4, "%d" % (maxrd)) self.list_exp.SetItem(self.index_exp, 5, "%s" % (fullpath)) self.list_exp.Select(self.index_exp) self.index_exp+=1
def loadCtrlFile(self, fullpath): name = transit_tools.basename(fullpath) (density, meanrd, nzmeanrd, nzmedianrd, maxrd, totalrd, skew, kurtosis) = tnseq_tools.get_wig_stats(fullpath) self.list_ctrl.InsertItem(self.index_ctrl, name) self.list_ctrl.SetItem(self.index_ctrl, 1, "%1.1f" % (totalrd)) self.list_ctrl.SetItem(self.index_ctrl, 2, "%2.1f" % (density*100)) self.list_ctrl.SetItem(self.index_ctrl, 3, "%1.1f" % (meanrd)) self.list_ctrl.SetItem(self.index_ctrl, 4, "%d" % (maxrd)) self.list_ctrl.SetItem(self.index_ctrl, 5, "%s" % (fullpath)) self.list_ctrl.Select(self.index_ctrl) self.index_ctrl+=1
def fromGUI(self, wxobj): """ """ #Get Annotation file annotationPath = wxobj.annotation if not transit_tools.validate_annotation(annotationPath): return None #Get selected files ctrldata = wxobj.ctrlSelected() if not transit_tools.validate_control_datasets(ctrldata): return None #Validate transposon types if not transit_tools.validate_transposons_used(ctrldata, transposons): return None #Read the parameters from the wxPython widgets samples = int(wxobj.binomialSampleText.GetValue()) burnin = int(wxobj.binomialBurnText.GetValue()) ignoreCodon = True NTerminus = float(wxobj.globalNTerminusText.GetValue()) CTerminus = float(wxobj.globalCTerminusText.GetValue()) replicates = "Sum" normalization = None LOESS = False #Get output path name = transit_tools.basename(ctrldata[0]) defaultFileName = "binomial_output.dat" defaultDir = os.getcwd() output_path = wxobj.SaveFile(defaultDir, defaultFileName) if not output_path: return None output_file = open(output_path, "w") return self(ctrldata, annotationPath, output_file, samples=samples, burnin=burnin, replicates=replicates, normalization=normalization, LOESS=LOESS, ignoreCodon=ignoreCodon, NTerminus=NTerminus, CTerminus=CTerminus, wxobj=wxobj)
def fromGUI(self, wxobj): """ """ #Get Annotation file annotationPath = wxobj.annotation if not transit_tools.validate_annotation(annotationPath): return None #Get selected files ctrldata = wxobj.ctrlSelected() if not transit_tools.validate_control_datasets(ctrldata): return None #Validate transposon types types = tnseq_tools.get_file_types(ctrldata) if 'himar1' in types: answer = transit_tools.ShowAskWarning("Warning: One of the selected wig files looks like a Himar1 dataset. This method is designed to work on Tn5 wig files. Proceeding will fill in missing data with zeroes. Click OK to continue.") if answer == wx.ID_CANCEL: return None #Read the parameters from the wxPython widgets ignoreCodon = True minread = int(wxobj.tn5GapsReadChoice.GetString(wxobj.tn5GapsReadChoice.GetCurrentSelection())) NTerminus = float(wxobj.globalNTerminusText.GetValue()) CTerminus = float(wxobj.globalCTerminusText.GetValue()) replicates= wxobj.tn5GapsRepChoice.GetString(wxobj.tn5GapsRepChoice.GetCurrentSelection()) normalization = None LOESS = False #Get output path name = transit_tools.basename(ctrldata[0]) defaultFileName = "tn5_gaps_output_m%d_r%s.dat" % (minread, replicates) defaultDir = os.getcwd() output_path = wxobj.SaveFile(defaultDir, defaultFileName) if not output_path: return None output_file = open(output_path, "w") return self(ctrldata, annotationPath, output_file, replicates, normalization, LOESS, ignoreCodon, minread, NTerminus, CTerminus, wxobj)
def fromGUI(self, wxobj): """ """ #Get Annotation file annotationPath = wxobj.annotation if not transit_tools.validate_annotation(annotationPath): return None #Get selected files ctrldata = wxobj.ctrlSelected() if not transit_tools.validate_control_datasets(ctrldata): return None #Validate transposon types if not transit_tools.validate_transposons_used(ctrldata, transposons): return None # minread = 1 #Read the parameters from the wxPython widgets ignoreCodon = True NTerminus = float(wxobj.globalNTerminusText.GetValue()) CTerminus = float(wxobj.globalCTerminusText.GetValue()) replicates = "Sum" normalization = None LOESS = False #Get output path name = transit_tools.basename(ctrldata[0]) defaultFileName = "griffin_output.dat" defaultDir = os.getcwd() output_path = wxobj.SaveFile(defaultDir, defaultFileName) if not output_path: return None output_file = open(output_path, "w") return self(ctrldata, annotationPath, output_file, minread, replicates, normalization, LOESS, ignoreCodon, NTerminus, CTerminus, wxobj)
def fromGUI(self, wxobj): """ """ #Get Annotation file annotationPath = wxobj.annotation if not transit_tools.validate_annotation(annotationPath): return None #Get selected files ctrldata = wxobj.ctrlSelected() if not transit_tools.validate_control_datasets(ctrldata): return None #Validate transposon types if not transit_tools.validate_transposons_used(ctrldata, transposons): return None #Read the parameters from the wxPython widgets replicates = wxobj.hmmRepChoice.GetString(wxobj.hmmRepChoice.GetCurrentSelection()) ignoreCodon = True NTerminus = float(wxobj.globalNTerminusText.GetValue()) CTerminus = float(wxobj.globalCTerminusText.GetValue()) normalization = wxobj.hmmNormChoice.GetString(wxobj.hmmNormChoice.GetCurrentSelection()) LOESS = False LOESS = wxobj.hmmLoessCheck.GetValue() #Get output path name = transit_tools.basename(ctrldata[0]) defaultFileName = "hmm_output.dat" defaultDir = os.getcwd() output_path = wxobj.SaveFile(defaultDir, defaultFileName) if not output_path: return None output_file = open(output_path, "w") return self(ctrldata, annotationPath, output_file, replicates, normalization, LOESS, ignoreCodon, NTerminus, CTerminus, wxobj)
def updateFiles(self): self.index_stats = 0 try: for j,row in enumerate(self.normdata): name = transit_tools.basename(self.wigList[j]) (density, meanrd, nzmeanrd, nzmedianrd, maxrd, totalrd, skew, kurtosis) = tnseq_tools.get_data_stats(row) self.statsListCtrl.InsertStringItem(self.index_stats, name) self.statsListCtrl.SetStringItem(self.index_stats, 1, "%1.1f" % (density*100.0)) self.statsListCtrl.SetStringItem(self.index_stats, 2, "%1.1f" % (meanrd)) self.statsListCtrl.SetStringItem(self.index_stats, 3, "%1.1f" % (nzmeanrd)) self.statsListCtrl.SetStringItem(self.index_stats, 4, "%1.1f" % (nzmedianrd)) self.statsListCtrl.SetStringItem(self.index_stats, 5, "%d" % (maxrd)) self.statsListCtrl.SetStringItem(self.index_stats, 6, "%d" % (totalrd)) self.statsListCtrl.SetStringItem(self.index_stats, 7, "%1.1f" % (skew)) self.statsListCtrl.SetStringItem(self.index_stats, 8, "%1.1f" % (kurtosis)) print(self.qc_prefix, "Adding dataset (%d): %s" % (self.index_stats, name)) self.index_stats+=1 except Exception as e: print(self.qc_prefix, "Error:", e) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def updateFiles(self): self.index_stats = 0 try: for j,row in enumerate(self.normdata): name = transit_tools.basename(self.wigList[j]) (density, meanrd, nzmeanrd, nzmedianrd, maxrd, totalrd, skew, kurtosis) = tnseq_tools.get_data_stats(row) self.statsListCtrl.InsertStringItem(self.index_stats, name) self.statsListCtrl.SetStringItem(self.index_stats, 1, "%1.1f" % (density*100.0)) self.statsListCtrl.SetStringItem(self.index_stats, 2, "%1.1f" % (meanrd)) self.statsListCtrl.SetStringItem(self.index_stats, 3, "%1.1f" % (nzmeanrd)) self.statsListCtrl.SetStringItem(self.index_stats, 4, "%1.1f" % (nzmedianrd)) self.statsListCtrl.SetStringItem(self.index_stats, 5, "%d" % (maxrd)) self.statsListCtrl.SetStringItem(self.index_stats, 6, "%d" % (totalrd)) self.statsListCtrl.SetStringItem(self.index_stats, 7, "%1.1f" % (skew)) self.statsListCtrl.SetStringItem(self.index_stats, 8, "%1.1f" % (kurtosis)) print self.qc_prefix, "Adding dataset (%d): %s" % (self.index_stats, name) self.index_stats+=1 except Exception as e: print self.qc_prefix, "Error:", e exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def addPlots(self): try: for i,reads in enumerate(self.normdata): #Data name = transit_tools.basename(self.wigList[i]) #reads,position = tnseq_tools.get_data([]) nzreads = reads[reads>0] n_nz = len(nzreads) truncnzreads = sorted(nzreads)[:int(n_nz*0.99)] fig = plt.figure(facecolor='white', figsize=(5, 5), dpi=100) ax = fig.add_subplot(111, frame_on=False) #Plot 1 n, bins, patches = ax.hist(truncnzreads, density=1, facecolor='c', alpha=0.75, bins=100) plt.xlabel('Reads') plt.ylabel('Probability') plt.title('Histogram of Non-Zero Reads\nDataset: %s' % name) plt.grid(True) buf = io.BytesIO() fig.savefig(buf, format='png') buf.seek(0) hist_pil_img = Image.open(buf) hist_wx_img = PilImageToWxImage( hist_pil_img ) hist_wx_bitmap = wx.BitmapFromImage(hist_wx_img) #Plot 2 plt.clf() ax = fig.add_subplot(111, frame_on=False) ((qtheoretical, qdata), (slope, intercept, r)) = scipy.stats.probplot(truncnzreads, dist="geom", sparams=(1.0/numpy.mean(truncnzreads),)) n_qdata = len(qdata) #qtheoretical = qtheoretical[:int(n_qdata*0.99)] #qdata = qdata[:int(n_qdata*0.99)] ax.plot(qdata, qtheoretical, "ob") maxval = max(numpy.max(qtheoretical), numpy.max(qdata)) ax.plot((0, maxval), (0, maxval), ls="-", c="r") plt.xlabel("Data Quantiles") plt.ylabel("Theoretical Quantiles") plt.title('QQ-Plot with Theoretical Geom\nDataset: %s' % name) plt.grid(True) buf = io.BytesIO() fig.savefig(buf, format='png') buf.seek(0) qq_pil_img = Image.open(buf) qq_wx_img = PilImageToWxImage(qq_pil_img) qq_wx_bitmap = wx.BitmapFromImage(qq_wx_img) #Plot 3 plt.clf() ax = fig.add_subplot(111, frame_on=False) ax.plot(sorted(reads), "ob", linewidth=3) plt.title('Rank Reads\nDataset: %s' % name) plt.xlabel("Reads") plt.ylabel("Rank") plt.grid(True) plt.xticks(rotation=45) buf = io.BytesIO() fig.savefig(buf, format='png') buf.seek(0) sorted_pil_img = Image.open(buf) sorted_wx_img = PilImageToWxImage(sorted_pil_img) sorted_wx_bitmap = wx.BitmapFromImage(sorted_wx_img) self.plots_list.append([fig, hist_wx_bitmap, qq_wx_bitmap, sorted_wx_bitmap]) except Exception as e: print(self.qc_prefix, "Error:", e) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def fromGUI(self, wxobj): """ """ #Get Annotation file annotationPath = wxobj.annotation if not transit_tools.validate_annotation(annotationPath): return None #Get selected files ctrldata = wxobj.ctrlSelected() if not transit_tools.validate_control_datasets(ctrldata): return None #Validate transposon types if not transit_tools.validate_transposons_used(ctrldata, transposons): return None #Read the parameters from the wxPython widgets try: minread = int( wxobj.gumbelReadChoice.GetString( wxobj.gumbelReadChoice.GetCurrentSelection())) except: warnings.warn( "Warning: problem reading minimum read parameter. Assuming a value of '1'" ) minread = 1 try: samples = int(wxobj.gumbelSampleText.GetValue()) except: warnings.warn( "Warning: problem reading samples parameter. Assuming a value of '10000'" ) samples = 10000 try: burnin = int(wxobj.gumbelBurninText.GetValue()) except: warnings.warn( "Warning: problem reading burnin parameter. Assuming a value of '500'" ) burnin = 500 try: trim = int(wxobj.gumbelTrimText.GetValue()) except: warnings.warn( "Warning: problem reading trim parameter. Assuming a value of '1'" ) trim = 1 try: replicates = wxobj.gumbelRepChoice.GetString( wxobj.gumbelRepChoice.GetCurrentSelection()) except: warnings.warn( "Warning: problem reading replicates parameter. Assuming a value of 'Mean'" ) replicates = "Mean" ignoreCodon = True try: NTerminus = float(wxobj.globalNTerminusText.GetValue()) except: warnings.warn( "Warning: problem reading NTerminus parameter. Assuming a value of '0.00'" ) NTerminus = 0.0 try: CTerminus = float(wxobj.globalCTerminusText.GetValue()) except: warnings.warn( "Warning: problem reading CTerminus parameter. Assuming a value of '0.00'" ) CTerminus = 0.0 normalization = None LOESS = False #Get output path name = transit_tools.basename(ctrldata[0]) defaultFileName = "gumbel_%s_s%d_b%d_t%d.dat" % (".".join( name.split(".")[:-1]), samples, burnin, trim) defaultDir = os.getcwd() output_path = wxobj.SaveFile(defaultDir, defaultFileName) if not output_path: return None output_file = open(output_path, "w") return self(ctrldata, annotationPath, output_file, samples, burnin, trim, minread, replicates, normalization, LOESS, ignoreCodon, NTerminus, CTerminus, wxobj)
def fromGUI(self, wxobj): """ """ #Get Annotation file annotationPath = wxobj.annotation if not transit_tools.validate_annotation(annotationPath): return None #Get selected files ctrldata = wxobj.ctrlSelected() if not transit_tools.validate_control_datasets(ctrldata): return None #Validate transposon types if not transit_tools.validate_transposons_used(ctrldata, transposons): return None #Read the parameters from the wxPython widgets try: minread = int(wxobj.gumbelReadChoice.GetString(wxobj.gumbelReadChoice.GetCurrentSelection())) except: warnings.warn("Warning: problem reading minimum read parameter. Assuming a value of '1'") minread = 1 try: samples = int(wxobj.gumbelSampleText.GetValue()) except: warnings.warn("Warning: problem reading samples parameter. Assuming a value of '10000'") samples = 10000 try: burnin = int(wxobj.gumbelBurninText.GetValue()) except: warnings.warn("Warning: problem reading burnin parameter. Assuming a value of '500'") burnin = 500 try: trim = int(wxobj.gumbelTrimText.GetValue()) except: warnings.warn("Warning: problem reading trim parameter. Assuming a value of '1'") trim = 1 try: replicates = wxobj.gumbelRepChoice.GetString(wxobj.gumbelRepChoice.GetCurrentSelection()) except: warnings.warn("Warning: problem reading replicates parameter. Assuming a value of 'Mean'") replicates = "Mean" ignoreCodon = True try: NTerminus = float(wxobj.globalNTerminusText.GetValue()) except: warnings.warn("Warning: problem reading NTerminus parameter. Assuming a value of '0.00'") NTerminus = 0.0 try: CTerminus = float(wxobj.globalCTerminusText.GetValue()) except: warnings.warn("Warning: problem reading CTerminus parameter. Assuming a value of '0.00'") CTerminus = 0.0 normalization = None LOESS = False #Get output path name = transit_tools.basename(ctrldata[0]) defaultFileName = "gumbel_%s_s%d_b%d_t%d.dat" % (".".join(name.split(".")[:-1]), samples, burnin, trim) defaultDir = os.getcwd() output_path = wxobj.SaveFile(defaultDir, defaultFileName) if not output_path: return None output_file = open(output_path, "w") return self(ctrldata, annotationPath, output_file, samples, burnin, trim, minread, replicates, normalization, LOESS, ignoreCodon, NTerminus, CTerminus, wxobj)
def addPlots(self): try: for i,reads in enumerate(self.normdata): #Data name = transit_tools.basename(self.wigList[i]) #reads,position = tnseq_tools.get_data([]) nzreads = reads[reads>0] n_nz = len(nzreads) truncnzreads = sorted(nzreads)[:int(n_nz*0.99)] fig = plt.figure(facecolor='white', figsize=(5, 5), dpi=100) ax = fig.add_subplot(111, frame_on=False) #Plot 1 n, bins, patches = ax.hist(truncnzreads, density=1, facecolor='c', alpha=0.75, bins=100) plt.xlabel('Reads') plt.ylabel('Probability') plt.title('Histogram of Non-Zero Reads\nDataset: %s' % name) plt.grid(True) buf = io.BytesIO() fig.savefig(buf, format='png') buf.seek(0) hist_pil_img = Image.open(buf) hist_wx_img = PilImageToWxImage( hist_pil_img ) hist_wx_bitmap = wx.BitmapFromImage(hist_wx_img) #Plot 2 plt.clf() ax = fig.add_subplot(111, frame_on=False) ((qtheoretical, qdata), (slope, intercept, r)) = scipy.stats.probplot(truncnzreads, dist="geom", sparams=(1.0/numpy.mean(truncnzreads),)) n_qdata = len(qdata) #qtheoretical = qtheoretical[:int(n_qdata*0.99)] #qdata = qdata[:int(n_qdata*0.99)] ax.plot(qdata, qtheoretical, "ob") maxval = max(numpy.max(qtheoretical), numpy.max(qdata)) ax.plot((0, maxval), (0, maxval), ls="-", c="r") plt.xlabel("Data Quantiles") plt.ylabel("Theoretical Quantiles") plt.title('QQ-Plot with Theoretical Geom\nDataset: %s' % name) plt.grid(True) buf = io.BytesIO() fig.savefig(buf, format='png') buf.seek(0) qq_pil_img = Image.open(buf) qq_wx_img = PilImageToWxImage(qq_pil_img) qq_wx_bitmap = wx.BitmapFromImage(qq_wx_img) #Plot 3 plt.clf() ax = fig.add_subplot(111, frame_on=False) ax.plot(sorted(reads), "ob", linewidth=3) plt.title('Rank Reads\nDataset: %s' % name) plt.xlabel("Reads") plt.ylabel("Rank") plt.grid(True) plt.xticks(rotation=45) buf = io.BytesIO() fig.savefig(buf, format='png') buf.seek(0) sorted_pil_img = Image.open(buf) sorted_wx_img = PilImageToWxImage(sorted_pil_img) sorted_wx_bitmap = wx.BitmapFromImage(sorted_wx_img) self.plots_list.append([fig, hist_wx_bitmap, qq_wx_bitmap, sorted_wx_bitmap]) except Exception as e: print self.qc_prefix, "Error:", e exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)