def loadPair( self, seq1, seq2 ): temp_mali = Mali.Mali() temp_mali.addSequence( "seq1", 0, len(seq1), seq1 ) temp_mali.addSequence( "seq2", 0, len(seq2), seq2 ) try: self.mResult = self.mBaseml.Run( temp_mali, tree = "(seq1,seq2);", dump = self.mDump, test = self.mTest ) except WrapperCodeML.UsageError: self.mResult = None
def Run(self, mali, tree=None, dump=0, test=False, options={}): self.mTempdir = tempfile.mkdtemp() self.mFilenameInput = "input" self.mFilenameOutput = "output" if test: print "# temporary directory is %s" % self.mTempdir mali.writeToFile(open(self.mTempdir + "/" + self.mFilenameInput, "w"), format="fasta") statement = " ".join((self.mExecutable, "-in %s" % self.mFilenameInput, "-out %s" % self.mFilenameOutput)) s = subprocess.Popen(statement, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.mTempdir, close_fds=True) (out, err) = s.communicate() if s.returncode != 0: raise UsageError, "Error in running %s \n%s\n%s\nTemporary directory in %s" % ( self.mExecutable, err, out, self.mTempdir) if dump: print "# stdout output of %s:\n%s\n######################################" % ( self.mExecutable, out) result = Mali.Mali() result.readFromFile(open( "%s/%s" % (self.mTempdir, self.mFilenameOutput), "r"), format="fasta") if not test: shutil.rmtree(self.mTempdir) return result
def create( self, infile ): """create profile library from file.""" self.mOutfileDatabase = open( self.mFilenameProfiles, "wb" ) outfile_index = open( self.mFilenameIndex, "w" ) ninput, noutput = 0, 0 while mali.readFromFile( sys.stdin, format="profile" ): ninput += 1 m = Mali.convertMali2Alignlib( mali ) p = alignlib.makeProfile( m ) p.prepare() self.add( mali.getName(), p ) noutput += 1 return ninput, noutput
def verify( self, infile ): """verify data in database against original data.""" if not self.mIndex: self.__loadIndex() ninput, nfound, nnotfound, ndifferent = 0,0,0,0 while mali.readFromFile( sys.stdin, format="profile" ): ninput += 1 m = Mali.convertMali2Alignlib( mali ) p1 = alignlib.makeProfile( m ) p1.prepare() p2 = self.getProfile( mali.getName() ) if p1.getLength() != p2.getLength() or \ str(p1) != str(p2): ndifferent += 1 continue nfound += 1 return ninput, nfound, nnotfound, ndifferent
parser.add_option("-w", "--weightor", dest="weightor", type="choice", choices=("none", "Henikoff", "HenikoffKimmen" ), help="sequence weightor to choose." ) parser.set_defaults( prefix = "profiles", action = "create", weightor = None, source = None, ) (options, args) = Experiment.Start( parser ) #-------------------------------------------------------- # main part of script mali = Mali.Mali() if options.action in ("create", "merge", "extract" ): mode = "w" else: mode = "r" plib = ProfileLibrary( options.prefix, mode ) plib.setWeightor( options.weightor ) if options.action == "verify": ninput, nfound, nnotfound, ndifferent = plib.verify(sys.stdin) if options.loglevel >= 1: options.stdlog.write( "# verify: ninput=%i, nfound=%i, nnotfound=%i, ndifferent=%i\n" % (ninput, nfound, nnotfound, ndifferent)) elif options.action == "create":