Hi, I had this class and subclass :
class Range:
def __init__(self, start, end):
self.setStart(start)
self.setEnd(end)
def getStart(self):
return self.start
def setStart(self, s):
self.start = s
def getEnd(self):
return self.end
def setEnd(self, e):
self.end = e
def getLength(self):
return len(range(self.start, self.end))
def overlaps(self, r):
if (r.getStart() < self.getEnd() and r.getEnd() >= self.getEnd()) or \
(self.getStart() < r.getEnd() and self.getEnd() >= r.getEnd()) or \
(self.getStart() >= r.getStart() and self.getEnd() <= r.getEnd()) or \
(r.getStart() >= self.getStart() and r.getEnd() <= self.getEnd()):
return True
else:
return False
class DNAFeature(Range):
def __init__(self, start, end): self.setStart(start) self.setEnd(end) self.strand = none self.sequencename = none def getSeqName(self, s): return self.SeqName def setSeqName(self, s): self.sequencename = s def getStrand(self): if self.SeqName == 'plus': return 1 elif self.SeqName == 'minus': return -1 else: return 0 def setStrand(self, s): self.strand = s
And here is what I have to do: Create a new class – GeneModel ‐ that contains a group of DNAFeature objects representing exons and is a child class of DNAFeature. It should implement the following methods: getFeats() – returns a list of DNAFeature objects, sorted by start position addFeat(feat) – accepts a DNAFeature feat and adds it to its internal group of DNAFeature objects setTranslStart(i) – accepts a non‐negative int, sets the start position of the initiating ATG codon getTranslStart() – returns an int, the start position of the initiating ATG codon setTranslStop(i) – accepts a positive int, sets the end position for the stop codon getTranslStop() – returns an int, the end position for the stop codon setDisplayId(s) – sets the name of the gene model; s is a string getDisplayId() – return the name of the gene model, returns a string, e.g., AT1G10555.1 GeneModel should raise appropriate ValueError and TypeError exceptions when users pass incorrect types and values to constructors and “set” methods.
I have tried to write whatever comes to my mind, and read the books as well as searching the way to put codes together, but I am so new to programming and hardly can understand how to write the codes correctly. To be honest, this is the first time I ever do a programming class. So if I make any funny mistake in my codes, please forgive me. I haven't finish my codes yet and still reading the books to see where I am doing wrong and right with my codes. However, I really need your help to guide me to the right path. Thank you guys very much. Below is my codes:
class GeneModel(DNAFeature):
def __init__(self, translstart, translend, displayid): self.setTranslStart(translstart) self.setTranslStop(translend) setDisplayId(displayid) def getFeats(): result = [] sort.self.getStart() return result def addFeat(feat): self.addFeat = feat return self.getStart+self.getEnd def setTranslStart(i): self.translstart = self.setStart self.translstart = non-negative int def getTranslStart(): return self.translstart def setTranslStop(i): self.translend = self.setEnd self.translend = "+" int def getTranslStop(): return self.translend def setDisplayId(s): self.displayid = re.compile('r'\AT1G[0-9]{5,5}\.[0-9]{,1}, IGNORECASE') def getDisplayId(): return self.displayid