def openStrandSequenceFile(self): """ Open (read) the user specified Strand sequence file and enter the sequence in the Strand sequence Text edit. Note that it ONLY reads the FIRST line of the file. @TODO: It only reads in the first line of the file. Also, it doesn't handle any special cases. (Once the special cases are clearly defined, that functionality will be added. """ if self.parentWidget.assy.filename: odir = os.path.dirname(self.parentWidget.assy.filename) else: odir = env.prefs[workingDirectory_prefs_key] self.sequenceFileName = \ str(QFileDialog.getOpenFileName( self, "Load Strand Sequence", odir, "Strand Sequnce file (*.txt);;All Files (*.*);;")) lines = self.sequenceFileName try: lines = open(self.sequenceFileName, "rU").readlines() except: print "Exception occurred to open file: ", self.sequenceFileName return sequence = lines[0] sequence = QString(sequence) sequence = sequence.toUpper() self._updateSequenceAndItsComplement(sequence) return
def updateSequence(self): """ Update the sequence string in the sequence editor @see: DnaSequenceEditor.setSequence() @see DnaSequenceEditor._determine_complementSequence() @see: DnaSequenceEditor.setComplementSequence() @see: DnaStrand.getStrandSequenceAndItsComplement() """ #Read in the strand sequence of the selected strand and #show it in the text edit in the sequence editor. ##strand = self.strandListWidget.getPickedItem() if not self.editCommand.hasValidStructure(): return strand = self.editCommand.struct titleString = 'Sequence Editor for ' + strand.name self.sequenceEditor.setWindowTitle(titleString) sequenceString, complementSequenceString = strand.getStrandSequenceAndItsComplement() if sequenceString: sequenceString = QString(sequenceString) sequenceString = sequenceString.toUpper() #Set the initial sequence (read in from the file) self.sequenceEditor.setSequence(sequenceString) #Set the initial complement sequence for DnaSequence editor. #do this independently because 'complementSequenceString' may have #some characters (such as * ) that denote a missing base on the #complementary strand. this information is used by the sequence #editor. See DnaSequenceEditor._determine_complementSequence() #for more details. See also bug 2787 self.sequenceEditor.setComplementSequence(complementSequenceString)
def updateSequence(self): """ Update the sequence string in the sequence editor @see: DnaSequenceEditor.setSequence() @see DnaSequenceEditor._determine_complementSequence() @see: DnaSequenceEditor.setComplementSequence() @see: DnaStrand.getStrandSequenceAndItsComplement() """ #Read in the strand sequence of the selected strand and #show it in the text edit in the sequence editor. ##strand = self.strandListWidget.getPickedItem() if not self.editCommand.hasValidStructure(): return strand = self.editCommand.struct titleString = 'Sequence Editor for ' + strand.name self.sequenceEditor.setWindowTitle(titleString) sequenceString, complementSequenceString = strand.getStrandSequenceAndItsComplement( ) if sequenceString: sequenceString = QString(sequenceString) sequenceString = sequenceString.toUpper() #Set the initial sequence (read in from the file) self.sequenceEditor.setSequence(sequenceString) #Set the initial complement sequence for DnaSequence editor. #do this independently because 'complementSequenceString' may have #some characters (such as * ) that denote a missing base on the #complementary strand. this information is used by the sequence #editor. See DnaSequenceEditor._determine_complementSequence() #for more details. See also bug 2787 self.sequenceEditor.setComplementSequence(complementSequenceString)
def _open_FASTA_File(self): """ Open (read) the user specified FASTA sequence file and load it into the sequence field. @TODO: It only reads in the first line of the file. Also, it doesn't handle any special cases. (Once the special cases are clearly defined, that functionality will be added. @attention: This is not implemented yet. """ #Urmi 20080714: should not this be only fasta file, for both load and save if self.parentWidget.assy.filename: odir = os.path.dirname(self.parentWidget.assy.filename) else: odir = env.prefs[workingDirectory_prefs_key] self.sequenceFileName = \ str(QFileDialog.getOpenFileName( self, "Load FASTA sequence for " + self.current_protein.name, odir, "FASTA file (*.txt);;All Files (*.*);;")) lines = self.sequenceFileName try: lines = open(self.sequenceFileName, "rU").readlines() except: print "Exception occurred to open file: ", self.sequenceFileName return sequence = lines[0] sequence = QString(sequence) sequence = sequence.toUpper() self._setSequence(sequence) return
def updateSequence(self, strand=None, cursorPos=-1): """ Updates and shows the sequence editor with the sequence of I{strand}. This is the main (public) method to call to update the sequence editor. @param strand: the strand. If strand is None (default), update the sequence of the current strand (i.e. self.current_strand). @type strand: DnaStrand @param cursorPos: the position in the sequence in which to place the cursor. If cursorPos is negative, the cursor position is placed at the end of the sequence (default). @type cursorPos: int """ if strand == " ": self.current_strand = None self.clear() return if strand: assert isinstance(strand, self.win.assy.DnaStrand) self.current_strand = strand else: # Use self.current_strand. Make sure it's not None (as a precaution). assert isinstance(self.current_strand, self.win.assy.DnaStrand) sequence, complementSequence = \ self.current_strand.getStrandSequenceAndItsComplement() if sequence: sequence = QString(sequence) sequence = sequence.toUpper() #Set the initial sequence (read in from the file) self._setSequence(sequence) #Set the initial complement sequence for DnaSequence editor. #do this independently because 'complementSequenceString' may have #some characters (such as * ) that denote a missing base on the #complementary strand. This information is used by the sequence #editor. See DnaSequenceEditor._determine_complementSequence() #for more details. See also bug 2787 self._setComplementSequence(complementSequence) else: msg = "DnaStrand '%s' has no sequence." % self.current_strand.name print_compact_traceback(msg) self._setSequence(msg) self._setComplementSequence("") # Set cursor position. self.setCursorPosition(cursorPos) # Update the bg color to white. self._sequence_changed = False self._previousSequence = sequence self._updateSequenceBgColor() # Update window title with name of current protein. titleString = 'Sequence Editor for ' + self.current_strand.name self.setWindowTitle(titleString) if not self.isVisible(): #Show the sequence editor if it isn't visible. #ATTENTION: the sequence editor will (temporarily) close the #Reports dockwidget (if it is visible). The Reports dockwidget #is restored when the sequence Editor is closed. self.show() return
def updateSequence(self, strand = None, cursorPos = -1): """ Updates and shows the sequence editor with the sequence of I{strand}. This is the main (public) method to call to update the sequence editor. @param strand: the strand. If strand is None (default), update the sequence of the current strand (i.e. self.current_strand). @type strand: DnaStrand @param cursorPos: the position in the sequence in which to place the cursor. If cursorPos is negative, the cursor position is placed at the end of the sequence (default). @type cursorPos: int """ if strand == " ": self.current_strand = None self.clear() return if strand: assert isinstance(strand, self.win.assy.DnaStrand) self.current_strand = strand else: # Use self.current_strand. Make sure it's not None (as a precaution). assert isinstance(self.current_strand, self.win.assy.DnaStrand) sequence, complementSequence = \ self.current_strand.getStrandSequenceAndItsComplement() if sequence: sequence = QString(sequence) sequence = sequence.toUpper() #Set the initial sequence (read in from the file) self._setSequence(sequence) #Set the initial complement sequence for DnaSequence editor. #do this independently because 'complementSequenceString' may have #some characters (such as * ) that denote a missing base on the #complementary strand. This information is used by the sequence #editor. See DnaSequenceEditor._determine_complementSequence() #for more details. See also bug 2787 self._setComplementSequence(complementSequence) else: msg = "DnaStrand '%s' has no sequence." % self.current_strand.name print_compact_traceback(msg) self._setSequence(msg) self._setComplementSequence("") # Set cursor position. self.setCursorPosition(cursorPos) # Update the bg color to white. self._sequence_changed = False self._previousSequence = sequence self._updateSequenceBgColor() # Update window title with name of current protein. titleString = 'Sequence Editor for ' + self.current_strand.name self.setWindowTitle(titleString) if not self.isVisible(): #Show the sequence editor if it isn't visible. #ATTENTION: the sequence editor will (temporarily) close the #Reports dockwidget (if it is visible). The Reports dockwidget #is restored when the sequence Editor is closed. self.show() return