Commit dda7a660 authored by Lucianna Osucha's avatar Lucianna Osucha

Added a robust linked list, did basically nothing on protloc

parent c2cc764a
......@@ -8,18 +8,23 @@ import sys
import os
from __init__ import *
from util.AminoChain import *
from struct import *
from util.misc_util import *
filename = os.path.abspath(mypath + 'locStrings.txt')
try:
m_locstrings = open(filename, 'r')
f_locStrings = open(filename, 'r')
except OSError as e:
print("[!!FATAL!!] Error opening \"" + filename + "\"\n", file=sys.stderr)
raise
print("[!!FATAL!!] Error opening \"" + filename + "\"\n", file=sys.stderr)
raise
locStrings = DoubleLinkedList(f_locstrings.readlines())
while locStrings.next != None
if locStrings.data.substring(0,1) == "#":
locStrings = locStrings.remove()
#TODO
def tagLocStrings(aac:AminoAcidChain) -> AminoAcidChain:
return aac;
def tagLocStrings(aac:AminoAcidChain):
cur_loctags = []
for i in range(0, locStrings.len()):
locStrings
# Miscillaneous utility methods and classes for general use
# Contributing authors:
# -Lucianna Osucha (lucianna@vulpinedesings.com)
import sys
class RobustLinkedList:
class ListNode:
def __init__(self, data, n_next=None, n_prev=None):
self.data = data
self.prev = n_prev
self.next = n_next
def __str__(self):
return str(self.data)
def __init__(self, curNode=None, n_head=None, n_foot=None, size=-1):
self.curNode = curNode
self.head = n_head
self.foot = n_foot
if curNode == None:
self.size = 0
else:
self.size = size
@classmethod
def from_list(cls, m_list):
head = RobustLinkedList.ListNode(m_list[0])
cur = head
for i in range(1, len(m_list) - 1):
cur.next = RobustLinkedList.ListNode(m_list[i], None, cur)
cur = cur.next
foot = RobustLinkedList.ListNode(m_list[-1], None, cur)
cur.next = foot
return cls(head, head, foot, len(m_list))
def getData(self):
return self.curNode.data
def insert(self, data, before=False):
if self.size == 0:
self.curNode = RobustLinkedList.ListNode(data)
self.head = self.curNode
self.foot = self.curNode
else:
if before:
self.curNode.prev = RobustLinkedList.ListNode(data, self.curNode, self.curNode.prev)
if self.curNode == self.head:
self.head = self.curNode.prev
self.curNode = self.head
else:
self.curNode = self.curNode.prev
self.curNode.prev.next = self.curNode
else:
self.curNode.next = RobustLinkedList.ListNode(data, self.curNode.next, self.curNode)
if self.curNode == self.foot:
self.foot = self.curNode.next
self.curNode = self.foot
else:
self.curNode = self.curNode.next
self.curNode.next.prev = self.curNode
self.size += 1
return self
def remove(self):
if self.head == self.foot:
self.head = None
self.foot = None
self.curNode = None
self.size = 0
return self
elif self.curNode == self.head:
self.head = self.curNode.next
self.curNode = self.head
self.curNode.prev = None
elif self.curNode == self.foot:
self.foot = self.curNode.prev
self.curNode = self.foot
self.curNode.next = None
else:
self.curNode.prev.next = self.curNode.next
self.curNode.next.prev = self.curNode.prev
self.curNode = self.curNode.next
self.size -= 1
return self
def len(self, force=False):
if force and self.size == -1:
node = self.head
self.size;
while node != None:
self.size += 1
node = node.next
if (self.size > 10000): # Assume loop at 10,000 iterations
self.size = -1
break
return self.size
def to_head(self):
self.curNode = self.head
return self
def to_foot(self):
self.curNode = self.foot
return self
def next(self):
self.curNode = self.curNode.next
return self
def prev(self):
self.curNode = self.curNode.prev
return self
# Traverse n entries, positive values go footwards and negatives go headwards.
def traverse(self, n = 1):
while n > 0:
self.curNode = self.curNode.next
if (self.curNode == None):
self.curNode = self.head
n -= 1
while n < 0:
self.curNode = self.curNode.prev
if (self.curNode == None):
self.curNode = self.foot
n += 1
return self
def __str__(self):
node = self.head
result = ""
while node != None:
if node == self.curNode:
result += "-> " + str(node) + "\n"
else:
result += " " + str(node) + "\n"
node = node.next
return result
# Find index in a sorted list. If not found, returns the negated index of the
# nearest value #TODO
def stubbornBinSearch(list, object) -> int:
i = list.len() / 2
j = 0
while (list[i] != object && i != j):
return ((i == j) * -1) * i;
#def stubbornBinSearch(list, object) -> int:
# i = len(list) / 2
# j = 0
# while (list[i] != object and i != j):
# if (list[i] < object)
# return ((i == j) * -1) * i;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment