def _addHPList(self, HPListToAdd): """ Takes either an int (converted to a list in place) or a list of ints Filters that list to ensure it doesn't overlap with HPList """ if type(HPListToAdd) == int: HPListToAdd = [HPListToAdd] HPListToAdd = bf.CleanList( [x for x in HPListToAdd if x not in self.HPList]) if HPListToAdd == []: return # PrevHPList is a list of all previous HPLists held by this HairpinList self.PrevHPList.append(list(self.HPList)) # Clean the sum of InnerHPs and the new, non-intersecting-with-HPList stuff to be added self.HPList = bf.CleanList(self.InnerHPs + HPListToAdd) self.HPList = self._getAllConnectingHPs(self.HPList, 0) self.categorizeHPs() if len(self ) > self.maxlength: #Checks to see if the length is too long self._resetHPList() self.AddedLast = 'no' else: self._checkHPList( ) #Checks things like whether we added new HPs or not
def getBulgesConnectingHPs(self, HP, HPList): # print("Hmmm", HPList) ChildBulges = bf.getAttributeOfFeatFromMemberID( Bulge, 'parentHPID', HPList, 'ID', 'any') ParentBulges = bf.getAttributeOfFeatFromMemberID( Bulge, 'childHPID', HPList, 'ID', 'any') return bf.CleanList([ChildBulges + ParentBulges for x in HPList])
def getShellHPs(self): #Returns HPs that are being replaced by bulges BulgeHPs = bf.CleanList( [self.FG.HP[x].neighborID for x in self.SubHPs]) BulgeHPs = [ x for x in BulgeHPs if x not in self.InnerHPs + self.OuterHPs ] return BulgeHPs
def _getAllConnectingHPs(self, HPList, IncludeParentFlag=0): FG = self.FG ParentHP = self.findParentHP(HPList) if type(ParentHP) == int: ParentHP = [ParentHP] if ParentHP not in HPList and IncludeParentFlag ==1 and ParentHP!=[]: HPList.insert(0, ParentHP) # Gets all connecting HPs, searches for their children, and then repeats to be sure HPsConnectingList = bf.FlattenList([HPList]) # for j in range(0,1): #Repeats twice for i in range(0, len(HPList) - 1): for j in range(i, len(HPList)): HPsConnectingList.append( self.getPathBetweenHPs([HPList[i], HPList[j]], 0)) HPsConnectingList = bf.CleanList(HPsConnectingList) # for x in HPsConnectingList: # print(":", any(elem in FG.HP[x].childrenID for elem in HPsConnectingList)) # print("LeafHPs", HPList, "are as follows:", LeafHPs) NeighboringHPs = [FG.HP[x].neighborID for x in HPsConnectingList] HPsConnectingList = bf.CleanList(HPsConnectingList + NeighboringHPs) return list(sorted(HPsConnectingList))
def _getBulgeIdx(self): FG = self.FG InnerHPs = list(self.InnerHPs ) #HPs that are included and are sufficiently isolated OuterHPs = list(self.OuterHPs) SubHPs = list( self.SubHPs ) #Outer HPs that are sufficiently long to directly replace safely ShellHPs = list( self.StapleHPs ) #Outer HPs that are not long enough to directly replace BulgeHPs = list(self.ShellHPs) #OuterHPs that Bulges = [ FG.HP[x].Bulge5p + FG.HP[x].Bulge3p for x in InnerHPs + SubHPs ] Bulges += [FG.HP[x].Bulge5p for x in BulgeHPs + ShellHPs] return list(sorted(bf.CleanList(Bulges)))
def findParentHP(self, start=False): temp_HPList = None if start: temp_HPList = self.StartHPList else: temp_HPList = self.HPList if type(temp_HPList) == int: temp_HPList = [int] temp_HPList = bf.CleanList(temp_HPList) for i in temp_HPList: progenyIDs = list(self.FG.HP[i].progenyID + [i]) if all(elem in progenyIDs for elem in temp_HPList): return i ParentIDs = [self.FG.HP[x].parentID for x in temp_HPList] ParentIDs = [x for x in ParentIDs if x != []] minParent = min(ParentIDs)[0] for i in list(reversed(range(0, minParent + 1))): progenyIDs = list(self.FG.HP[i].progenyID + [i]) if all(elem in progenyIDs for elem in HPList): return [i] return []
def _getHPIdx(self): return list( sorted( bf.CleanList( [self.FG.HP[x].idx for x in self.InnerHPs + self.SubHPs])))