# Path: xenoGI/genomes.py
# def loadSeq(paramD,fileEnding,genesS=None):
#     def __init__(self, geneInfoFN):
#     def initializeGeneRangeByStrainD(self,geneInfoFN):
#     def initializeStrainGeneRangeT(self):
#     def initializeGeneNumToNameD(self,geneInfoFN,strainNamesL=None):
#     def initializeGeneInfoD(self,geneInfoFN,strainNamesL=None):
#     def loadDictFromGeneInfoFile(self,geneInfoFN,strainNamesL,onlyNames):
#     def numToStrainName(self,geneNum):
#     def numToName(self,geneNumber):
#     def iterGenes(self,strainL=None):
#     def iterGenesStrain(self,strainName):
#     def numToGeneInfo(self,geneNumber):
#     def __len__(self):
#     def __repr__(self):
# def getProximityInWindow(geneWinT,geneProximityD):
# def createGeneProximityD(geneOrderD,geneProximityForGroup):
# def createGeneOrderD(geneOrderFN,strainNamesL):
# class genes:
#         D = {}
#         L=s.split('\t')
# 
# Path: xenoGI/fasta.py
# def load(filename):


from Bio import Phylo
from multiprocessing import Pool
from .Tree import *
from xenoGI import genomes,fasta
import glob,os,shutil,subprocess

def prepareTree(bpTree,outGroupTaxaL):
    '''Given a biopython unrooted tree object (e.g. ASTRAL output) root,
name the internal nodes, and strip branch lengths (if
any). outGroupTaxaL provides the outgroups for rooting. Return
resulting tree in four tuple form.

    '''
    # strip confidence values in internal nodes (which mess up our
    # names)
    for n in bpTree.get_nonterminals():
        n.confidence = None
    
    bpTree = rootTree(bpTree,outGroupTaxaL)
    bpTree = nameInternalNodes(bpTree,"s")

    return bpTree

def rootTree(bpTree,outGroupTaxaL):
    '''Given a bio python tree, root it. outGroupTaxaL should consist of
all the species in the desired outgroup clade.'''

    bpTree.root_with_outgroup(*outGroupTaxaL)
    # rooting with outgroups with multiple species seems to leave a
    # trifurcating root.
    if len(bpTree.root)==2:
        return bpTree
    else:
        return makeRootBifurcation(bpTree,outGroupTaxaL)        


# Path: xenoGI/genomes.py
# def loadSeq(paramD,fileEnding,genesS=None):
#     def __init__(self, geneInfoFN):
#     def initializeGeneRangeByStrainD(self,geneInfoFN):
#     def initializeStrainGeneRangeT(self):
#     def initializeGeneNumToNameD(self,geneInfoFN,strainNamesL=None):
#     def initializeGeneInfoD(self,geneInfoFN,strainNamesL=None):
#     def loadDictFromGeneInfoFile(self,geneInfoFN,strainNamesL,onlyNames):
#     def numToStrainName(self,geneNum):
#     def numToName(self,geneNumber):
#     def iterGenes(self,strainL=None):
#     def iterGenesStrain(self,strainName):
#     def numToGeneInfo(self,geneNumber):
#     def __len__(self):
#     def __repr__(self):
# def getProximityInWindow(geneWinT,geneProximityD):
# def createGeneProximityD(geneOrderD,geneProximityForGroup):
# def createGeneOrderD(geneOrderFN,strainNamesL):
# class genes:
#         D = {}
#         L=s.split('\t')
# 
# Path: xenoGI/fasta.py
# def load(filename):


# Path: xenoGI/trees.py
from Bio import Phylo
from multiprocessing import Pool
from .Tree import *
from xenoGI import genomes,fasta
import glob,os,shutil,subprocess


def prepareTree(bpTree,outGroupTaxaL):
    '''Given a biopython unrooted tree object (e.g. ASTRAL output) root,
name the internal nodes, and strip branch lengths (if
any). outGroupTaxaL provides the outgroups for rooting. Return
resulting tree in four tuple form.

    '''
    # strip confidence values in internal nodes (which mess up our
    # names)
    for n in bpTree.get_nonterminals():
        n.confidence = None
    
    bpTree = rootTree(bpTree,outGroupTaxaL)
    bpTree = nameInternalNodes(bpTree,"s")

    return bpTree

def rootTree(bpTree,outGroupTaxaL):
    '''Given a bio python tree, root it. outGroupTaxaL should consist of
all the species in the desired outgroup clade.'''

    bpTree.root_with_outgroup(*outGroupTaxaL)
    # rooting with outgroups with multiple species seems to leave a
    # trifurcating root.
    if len(bpTree.root)==2:
        return bpTree
    else:
        return makeRootBifurcation(bpTree,outGroupTaxaL)        


def makeRootBifurcation(bpTree,outGroupTaxaL):