def on_output_browse(self, event): if self.combine_ck.IsChecked(): output_file = report_chooser(self, title='Save output file as:', mode='w') if output_file: self.output_text.SetValue(output_file) else: folder_chooser = wx.DirDialog(self, "Choose folder to save output:", style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON) if folder_chooser.ShowModal() == wx.ID_OK: self.output_text.SetValue(folder_chooser.GetPath()) folder_chooser.Destroy()
def on_click(self, event): #update statusbar self.set_status("Fragmenting...",0) self.set_status("",1) peptide = self.peptideString.GetValue() peptide = re.sub(r'\[\]', '', peptide) self.peptideString.SetValue(peptide) ion_array = [] if self.one_plus.IsChecked(): for k,v in self.ions.items(): if v.IsChecked(): ion_array.append(v.GetName()) if self.two_plus.IsChecked(): ion_array.extend([(ion+'++') for ion in ion_array if not ion.startswith('inty')]) # NB: generator causes infinite loop! elif self.two_plus.IsChecked(): for k,v in self.ions.items(): if v.IsChecked() and not k.startswith('Internal'): ion_array.append(v.GetName() + '++') ion_array.sort() if not peptide: wx.MessageBox('No peptide sequence was entered.') return try: frag_data = fragment_legacy(peptide, ion_array, labels = False) except ValueError as err: print err wx.MessageBox('Invalid mass value.', 'Error') # update statusbar self.set_status("Ready", 0) self.set_status("Done", 1) return except LookupError as err: print err wx.MessageBox('Invalid modification name or position.', 'Error') import sys print sys.exc_info() # update statusbar self.set_status("Ready", 0) self.set_status("Done", 1) return pep_cleaner = re.compile(r'-?(\[.+?\]|[a-z0-9])-?') # peptide without any modifications sequence = pep_cleaner.sub('', peptide) row_headers = list(sequence) for m in re.finditer(r'(-?(\[.+?\]|[a-z])-?)', peptide): mod = m.group(1) if m.end() < len(peptide): i = len(pep_cleaner.sub('', peptide[:m.end() + 1])) - 1 row_headers[i] = '%s%s' % (mod, row_headers[i]) else: row_headers[-1] = '%s%s' % (row_headers[-1], mod) data = [[0.0 for ion in ion_array] for aa in sequence] # convert data to list of lists per AA for i,ion in enumerate(ion_array): ion_series = frag_data[i] + [None] if ion[0] in ('x', 'y', 'z'): ion_series.reverse() for j,aa in enumerate(sequence): data[j][i] = ion_series[j] if self.writeToggleCk.GetValue(): writeFile = report_chooser(self, mode='w') or os.path.join(myData, 'pepFrag.csv') if os.path.exists(writeFile): os.remove(writeFile) myreport = multiplierz.mzReport.writer(writeFile, columns=[''] + ion_array) for i in range(len(row_headers)): myreport.write([row_headers[i]] + data[i]) myreport.close() else: tableFrame = FragTable(self, -1, "Fragment Table", row_headers, ion_array, data) tableFrame.Show() #self.dataDisplay.displayData(row_headers, ion_array, data) # update statusbar self.set_status("Ready", 0) self.set_status("Done", 1)
def addFile(self, event): filenames = report_chooser('Select file:', mode='m') if filenames: self.fileList.InsertItems(filenames, 0)
def OnClickMascotFile(self, event): file_name = report_chooser(self) if file_name: self.file_text.SetValue(file_name)
def OnClick(self, event): #update statusbar self.set_status("Digesting...", 0) self.set_status("", 1) fasta_split = self.proteinInput.GetValue().split('\n') headers = [] proteins = [] for line in fasta_split: if not line: continue if line[0] == '>': headers.append(line[1:]) proteins.append('') continue proteins[-1] += line.upper() enzyme = self.enzymeCB.GetValue() missed_cleavages = int(self.missed_cleavagesCB.GetValue()) if enzyme[0] != "[": (enzyme, spec) = enzyme.split(':') data = [] for (i, protein) in enumerate(proteins): try: digests = digest(protein, enzyme, missed_cleavages) except Exception as err: wx.MessageBox( 'Error while parsing protein entry: %s' % protein, "An error occurred.") raise err header = headers[i] for (j, dig) in enumerate(digests): pep = digests[j][0] range = digests[j][1] m_c = digests[j][2] try: oneMass = "%0.3f" % mz(pep, [], 1) twoMass = "%0.3f" % mz(pep, [], 2) threeMass = "%0.3f" % mz(pep, [], 3) data.append( (header, pep, range, m_c, oneMass, twoMass, threeMass)) except Exception as err: wx.MessageBox( 'Error while parsing peptide substring: %s' % pep, "An error occurred.") raise err if self.writeToggleCk.GetValue(): writeFile = report_chooser(self, mode='w') or os.path.join( myData, 'protDigest.csv') if os.path.exists(writeFile): os.remove(writeFile) cols = [ 'Header', 'Sequence', 'Range', 'Missed Cleavage', '1+ Mass', '2+ Mass', '3+ Mass' ] report = multiplierz.mzReport.writer(writeFile, columns=cols) for peptide in data: pepRange = str(peptide[2][0]) + '...' + str(peptide[2][1]) report.write(peptide[:2] + (pepRange, ) + peptide[3:]) report.close() else: tableFrame = Table1(self, -1, "Digest Table", data) tableFrame.Show() #update statusbar self.set_status("Ready", 0) self.set_status("Done", 1)