def getAccessiblePaths(self, pathLength=0): # Stats for the entire network totalPaths = 0 # Total mutational paths (only shortest) allAccPaths = 0 # No. of accessible paths (only shortest) # Get the sequence with the highest score. This sequence # will represent the global peak. All paths use this # sequence as the target. summit = Utils.getSeqWithMaxScore(self.network, self.bitManip.seqLength) # Get the vertex object that represents the summit trgtVrtx = self.netUtils.getVertex(summit, self.network) # Store a copy of the summit self.summitId = trgtVrtx.index # Get a list of all sequences in the network sequences = self.network.vs["sequences"] # Remove the target itself sequences.remove(summit) # For each sequence in the network for source in sequences: # If we only need to calculate all accessible paths, regardless # of the path length, if pathLength == 0: # Get all shortest paths as well as all accessible # shortest paths from source to summit self.getShortestAccPaths(source, trgtVrtx, pathLength) else: # Ratios should be calculated shrtPaths, accPaths = self.getShortestAccPaths(source, trgtVrtx, pathLength + 1) # If at least one shortest path of length == 'pathLength' was # found, if shrtPaths: # Increment the counts totalPaths += float(len(shrtPaths)) allAccPaths += float(len(accPaths)) try: return float(allAccPaths) / float(totalPaths) except ZeroDivisionError: return 0
def populateDistsToSummit(self) : # Convenient handle for bitManip bm = self.bitManip # Get the summit sequence summit = Utils.getSeqWithMaxScore(self.network, self.bitManip.seqLength) # Get vertex that represents summit trgtVrtx = self.netUtils.getVertex(summit, self.network) # Reference to the list of sequences in the network vertices = [ self.netUtils.getVertex(seq, self.network) \ for seq in self.network.vs["sequences"] ] self.network.vs["Distance from Summit"] = \ [ len(self.network.get_shortest_paths(srcVrtx, to=trgtVrtx, \ weights=None, mode=igraph.OUT, output="epath")[0]) \ for srcVrtx in vertices ]