Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
benedictpaten committed Feb 13, 2013
1 parent 0ffe2dd commit eeb3c58
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DNAHistoryGraph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def threadCmp(self, thread1, thread2):
## Output
##################################
def dot(self):
return "\n".join(["digraph G {"] + [X.dot() for X in self.eventGraph] + ["}"])
return "\n".join(["digraph G {" ] + [X.dot() for X in self.eventGraph] + ["}"])

##################################
## Validation
Expand Down
14 changes: 10 additions & 4 deletions DNAHistoryGraph/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,21 @@ def threads(self, data):
##########################
def dot(self):
if self.label != None:
label = str(self.label)
labelColour = { 'A':"greenyellow", 'C':'rosybrown', 'G':"powderblue", 'T':"plum" }[str(self.label)]
else:
label = ""
lines = ['%i [label="%s"]' % (id(self), label)]
labelColour = "white"
colour = "black"
if self.parent == None:
colour = "grey"
lines = ['%i [label="", style=filled, fillcolor=%s, width=0.25, height=0.25, color=%s, fixedsize=true]' % (id(self), labelColour, colour)]
if self.parent is not None:
if (self.label != None and self.ancestor().label == self.label) or (self.label == None and len(self.liftedLabels().intersection(self.ancestor().nonTrivialLiftedLabels())) == 0):
lines.append('%i -> %i [color=green, weight=1000]' % (id(self.parent), id(self)))
else:
lines.append('%i -> %i [color=blue, weight=1000]' % (id(self.parent), id(self)))
if self.parent.parent == None:
lines.append('%i -> %i [color=lightblue, weight=1000]' % (id(self.parent), id(self)))
else:
lines.append('%i -> %i [color=blue, weight=1000]' % (id(self.parent), id(self)))
lines.append(self.left.dot())
if self.left.bond is not self.right:
lines.append(self.right.dot())
Expand Down
7 changes: 5 additions & 2 deletions DNAHistoryGraph/side.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,18 @@ def fn(side):
if self.bond is not None:
if self <= self.bond:
l.append("%i -> %i [color=red, dir=both, arrowtail=%s, arrowhead=%s]" % (id(self.segment), id(self.bond.segment), fn(self), fn(self.bond)))


if self.isModuleMaterial():
nonTrivialLiftedBonds = self.nonTrivialLiftedBonds()
for descendant in self.liftedBonds():
linkedAncestor = descendant.bond.ancestor()
colour = "cyan"
if descendant in nonTrivialLiftedBonds:
colour = "magenta"
if self < linkedAncestor:
l.append("%i -> %i [color=%s, dir=both, arrowtail=%s, arrowhead=%s, weight=0]" % (id(self.segment), id(linkedAncestor.segment), colour, fn(self), fn(linkedAncestor)))
if self < linkedAncestor:
l.append("%i -> %i [color=%s, dir=both, arrowtail=%s, arrowhead=%s, weight=0]" % (id(self.segment), id(linkedAncestor.segment), colour, fn(self), fn(linkedAncestor)))

return "\n".join(l)

##############################
Expand Down
10 changes: 5 additions & 5 deletions process/deAVG.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
from pyAVG.DNAHistoryGraph.graph import DNAHistoryGraph
from pyAVG.inputs.simulator import RandomHistory

def deAVG(avg, removalDensity=0.1, labelRemovalDensity=0.5, bondRemovalDensity=0.25):
def deAVG(avg, removalDensity=0.1, labelRemovalDensity=0.1, bondRemovalDensity=0.1):
# Copy graph
graph = copy.copy(avg)

# Remove all non-root or leaf segments
for segment in list(graph.segments):
if random.random() < removalDensity and segment.parent != None:
if segment.parent != None and (random.random() < removalDensity or len(segment.children) > 0):
segment.disconnect()
graph.segments.remove(segment)
else:
if random.random() < labelRemovalDensity:
if random.random() < labelRemovalDensity or len(segment.liftedLabels()) > 0:
segment.label = None
if random.random() < bondRemovalDensity:
if random.random() < bondRemovalDensity or len(segment.left.liftedBonds()) > 0:
segment.left.deleteBond()
if random.random() < bondRemovalDensity:
if random.random() < bondRemovalDensity or len(segment.right.liftedBonds()) > 0:
segment.right.deleteBond()

for segment in list(graph.segments): #Get rid of useless nodes
Expand Down
32 changes: 27 additions & 5 deletions scripts/scriptsForAVGTheoryPaper/simulationsForPaperScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,50 @@
"""

def main():
experimentNumber = 20
iterationNumber = 1000
experimentNumber = 5
iterationNumber = 1
startTime = time.time()
last = startTime
results = []
experiment = 0
segmentNumber = 5
epochs = 5

outputDir = "results"
system("mkdir %s" % outputDir)

while experiment < experimentNumber:
#Create a random history
history = RandomHistory(10, 5)
history = RandomHistory(segmentNumber, epochs)
avg = history.avg()

def breakAllHomologousSides(side, graph):
if side.bond != None:
graph.deleteBond(side)
for child in side.children():
breakAllHomologousSides(child, graph)

def homologousSidesHaveOnlyTrivialLifts(side):
if side.bond != None and len(side.nonTrivialLiftedBonds()) > 0:
return False
for child in side.children():
if not homologousSidesHaveOnlyTrivialLifts(child):
return False
return True

sidesToBreak = [ side for side in avg.sides() if side.parent() == None and homologousSidesHaveOnlyTrivialLifts(side) ]
if len(sidesToBreak) > 0:
breakAllHomologousSides(sidesToBreak[0], avg)

#Undo stuff in the first graph
baseGraph = deAVG(avg)
assert avg.ambiguity() == 0
assert avg.substitutionAmbiguity() == 0
assert avg.rearrangementAmbiguity() == 0
assert avg.lowerBoundRearrangementCost() == avg.upperBoundRearrangementCost()
assert baseGraph.lowerBoundRearrangementCost() <= avg.lowerBoundRearrangementCost()

if baseGraph.substitutionAmbiguity() == 0 or baseGraph.rearrangementAmbiguity() == 0:
#Selection of histories with what we want
if avg.lowerBoundRearrangementCost() == 0 or avg.lowerBoundSubstitutionCost() == 0 or baseGraph.substitutionAmbiguity() == 0 or baseGraph.rearrangementAmbiguity() == 0 or len([ segment for segment in baseGraph.segments if len(segment.children) == 0 ]) != 4*segmentNumber:
continue

def reportGraph(graph, graphName, iteration, step):
Expand Down

0 comments on commit eeb3c58

Please sign in to comment.