Exemple #1
0
def traverseNewickTreeAndOutputToFile(node):
    if len(node.clades) > 0:
        traverseNewickTreeAndOutputToFile(node.clades[0])
        if len(node.clades) > 1:
            traverseNewickTreeAndOutputToFile(node.clades[1])
    if node.name != None and len(node.name) > 0:
        filteredList = iter(filter(lambda x: x.name == node.name, strains))
        foundStrain = next(filteredList, None)
        if foundStrain != None:
            outputStrainDetailsToFile(outputFileName, foundStrain)
Exemple #2
0
def createAncestor(strain1, strain2, neighborStrain):
    globals.ancestralCounter += 1
    ancestor = None
    ancestralName = 'Ancestor ' + str(globals.ancestralCounter)
    ancestralFragments = None

    strain1Copy = copy.deepcopy(
        strain1)  #Do a deep copy of object for when we compare to the neighbor
    neighborCopy = copy.deepcopy(
        neighborStrain
    )  #Do a deep copy of the neighbor as well b/c we don't want to store those comparisons in the strain either

    print(
        'Performing a series of alignments for the following strains: %s, %s' %
        (strain1.name, strain2.name))
    events, duplicatesStrain1, duplicatesStrain2 = constructEvents(
        strain1, strain2)

    print('Constructing dot plot for the following strains: %s, %s' %
          (strain1.name, strain2.name))
    points, lostPoints = normalizeIndexesForDotPlot(events, duplicatesStrain1,
                                                    duplicatesStrain2, strain1,
                                                    strain2)
    createDotPlot(points, strain1, strain2)

    createBarGraph(strain1.duplicationCounts,
                   'Distribution of Duplications for %s' % (strain1.name))
    createBarGraph(strain2.duplicationCounts,
                   'Distribution of Duplications for %s' % (strain2.name))
    createBarGraph(
        strain1.deletionCounts, 'Distribution of Deletions for %s' %
        (strain1.name))  #Remember! Deletions refer to the other strain!
    createBarGraph(
        strain2.deletionCounts, 'Distribution of Deletions for %s' %
        (strain2.name))  #Remember! Deletions refer to the other strain!

    #Compute and output the inverted, transposed, and inverted transposed regions
    FCR, TR, IR, ITR = determineRegions(points)
    #FCR, TR, IR, ITR, LR = computeOperonArrangements(events)  OLD VERSION

    #inversionDetails1, inversionDetails2 = computeRegionDetails(IR, 'Inversion:')
    #transpositionDetails1, transpositionDetails2 = computeRegionDetails(TR, 'Transposition:')
    #invertedTransposedDetails1, invertedTransposedDetails2 = computeRegionDetails(ITR, 'Inverted Transposition:')

    #Compare one of the siblings to the neighbor if one exists
    if neighborCopy != None:
        print(
            'Now performing a series of alignments between the nighboring strains: %s, %s'
            % (strain1Copy.name, neighborCopy.name))
        neighborEvents, duplicatesStrain1Copy, duplicatesStrainNeighbor = constructEvents(
            strain1Copy, neighborCopy)

        print('Constructing dot plot for the neighboring strains: %s, %s' %
              (strain1Copy.name, neighborCopy.name))
        neighborPoints, neighborLostPoints = normalizeIndexesForDotPlot(
            neighborEvents, duplicatesStrain1Copy, duplicatesStrainNeighbor,
            strain1Copy, neighborCopy)
        #createDotPlot(neighborPoints, strain1Copy, neighborCopy)

        #Compute the various regions for the neighbor
        #NFCR, NTR, NIR, NITR, NLR = computeOperonArrangements(neighborEvents) OLD VERSION
        NFCR, NTR, NIR, NITR = determineRegions(neighborPoints)
        ancestralFragments, strain1, strain2 = determineAncestralFragmentArrangementUsingNeighbor(
            FCR, TR, IR, ITR, lostPoints, NFCR, NTR, NIR, NITR,
            neighborLostPoints, strain1, strain2)
    else:
        if neighborCopy == None:
            print('No neighbor found!')
        elif len(TR) == 0 and len(IR) == 0 or len(ITR) == 0:
            print('No inverted or transposed regions detected!!')
        ancestralFragments, strain2 = determineAncestralFragmentArrangementWithoutNeighbor(
            FCR, TR, IR, ITR, lostPoints, strain2)

    #Computes the total number of inversions, transpositions, inverted transpositions
    globals.inversionCounter += len(IR)
    globals.transposedCounter += len(TR)
    globals.invertedTransposedCounter += len(ITR)

    #Increments the counters for the size distributions for each event type
    updateGlobalDeletionCounter(strain1)
    updateGlobalDeletionCounter(strain2)
    updateGlobalDuplicationCounter(strain1)
    updateGlobalDuplicationCounter(strain2)
    updateGlobalInversionSizeDistributionCounter(strain1)
    updateGlobalInversionSizeDistributionCounter(strain2)
    updateGlobalTranspositionSizeDistributionCounter(strain1)
    updateGlobalTranspositionSizeDistributionCounter(strain2)
    updateGlobalInvertedTranspositionSizeDistributionCounter(strain1)
    updateGlobalInvertedTranspositionSizeDistributionCounter(strain2)

    #Append all details to file here
    outputStrainDetailsToFile(outputFileName, strain1)
    outputStrainDetailsToFile(outputFileName, strain2)

    ancestor = BacterialStrain(ancestralName, ancestralFragments)
    return ancestor