當前位置: 首頁>>代碼示例>>Python>>正文


Python Session.refresh方法代碼示例

本文整理匯總了Python中hpf.hddb.db.Session.refresh方法的典型用法代碼示例。如果您正苦於以下問題:Python Session.refresh方法的具體用法?Python Session.refresh怎麽用?Python Session.refresh使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在hpf.hddb.db.Session的用法示例。


在下文中一共展示了Session.refresh方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: HPFPsipredWrap

# 需要導入模塊: from hpf.hddb.db import Session [as 別名]
# 或者: from hpf.hddb.db.Session import refresh [as 別名]

#.........這裏部分代碼省略.........
        """Variables:
        self.prediction - The PsipredPrediction object returned from Psipred32(...).run()
        self.dbo        - If dbstore=True, the Psipred ORM object (DataBaseObject) from the HPF DB
        """
        from hpf.hddb.db import Session, Sequence

        self.sequence_key  = sequence_key
        self.nr_db = os.path.abspath(os.path.expanduser(nr_db))
        self.ginzu_version = ginzu_version
        self.dir = dir if dir else os.getcwd()
        self.dbstore = dbstore
        self.debug = debug

	#kdrew: commenting out because "nr" is not a file but a location
        #if not os.path.isfile(self.nr_db):
        #    raise Exception("Must provide a valid NR database file")
        
        self.session  = Session()
        self.sequence = self.session.query(Sequence).get(self.sequence_key)
        if not self.sequence:
            raise Exception("No sequence with key {0} exists in DB".format(self.sequence_key))
        
        self.fasta_file = "{0}.fasta".format(self.sequence_key)
        self.chkpt_file = "{0}.chk".format(self.sequence_key)
        self.psipred_file = "{0}.psipred".format(self.sequence_key)

        # Set in run (dbo optionally)
        self.prediction = None
        self.dbo = None

        if autorun:
            self.prediction = self.run()

    def get_prediction_string(self, ):
        """Returns the prediction string from the PsipredPrediction object (if populated)"""
        if not self.prediction:
            return None
        return self.prediction.prediction

    def run(self, ):
        """
        Cobbles together elements for running Psipred (writes fasta, runs blast to get checkpoint,
        runs psipred and psipass2, and then parses results and uploads to DB if set to).
        IF dbstore is true, adds Psipred ORM object to hpf database and sets self.dbo.
        RETURNS hpf.pdb.psipred.PsipredPrediction object
        """
        import subprocess
        from Bio import SeqIO
        from Bio.Blast.NCBIStandalone import blastpgp
        from hpf.hddb.db import Psipred as PsipredORM, PsipredFactory
        from sqlalchemy.exc import IntegrityError

        # Write fasta file
        if self.debug: print "Psipred: writing fasta file"
        with open(self.fasta_file, 'w') as handle:
            SeqIO.write([self.sequence.record], handle, "fasta")

        # Get exe path and run blast
        if self.debug: print "Psipred: running blastpgp against '{0}' DB to create checkpoint file".format(self.nr_db)
        blast_cmd = subprocess.Popen(["which", "blastpgp"], stdout=subprocess.PIPE).communicate()[0].strip()
        result,error = blastpgp(blastcmd=blast_cmd, 
                                program='blastpgp', 
                                database=self.nr_db, 
                                infile=self.fasta_file, 
                                npasses=3, 
                                checkpoint_outfile=self.chkpt_file, 
                                expectation=1e-4, 
                                model_threshold=1e-4, 
                                align_outfile="/dev/null")
        # Note: must call something that blocks on blastpgp results (need to wait for cmd to finish)
        res = result.read()
        err = error.read()
        if self.debug:
            print "Result: ", res
            print "Error/Warning: ", err

        # Create Psipred options object and run Psipred 3.2 on them
        if self.debug: print "Psipred: running Psipred 3.2"
        options = PsipredOptions(self.fasta_file,
                                 profile=self.chkpt_file,
                                 output=self.psipred_file+".1",
                                 output2=self.psipred_file+".2",
                                 horiz=self.psipred_file,
                                 cwd=self.dir)
        self.prediction = Psipred32(options).run()
        
        # Add to database (optional) and return
        if self.dbstore:
            if self.debug: print "Psipred: adding psipred DBO to hpf database"
            psipred_dbo = PsipredFactory().create(self.prediction, sequence_key=self.sequence.id, ginzu_version=self.ginzu_version)
            self.session.add(psipred_dbo)
            try:
                self.session.commit()
            except IntegrityError:
                print "Psipred entry for <seq {0}, ginzu_version {1}> already exists in DB. Returning existing object".format(self.sequence_key, self.ginzu_version)
                self.session.rollback()
                psipred_dbo = self.session.query(PsipredORM).filter_by(sequence_key=self.sequence.id, ginzu_version=self.ginzu_version).first()
            self.session.refresh(psipred_dbo)
            self.dbo = psipred_dbo
        return self.prediction
開發者ID:bsmithers,項目名稱:hpf,代碼行數:104,代碼來源:psipred.py


注:本文中的hpf.hddb.db.Session.refresh方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。