# Path: xenoGI/analysis.py
# def printTable(L,indent=0,fileF=sys.stdout):
#     '''Given tabular data in a list of lists (where sublists are rows)
# print nicely so columns line up. Indent is an optional number of blank spaces to put in front of each row.'''
#     # get max width for each column
#     colMax=[]
#     for col in range(len(L[0])):
#         mx=0
#         for row in L:
#             if len(row[col]) > mx:
#                 mx = len(row[col])
#         colMax.append(mx)
#     
#     # print
#     for row in L:
#         for col in range(len(row)):
#             row[col]=row[col]+' ' * (colMax[col]-len(row[col]))
#             
#     for row in L:
#         printStr = " "*indent + " | ".join(row)
#         print(printStr.rstrip(),file=fileF)


import sys,numpy,os,random,glob,copy,shutil
from scipy.signal import find_peaks
from Bio import Phylo
from multiprocessing import Pool
from . import blast,genomes,trees,scores,DTLOR_DP,new_DTLOR_DP,islands
from .Family import *
from .Island import *
from .Tree import *
from .analysis import printTable
        eventsInEntryL = []
        for eventT in value:
            eventsInEntryL.append(eventT[0])
        if event in eventsInEntryL:
            outL.append(geneTreeLoc)
    return outL

def splitTreeByOrigin(geneRtreeO,branchOriginL):
    '''Take a gene tree, and a list of branches where origin events
occur. Split the tree into multiple trees, where each origin event
defines the root of a new tree. Note that if there is no origin event
at the root (ie they come later) this may mean that some parts of the
gene tree are not included.

    '''
    originTreeL = []
    for branch in branchOriginL:
        originTreeL.append(geneRtreeO.subtree(branch))
    return originTreeL

def getGeneTreeReconPairs(originTreeL,mprNodeFormatD):
    '''Given a list of geneTrees (new origin families), extract the
corresponding parts from the mprNodeFormatD for each.'''

    geneTreeReconPairL = []
    for geneRtreeO in originTreeL:
        splitReconD = {}
        for geneTreeLoc in geneRtreeO.preorder():
            nbKey = (geneTreeLoc,'b')
            if nbKey in mprNodeFormatD:

# Path: xenoGI/analysis.py
# def printTable(L,indent=0,fileF=sys.stdout):
#     '''Given tabular data in a list of lists (where sublists are rows)
# print nicely so columns line up. Indent is an optional number of blank spaces to put in front of each row.'''
#     # get max width for each column
#     colMax=[]
#     for col in range(len(L[0])):
#         mx=0
#         for row in L:
#             if len(row[col]) > mx:
#                 mx = len(row[col])
#         colMax.append(mx)
#     
#     # print
#     for row in L:
#         for col in range(len(row)):
#             row[col]=row[col]+' ' * (colMax[col]-len(row[col]))
#             
#     for row in L:
#         printStr = " "*indent + " | ".join(row)
#         print(printStr.rstrip(),file=fileF)


# Path: xenoGI/families.py
import sys,numpy,os,random,glob,copy,shutil
from scipy.signal import find_peaks
from Bio import Phylo
from multiprocessing import Pool
from . import blast,genomes,trees,scores,DTLOR_DP,new_DTLOR_DP,islands
from .Family import *
from .Island import *
from .Tree import *
from .analysis import printTable

        eventsInEntryL = []
        for eventT in value:
            eventsInEntryL.append(eventT[0])
        if event in eventsInEntryL:
            outL.append(geneTreeLoc)
    return outL

def splitTreeByOrigin(geneRtreeO,branchOriginL):
    '''Take a gene tree, and a list of branches where origin events
occur. Split the tree into multiple trees, where each origin event
defines the root of a new tree. Note that if there is no origin event
at the root (ie they come later) this may mean that some parts of the
gene tree are not included.

    '''
    originTreeL = []
    for branch in branchOriginL:
        originTreeL.append(geneRtreeO.subtree(branch))
    return originTreeL

def getGeneTreeReconPairs(originTreeL,mprNodeFormatD):
    '''Given a list of geneTrees (new origin families), extract the
corresponding parts from the mprNodeFormatD for each.'''

    geneTreeReconPairL = []
    for geneRtreeO in originTreeL:
        splitReconD = {}
        for geneTreeLoc in geneRtreeO.preorder():
            nbKey = (geneTreeLoc,'b')
            if nbKey in mprNodeFormatD:

                splitReconD[nbKey] = mprNodeFormatD[nbKey]