def __init__( self, outFolder='.', clusterLimit=20, verbose=1, log=None, silent=0 ): """ @param outFolder: project folder (results are put into subfolder) ['.'] @type outFolder: str @param clusterLimit: maximal number of returned sequence clusters (default: 20) @type clusterLimit: int @param verbose: keep temporary files (default: 1) @type verbose: 1|0 @param log: log file instance, if None, STDOUT is used (default: None) @type log: LogFile @param silent: don't print messages to STDOUT is used (default: 0) @type silent: 1|0 """ SequenceSearcher.__init__( self, outFolder=outFolder, verbose=1 ) self.ex_pdb = re.compile( 'pdb\|([A-Z0-9]{4})\|([A-Z]*)' ) self.ex_gb = re.compile( 'gi\|([0-9]+)\|') self.ex_resolution = re.compile(\ 'REMARK 2 RESOLUTION\. *([0-9\.]+|NOT APPLICABLE)' ) self.prepareFolders() self.verbose = verbose self.silent = silent self.log = log or StdLog() ## the maximal number of clusters to return self.clusterLimit = clusterLimit
def prepareFolders(self): """ Create folders needed by this class. """ SequenceSearcher.prepareFolders(self) if not os.path.exists(self.outFolder + self.F_ALL): os.mkdir(self.outFolder + self.F_ALL) if not os.path.exists(self.outFolder + self.F_NR): os.mkdir(self.outFolder + self.F_NR)
def prepareFolders( self ): """ Create folders needed by this class. """ SequenceSearcher.prepareFolders( self ) if not os.path.exists( self.outFolder + self.F_ALL ): os.mkdir( self.outFolder + self.F_ALL ) if not os.path.exists( self.outFolder + self.F_NR ): os.mkdir( self.outFolder + self.F_NR )
def fastaRecordFromId(self, db, id, chain=''): """ Use:: fastaRecordFromId( db, id ) -> Bio.Fasta.Record @param db: database @type db: str @param id: sequence database ID @type id: str @return: fasta record @rtype: Bio.SeqRecord.SeqRecord @raise BlastError: if can't fetch fasta record from database """ if chain == '': return SequenceSearcher.fastaRecordFromId(self, db, id) cmd = settings.fastacmd_bin + " -d %s -s 'pdb|%s|%s'" \ % (db, id, chain) err, o = commands.getstatusoutput(cmd) if err: EHandler.warning('%s returned error: %r' % (cmd, err)) raise BlastError(err) try: frecord = SeqIO.parse(cStringIO.StringIO(o), 'fasta').next() frecord.id = str(id) except StopIteration: raise InternalError, \ "Couldn't fetch fasta record %s from database %s" % (id,db) return frecord
def fastaRecordFromId( self, db, id, chain='' ): """ Use:: fastaRecordFromId( db, id ) -> Bio.Fasta.Record @param db: database @type db: str @param id: sequence database ID @type id: str @return: fasta record @rtype: Bio.SeqRecord.SeqRecord @raise BlastError: if can't fetch fasta record from database """ if chain == '': return SequenceSearcher.fastaRecordFromId( self, db, id ) cmd = settings.fastacmd_bin + " -d %s -s 'pdb|%s|%s'" \ % (db, id, chain) err, o = commands.getstatusoutput( cmd ) if err: EHandler.warning('%s returned error: %r' % (cmd, err) ) raise BlastError( err ) try: frecord = SeqIO.parse( cStringIO.StringIO(o), 'fasta').next() frecord.id = str(id) except StopIteration: raise InternalError, \ "Couldn't fetch fasta record %s from database %s" % (id,db) return frecord