コード例 #1
0
def splitReverseRedundancy(cycle, split):
    a1, a2 = getStartOfReverseRepeat(cycle, split.localCut, split.localCut,
                                     split.remoteCut, split.remoteCut)
    if (a1 - 1) % len(cycle) == split.localCut:
        # Double hairpin loop
        return []
    b1, b2 = getEndOfReverseRepeat(cycle, split.localCut, split.localCut,
                                   split.remoteCut, split.remoteCut)
    cycle = cycle.startAt(a1)
    a2 = (a2 - a1) % len(cycle)
    b1 = (b1 - a1) % len(cycle)
    b2 = (b2 - a1) % len(cycle)

    if b2 == 0 and a2 == b1:
        # Tandem dupe passage...?
        return [Event(Cycle(cycle[b1 + 1:]))]
    else:
        if len(cycle) == 0 or b1 + 1 >= b2 or a2 + 1 >= len(cycle) or cycle[
                b1 + 1].value is None or cycle[a2 + 1].value is None:
            print cycle
            print a2
            print b1
            print b2
            sys.stdout.flush()
        event1 = Event(Cycle(cycle[b1 + 1:b2]))
        event2 = Event(Cycle(cycle[a2 + 1:]))
        return [event1, event2]
コード例 #2
0
ファイル: sampleModuleCycles.py プロジェクト: xrigaru/cn-avg
def mergeCycles(cycleA, indexA, cycleB, indexB):
	b1, b2 = getEndOfRepeat(cycleA, indexA, indexA, cycleB, indexB, indexB) 
	cycleA = cycleA.startAt(b1+1)
	cycleB = cycleB.startAt(b2+1)
	a1, a2 = getStartOfRepeat(cycleA, 0, 0, cycleB, 0, 0) 

	merged = Event(Cycle(cycleA[:a1]) + Cycle(cycleB[:a2]).reverse())
	merged.setRatio(cycleA[0].value)

	residue = cycleB[0].value + cycleA[0].value
	if abs(residue) > ROUNDING_ERROR:
		return [merged, Event(Cycle(cycleB, residue))]
	else:
		return [merged]
コード例 #3
0
def fixHairpin(event, index):
    length = hairpinLength(event, index)
    if length < len(event.cycle) / 2:
        res = [Event(Cycle(event.cycle.startAt(index + 1)[length:-length]))]
        res[0].validate()
        return res
    else:
        return []
コード例 #4
0
def closePseudoTelomere(data, index):
    module, history = data
    PT = random.choice(list(module.pseudotelomeres))
    twin = module[PT].twin
    edge1 = Edge(PT, twin, module[PT].segment[index], index)
    module.removeEdgeFlow(edge1)
    edge2 = Edge(twin, module[twin].partner, -edge1.value, -1)
    module.removeEdgeFlow(edge2)
    module, edges = extractPseudoTelomereCycle(module, [edge1, edge2])
    history.absorbEvent(Event(Cycle(edges)))
    return module, history
コード例 #5
0
ファイル: sampleModuleCycles.py プロジェクト: xrigaru/cn-avg
def splitCycles(cycleA, indexA, cycleB, indexB, stub):
	b1, b2 = getEndOfRepeat(cycleA, indexA, indexA, cycleB, indexB, indexB) 
	cycleA = cycleA.startAt(b1+1)
	cycleB = cycleB.startAt(b2+1)
	a1, a2 = getStartOfRepeat(cycleA, 0, 0, cycleB, 0, 0) 

	shortCut = Cycle([Edge(cycleA[a1].start, stub, 0)])
	if a1 % 2 == 1:
		shortCut.append(Edge(stub, stub, 0))
	shortCut.append(Edge(stub, cycleA[0].start, 0))

	cycleAPrime = Event(Cycle(cycleA[:a1] + shortCut, cycleA[0].value))
	cycleBPrime = Event(Cycle(cycleB[:a2] + shortCut, cycleB[0].value))
	newCycles = [cycleAPrime, cycleBPrime]

	# Note: a1 and a2 have the same parity because a1 + len(shortCut) and a2 + len(shortCut) both even numbers. 
	if a1 % 2 == 0: 
		residue = cycleB[0].value + cycleA[0].value
	else:
		residue = -(cycleB[0].value + cycleA[0].value)
	if abs(residue) > ROUNDING_ERROR:
		newCycles.append(Event(Cycle(cycleA[a1:] + shortCut.reverse()), residue))
	return newCycles
コード例 #6
0
def splitDirectRedundancy(cycle, split):
    a1, a2 = getStartOfDirectRepeat(cycle, split.localCut, split.localCut,
                                    split.remoteCut, split.remoteCut)
    if (a1 - 1) % len(cycle) == split.localCut:
        # Double hairpin loop
        return []
    b1, b2 = getEndOfDirectRepeat(cycle, split.localCut, split.localCut,
                                  split.remoteCut, split.remoteCut)
    cycle = cycle.startAt(a1)
    a2 = (a2 - a1) % len(cycle)
    b1 = (b1 - a1) % len(cycle)
    b2 = (b2 - a1) % len(cycle)
    if b1 + 1 < a2 and b2 + 1 < len(cycle):
        return [
            Event(Cycle(cycle[b1 + 1:a2]) + Cycle(cycle[b2 + 1:]).reverse())
        ]
    elif b1 + 1 >= a2:
        # F*****g weird tandem repeat style craziness
        return [Event(Cycle(cycle[2 * a2:]))]
    else:
        # Symmetrical oddball
        cycle = cycle.startAt(a2)
        a1 = -a2 % len(cycle)
        return [Event(Cycle(cycle[2 * a1:]))]
コード例 #7
0
def extractCycle(edge, module):
    distances = dijkstra(edge.start,
                         edge.value,
                         module,
                         blockTwin=(edge.index >= 0))
    edgeList, module, success = extendCycle([edge], module, distances, -1)
    if success:
        edge_counts = Counter(E.adjacencyIndex() for E in edgeList)
        if max(edge_counts.values()) == 1:
            cycle = Cycle(edgeList)
        else:
            value = min(
                float(getAbsEdgeValue(E, module)) / edge_counts[E]
                for E in edge_counts)
            cycle = Cycle(edgeList, value=math.copysign(value, edge.value))

        return Event(cycle)
    else:
        return None
コード例 #8
0
ファイル: flattened.py プロジェクト: xrigaru/cn-avg
 def _unifyEvent(self, event):
     """ Return a flattened version of the event """
     return Event(self._unifyCycle(event.cycle))
コード例 #9
0
def breakEvenOverlap(event, knot):
    return [
        Event(Cycle(event.cycle[knot.localCut:knot.remoteCut])),
        Event(Cycle(event.cycle[knot.remoteCut:] +
                    event.cycle[:knot.localCut]))
    ]