コード例 #1
0
ファイル: ConstrainedNJ.py プロジェクト: kaspermunch/sap
    def consensusTree(self, iterations):

        import tempfile
        from SAP.Bio.Nexus import Trees as NexusTrees

        tmpFile, tmpFileName = tempfile.mkstemp()
        self.dumpBootstrapTreesNexus(iterations, tmpFileName)
        bootstrapTrees = Nexus.Nexus(tmpFileName)
        tmpFile.close()
        os.remove(tmpFileName)        
        consensusTree = NexusTrees.consensus(bootstrapTrees.trees)

        return "#NEXUS\n\nbegin trees;\n   " + consensusTree.to_string() + "\nend;\n"
コード例 #2
0
ファイル: ConstrainedNJ.py プロジェクト: cbirdlab/sap
    def consensusTree(self, iterations):

        import tempfile
        from SAP.Bio.Nexus import Trees as NexusTrees

        tmpFile, tmpFileName = tempfile.mkstemp()
        self.dumpBootstrapTreesNexus(iterations, tmpFileName)
        bootstrapTrees = Nexus.Nexus(tmpFileName)
        tmpFile.close()
        os.remove(tmpFileName)
        consensusTree = NexusTrees.consensus(bootstrapTrees.trees)

        return "#NEXUS\n\nbegin trees;\n   " + consensusTree.to_string(
        ) + "\nend;\n"
コード例 #3
0
ファイル: NeighbourJoinWrapper.py プロジェクト: cbirdlab/sap
    def run(self, alignmentFileName):
        """
        Run neighbour join bootstrap on alignment
        Returns name of tree file
        """

        baseName = os.path.splitext(os.path.split(alignmentFileName)[-1])[0]
        treeFileName = os.path.join(self.options.treescache,
                                    baseName + ".nex.nj.tree")

        print "%s: Sampling trees: " % baseName,
        sys.stdout.flush()

        # TODO: The way we check if there are cached results is not safe. The file may not be complete.
        if os.path.exists(treeFileName):
            print "Using cached results."
            sys.stdout.flush()
        else:
            print "Computing...",
            sys.stdout.flush()

            constraintTreeFileName = os.path.join(self.options.homologcache,
                                                  baseName + ".nex")
            constraintTreeFile = open(constraintTreeFileName, 'r')
            constraintTree = Nexus.Nexus(constraintTreeFile).trees[0]

            queryName = baseName
            alignment = Nexus.Nexus(alignmentFileName)
            nj = NeighbourJoin.NeighbourJoin(alignment,
                                             queryName=queryName,
                                             constraintTree=constraintTree)
            nj.dumpBootstrapTrees(self.options.bootstraps, treeFileName)

            bootstrapTrees = Nexus.Nexus(treeFileName)
            consensusTree = NexusTrees.consensus(bootstrapTrees.trees)
            consensusTreeFileName = os.path.join(self.options.treescache,
                                                 baseName + ".nj.con")

            s = "#NEXUS\n\nbegin trees;\n   " + consensusTree.to_string(
            ) + "\nend;\n"
            writeFile(consensusTreeFileName, s)

            print "done."
            sys.stdout.flush()
コード例 #4
0
    def run(self, alignmentFileName):
        """
        Run neighbour join bootstrap on alignment
        Returns name of tree file
        """

        baseName = os.path.splitext(os.path.split(alignmentFileName)[-1])[0]
        treeFileName = os.path.join(self.options.treescache, baseName + ".nex.nj.tree")

        print "%s: Sampling trees: " % baseName,
        sys.stdout.flush()

        # TODO: The way we check if there are cached results is not safe. The file may not be complete.
        if os.path.exists(treeFileName):
            print "Using cached results."
            sys.stdout.flush()
        else:
            print "Computing...",
            sys.stdout.flush()

            constraintTreeFileName = os.path.join(self.options.homologcache, baseName + ".nex")
            constraintTreeFile = open(constraintTreeFileName, 'r')
            constraintTree = Nexus.Nexus(constraintTreeFile).trees[0]

            queryName = baseName
            alignment = Nexus.Nexus(alignmentFileName)
            nj = NeighbourJoin.NeighbourJoin(alignment, queryName=queryName, constraintTree=constraintTree)
            nj.dumpBootstrapTrees(self.options.bootstraps, treeFileName)

            bootstrapTrees = Nexus.Nexus(treeFileName)
            consensusTree = NexusTrees.consensus(bootstrapTrees.trees)
            consensusTreeFileName = os.path.join(self.options.treescache, baseName + ".nj.con")

            s = "#NEXUS\n\nbegin trees;\n   " + consensusTree.to_string() + "\nend;\n"
            writeFile(consensusTreeFileName, s)

            print "done."
            sys.stdout.flush()