# Path: xenoGI/parameters.py
# def createParametersD(baseParamStr,paramFN):
# def addParametersToD(paramL,paramD):
# def loadFileNameMapD(fileNameMapFN,genbankFileList=None):
# 
# Path: xenoGI/blast.py
# def runBlast(dbFileL_1,dbFileL_2,paramD):
# def getDbFileL(fastaFilePath,strainNamesT):
# def formatDb(dbFileL,blastExecutDirPath):
# def makeBlastClineList(dbFileL_1, dbFileL_2,paramD):
# def processCline(cline):
# def determineShouldBlast(dbFile1,dbFile2,blastFilePath,blastFileJoinStr):
# def subprocessWrapper(cline):
# def parseBlastFile(blastFN,evalueThresh,alignCoverThresh,percIdentThresh):
#                 L = list(blastCLineT) + ['-query',query,'-db',db,'-out',outFN]
#     L = cline.split('"') # " make emacs happy.
#     L=[]
# 
# 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/xenoGI.py
# def main():
# def parseGenbankWrapper(paramD):
# def writeStrainInfoFN(strainNamesT,paramD):
# def readStrainInfoFN(strainInfoFN):
# def runBlastWrapper(paramD):
# def loadGenomeRelatedData(paramD):
# def calcScoresWrapper(paramD,blastFnL):
# def makeSpeciesTreeWrapper(paramD):
# def loadTreeRelatedData(speciesTreeFN):
# def makeFamiliesWrapper(paramD):
# def makeIslandsWrapper(paramD):
# def refineWrapper(paramD):
# def printAnalysisWrapper(paramD,speciesTreeFN,rootFocalClade):
# def createIslandBedWrapper(paramD):
# def interactiveAnalysisWrapper(paramD):
#     def printFam(familyNum,familiesO,fileF=sys.stdout):
#     def findGene(searchStr,fileF=sys.stdout):
#     def printLocusIsland(locusIslandNum,synWSize,fileF=sys.stdout):
#     def printLocusIslandsAtNode(node,fileF=sys.stdout):
# def debugWrapper(paramD):
#         L=matchFamilyIsland(genesO,gene2FamIslandD,searchStr)


import sys,os
from xenoGI import parameters,blast,genomes,xenoGI
    
    evalueThresh = paramD['evalueThresh']
    alignCoverThresh = paramD['alignCoverThresh']
    percIdentThresh =  paramD['percIdentThresh']
    blastFilePath = paramD['blastFilePath']
    blastFileJoinStr = paramD['blastFileJoinStr']

    # Blast them vs. all strains
    fastaDir = paramD['fastaFilePath'].split('*')[0]
    allStrainsFileNamesL = []
    for strain in strainNamesT:
        allStrainsFileNamesL.append(os.path.join(fastaDir,strain+"_prot.fa"))

    blast.runBlast([proteinMultiFastaPath],allStrainsFileNamesL,paramD)
    
    # parse blast to identify ifams with similarity to model seqs
    blastDir = os.path.split(blastFilePath)[0]

    proteinMultiFastaFN = os.path.split(proteinMultiFastaPath)[-1]
    # remove _prot.fa
    proteinMultiFastaFN = proteinMultiFastaFN.split("_prot.fa")[0]

    # if additional extension
    proteinMultiFastaStem = os.path.splitext(proteinMultiFastaFN)[0]
    
    outS = set()
    for strainName in strainNamesT:
        # remove dir (if any) from proteinMultiFastaPath
        fileStr = proteinMultiFastaStem+blastFileJoinStr+strainName+'.out'
        fn = os.path.join(blastDir,fileStr)

# Path: xenoGI/parameters.py
# def createParametersD(baseParamStr,paramFN):
# def addParametersToD(paramL,paramD):
# def loadFileNameMapD(fileNameMapFN,genbankFileList=None):
# 
# Path: xenoGI/blast.py
# def runBlast(dbFileL_1,dbFileL_2,paramD):
# def getDbFileL(fastaFilePath,strainNamesT):
# def formatDb(dbFileL,blastExecutDirPath):
# def makeBlastClineList(dbFileL_1, dbFileL_2,paramD):
# def processCline(cline):
# def determineShouldBlast(dbFile1,dbFile2,blastFilePath,blastFileJoinStr):
# def subprocessWrapper(cline):
# def parseBlastFile(blastFN,evalueThresh,alignCoverThresh,percIdentThresh):
#                 L = list(blastCLineT) + ['-query',query,'-db',db,'-out',outFN]
#     L = cline.split('"') # " make emacs happy.
#     L=[]
# 
# 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/xenoGI.py
# def main():
# def parseGenbankWrapper(paramD):
# def writeStrainInfoFN(strainNamesT,paramD):
# def readStrainInfoFN(strainInfoFN):
# def runBlastWrapper(paramD):
# def loadGenomeRelatedData(paramD):
# def calcScoresWrapper(paramD,blastFnL):
# def makeSpeciesTreeWrapper(paramD):
# def loadTreeRelatedData(speciesTreeFN):
# def makeFamiliesWrapper(paramD):
# def makeIslandsWrapper(paramD):
# def refineWrapper(paramD):
# def printAnalysisWrapper(paramD,speciesTreeFN,rootFocalClade):
# def createIslandBedWrapper(paramD):
# def interactiveAnalysisWrapper(paramD):
#     def printFam(familyNum,familiesO,fileF=sys.stdout):
#     def findGene(searchStr,fileF=sys.stdout):
#     def printLocusIsland(locusIslandNum,synWSize,fileF=sys.stdout):
#     def printLocusIslandsAtNode(node,fileF=sys.stdout):
# def debugWrapper(paramD):
#         L=matchFamilyIsland(genesO,gene2FamIslandD,searchStr)


# Path: misc/getProteinsWithBlastHitsVsMultifasta.py
import sys,os
from xenoGI import parameters,blast,genomes,xenoGI

    
    evalueThresh = paramD['evalueThresh']
    alignCoverThresh = paramD['alignCoverThresh']
    percIdentThresh =  paramD['percIdentThresh']
    blastFilePath = paramD['blastFilePath']
    blastFileJoinStr = paramD['blastFileJoinStr']

    # Blast them vs. all strains
    fastaDir = paramD['fastaFilePath'].split('*')[0]
    allStrainsFileNamesL = []
    for strain in strainNamesT:
        allStrainsFileNamesL.append(os.path.join(fastaDir,strain+"_prot.fa"))

    blast.runBlast([proteinMultiFastaPath],allStrainsFileNamesL,paramD)
    
    # parse blast to identify ifams with similarity to model seqs
    blastDir = os.path.split(blastFilePath)[0]

    proteinMultiFastaFN = os.path.split(proteinMultiFastaPath)[-1]
    # remove _prot.fa
    proteinMultiFastaFN = proteinMultiFastaFN.split("_prot.fa")[0]

    # if additional extension
    proteinMultiFastaStem = os.path.splitext(proteinMultiFastaFN)[0]
    
    outS = set()
    for strainName in strainNamesT:
        # remove dir (if any) from proteinMultiFastaPath
        fileStr = proteinMultiFastaStem+blastFileJoinStr+strainName+'.out'
        fn = os.path.join(blastDir,fileStr)

        for g1,g2,evalue,alCov,pident,score in blast.parseBlastFile(fn,evalueThresh,alignCoverThresh,percIdentThresh):    