Hi, I need to create a Bed module with these functions:
readBed(file) – read a BED format file and constructs a list of gene model objects from the data it contains.
writeBed(models=models,fname=file) – writes the given list of gene model objects and writes them to a file named fname.
For the readBed, I was thinking about readline function that I have wrote before, and add the codes for it to return a result as a list. For writeBed, I really am clueless. Here is my codes, please guide me everyone:
def ReadBed(file):
result = []
line = fh.readline()
if not line:
fh.close()
else:
return result
def writeBed(models=models, fname=file):
if file.ReadBed = result
return result in fname
Also, I had a Range class like this, and I want to raise TypeError and ValueError for my class, but not sure how to do it, can everyone please help me too. Thank you so much everyone:
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