def exportAlignment(self, widget): # create a file chooser dialog to get a file name and format from the user fc = seqwriter.SeqWriterFileDialog(self, 'Export Alignment') fc.set_current_folder(os.getcwd()) response = fc.run() fname = fc.get_filename() fformat = fc.getFileFormat() fc.destroy() if response != Gtk.ResponseType.OK: return # write out the sequences sw = seqwriter.SequenceWriterFactory.getSequenceWriter(fformat) try: sw.open(fname) except IOError: self.showMessage( 'The file "' + fname + '" could not be opened for writing. ' + 'Verify that you have permission to write to the specified file and directory.' ) return for cnt in range(0, self.numseqs): seqfname = self.cons.getSequenceTrace(cnt).getFileName() desc = 'sequence ' + str(cnt) if self.cons.getSequenceTrace(cnt).isReverseComplemented(): desc += ' (reverse complemented)' sw.addAlignedSequence(self.cons.getAlignedSequence(cnt), seqfname, desc) sw.write()
def exportConsensus(self, widget): # create a file chooser dialog to get a file name and format from the user fc = seqwriter.SeqWriterFileDialog(self, 'Export Consensus Sequence') fc.set_current_folder(os.getcwd()) response = fc.run() fname = fc.get_filename() fformat = fc.getFileFormat() fc.destroy() if response != Gtk.ResponseType.OK: return # write out the sequence sw = seqwriter.SequenceWriterFactory.getSequenceWriter(fformat) try: sw.open(fname) except IOError: self.showMessage( 'The file "' + fname + '" could not be opened for writing. ' + 'Verify that you have permission to write to the specified file and directory.' ) return desc = 'consensus' seqfname = self.cons.getSequenceTrace(0).getFileName() if self.numseqs == 2: seqfname += ', ' + self.cons.getSequenceTrace(1).getFileName() sw.addUnalignedSequence(self.cons.getCompactConsensus(), seqfname, desc) sw.write()
def exportSelected(self, widget): # create a file chooser dialog to get a file name and format from the user fc = seqwriter.SeqWriterFileDialog(self, 'Export Selected Sequences') fc.setShowOptions(True) fc.set_current_folder(os.getcwd()) response = fc.run() fname = fc.get_filename() fformat = fc.getFileFormat() include_fnames = fc.getIncludeFileNames() fc.destroy() if response != Gtk.ResponseType.OK: return # write out the sequences sw = seqwriter.SequenceWriterFactory.getSequenceWriter(fformat) try: sw.open(fname) except IOError: self.showMessage( 'The file "' + fname + '" could not be opened for writing. ' + 'Verify that you have permission to write to the specified file and directory.' ) return items = self.projview.getSelection() for item in items: if item.hasParent(): continue if item.getUseSequence(): desc = item.getNotes() if item.isFile(): seqfname = item.getName() else: children = item.getChildren() seqfname = children[0].getName( ) + ', ' + children[1].getName() if not (include_fnames): seqfname = '' sw.addUnalignedSequence(item.getCompactConsSequence(), seqfname, desc) try: sw.write() except seqwriter.SequenceWriterError as err: self.showMessage('Error: ' + str(err))