Example #1
0
 def createfile(self, *arg, **params):
     global file_dir
     if not file_dir:
         file_dir = ProfileFunc.GetBoxDisks(False)[0]
     if params.get("docname"):
         file_path = os.path.join(file_dir,params.get("docname"))
         createFile(file_path,False,{'size':1})
     return self.index(storages=file_dir)
Example #2
0
#                       main
######################################################
print('Starting application...')
startTime = time.time()

globals.initialize()  #Initialize the globals file

if globals.printToConsole:
    print('Reading newick tree from file: %s...' % (newickFileName))
newickTree = Phylo.read(newickFileName, 'newick')

if globals.printToConsole:
    Phylo.draw(newickTree)

globals.strains = strains  #Assign pointer to the global strains array so we can access it anywhere
createFile(outputFileName, newickTree)  #Creates file where data will be output

#Traverses the newick tree recursively reconstructing ancestral genomes
if globals.printToConsole:
    print('Traversing newick tree...')
result = traverseNewickTree(newickTree.clade, None)

endTime = time.time()
totalTime = endTime - startTime

if globals.printToConsole:
    #Output newick tree after the ancestors have been added to it
    Phylo.draw(newickTree)

#Output ancestral genome to console
root = newickTree.clade
Example #3
0
def main():
    globals.initialize()  #Initialize the globals file

    global newickFileName
    global outputFileName
    global testFileName

    if len(sys.argv) != 3:
        print "WARNING: Must provide a Newick tree and test folder name. Exiting..."
        sys.exit(0)

    newickFileName = sys.argv[1]
    if newickFileName == "tree2LeafNeighbour.dnd":
        outputFileName = sys.argv[2] + "/ApplicationNeighbourOutput.txt"
    else:
        outputFileName = sys.argv[2] + "/ApplicationOutput.txt"
    testFileName = sys.argv[2] + '/'

    print('Starting application...')
    startTime = time.time()

    if globals.printToConsole:
        print('Reading newick tree from file: %s...' % (newickFileName))
    newickTree = Phylo.read(newickFileName, 'newick')
    if globals.printToConsole:
        Phylo.draw(newickTree)

    globals.strains = strains  #Assign pointer to the global strains array so we can access it anywhere
    createFile(outputFileName,
               newickTree)  #Creates file where data will be output

    #Traverses the newick tree recursively reconstructing ancestral genomes
    if globals.printToConsole:
        print('Traversing newick tree...')
    result = traverseNewickTree(newickTree.clade, None)

    endTime = time.time()
    totalTime = endTime - startTime

    #Output ancestral genome to console
    if globals.printToConsole:
        print('This is the root ancestral genome!')

    root = newickTree.clade
    rootGenome = []
    if newickFileName == "tree2LeafNeighbour.dnd":
        if len(root.clades) == 2:
            child = root.clades[0]
            if len(child.clades) != 2:
                child = root.clades[1]
                neighbour = root.clades[0]
            else:
                neighbour = root.clades[1]
            if child.name != None and len(child.name) > 0:
                filteredList = iter(
                    filter(lambda x: x.name == child.name, strains))
                foundStrain = next(filteredList, None)
                if foundStrain != None:
                    ancestralFragments = foundStrain.genomeFragments
                    rootGenome = ', '.join(fragment.originalSequence
                                           for fragment in ancestralFragments)

            with open(testFileName + "appNeighbourRoot.txt", "w+") as f:
                f.write(rootGenome)
            neighbour.name = ''
            child.name = ''
    else:
        if root.name != None and len(root.name) > 0:
            filteredList = iter(filter(lambda x: x.name == root.name, strains))
            foundStrain = next(filteredList, None)
            if foundStrain != None:
                ancestralFragments = foundStrain.genomeFragments
                rootGenome = ', '.join(fragment.originalSequence
                                       for fragment in ancestralFragments)

        with open(testFileName + "appRoot.txt", "w+") as f:
            f.write(rootGenome)

    if globals.printToConsole:
        #Output newick tree after the ancestors have been added to it
        Phylo.draw(newickTree)

    #Need to traverse tree to ouput appropriate content to file
    newickTree.clade.name = ''  #Make sure that the output for the root is not output
    traverseNewickTreeAndOutputToFile(newickTree.clade)

    #Output the totals for the computation to console and file
    outputTotalsToFile(outputFileName, totalTime)

    #TODO compute lineage
    #target = 'NC_014019'
    #print('Computing lineage cost for: %s' % (target))
    #lineageCost = computeLineageCost(newickTree.clade, target, None)
    #if lineageCost != None:
    #print('Successfully found and computed the lineage for: %s' % (target))

    #Output Bar graphs of each event
    if globals.printToConsole:
        createBarGraph(globals.deletionSizeCounter,
                       'Distribution of Deletions')
        createBarGraph(globals.duplicationSizeCounter,
                       'Distribution of Duplications')
        createBarGraph(globals.inversionSizeDistributionCounter,
                       'Distribution of Inversions')
        createBarGraph(globals.transpositionSizeDistributionCounter,
                       'Distribution of Transpositions')
        createBarGraph(globals.invertedTranspositionSizeDistributionCounter,
                       'Distribution of Inverted Transpositions')

    print('Total time (in seconds): %s' % (totalTime))
    print('Ending application...')
Example #4
0
    #Case 3: Only the right sibling exists so return it
    elif rightSibling != None and rightSibling.genomeFragments != None and len(
            rightSibling.genomeFragments) > 0:
        return rightSibling
    #Case 4: None of the siblings exist so return NULL
    else:
        return None


######################################################
#                       main
######################################################
print('Starting application...')
startTime = time.time()

globals.initialize()
createFile(outputFileName)  #Creates file where data will be output

print('Reading newick tree from file: %s...' % (newickFileName))
newickTree = Phylo.read(newickFileName, 'newick')
Phylo.draw(newickTree)

#Traverses the newick tree recursively reconstructing ancestral genomes
print('Traversing newick tree...')
result = traverseNewickTree(newickTree.clade, None)

endTime = time.time()
totalTime = endTime - startTime
print('Total time (in seconds): %s' % (totalTime))

print('Ending application...')