子类/子类
我有这个类和子类:
类别范围:
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
DNAFeature 类(范围):
def __init__(self, 开始, 结束): self.setStart(开始) self.setEnd(结束) self.strand = 无 self.sequencename = 无 def getSeqName(self, s): 返回 self.SeqName def setSeqName(self, s): self.sequencename = s def getStrand(self): 如果 self.SeqName == '加': 返回1 elif self.SeqName == '减号': 返回-1 别的: 返回0 def setStrand(self, s): self.strand = s
这是我必须做的: 创建一个新类 – GeneModel – 包含一组代表外显子的 DNAFeature 对象,并且是 DNAFeature 的子类。 它应该实现以下方法: getFeats() – 返回 DNAFeature 对象的列表,按起始位置排序 addFeat(feat) – 接受 DNAFeature 专长并将其添加到 DNAFeature 对象的内部组中 setTranslStart(i) – 接受非负整数,设置起始 ATG 密码子的起始位置 getTranslStart() – 返回一个 int,即起始 ATG 密码子的起始位置 setTranslStop(i) – 接受正整数,设置终止密码子的结束位置 getTranslStop() – 返回一个 int,即终止密码子的结束位置 setDisplayId(s) – 设置基因模型的名称; s 是一个字符串 getDisplayId() – 返回基因模型的名称,返回一个字符串,例如,AT1G10555.1 当用户将不正确的类型和值传递给构造函数和“set”方法时,GeneModel 应引发适当的 ValueError 和 TypeError 异常。
我尝试过想到什么就写什么,也读过书,也搜索过如何组合代码,但我对编程很陌生,几乎不明白如何正确编写代码。说实话,这是我第一次上编程课。因此,如果我在代码中犯了任何有趣的错误,请原谅我。我还没有完成我的代码,仍在阅读书籍,看看我的代码在哪里做错了,哪里做对了。然而,我真的需要你的帮助来引导我走上正确的道路。非常感谢你们。下面是我的代码:
类基因模型(DNAFeature):
def __init__(self, translstart, translend, displayid): self.setTranslStart(translstart) self.setTranslStop(translend) 设置显示ID(显示ID) def getFeats(): 结果=[] sort.self.getStart() 返回结果 def addFeat(壮举): self.addFeat = 壮举 返回 self.getStart+self.getEnd def setTranslStart(i): self.translstart = self.setStart self.translstart = 非负整数 def getTranslStart(): 返回 self.translstart def setTranslStop(i): self.translend = self.setEnd self.translend =“+”int def getTranslStop(): 返回自传 def setDisplayId(s): self.displayid = re.compile('r'\AT1G[0-9]{5,5}\.[0-9]{,1}, IGNORECASE') def getDisplayId(): 返回 self.displayid
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白基因模型的名字是什么。我认为这是特定于主题的,但我认为这对您有用:
希望这会有所帮助。
I don't understand what the name of the gene model is. I think it's subject specific, but I think this will work for you:
Hope this helps.
首先,进行一些清理。我并不完全相信您原来的课程 DNAFeature 实际上是正确的。 DNAFeature 似乎继承自其他一些名为 Range 的类,我们在这里缺少该类,因此如果您有该代码,也请提供它。在那个原始类中,您需要定义变量 SeqName (另外,最好将变量保持小写),否则 self.SeqName 将毫无意义。此外,除非它们是从 Range 类继承的,否则您还应该定义方法“setStart”和“setEnd”。你的吸气剂不应该有任何额外的变量,所以随意将其更改为“def getSeqName(self)”而不是添加“s”。我不确定您的代码还应该做什么,所以我将保留任何进一步的评论。
此外,尽管您在评论中另有说明,但我必须从命名约定(以及我从生物中记得的一点点)中相信您实际上希望 GeneModel 成为一组 DNAFeature 实例的容器。这与子类化 DNAFeature 的 GeneModel 不同。如果我是对的,那么您可以尝试:
这里 dnafeatures 只是 dnafeature 实例的列表。然后,您可以编写方法来访问这些功能并做任何您需要做的有趣的事情。
我的建议是确保您的 DNAFeature 类是正确的,并且您希望如何解决问题的模型(就您的类的作用而言),并在更清晰时再次尝试询问。希望这有帮助!
First, a little bit of cleanup. I'm not completely convinced that your original class, DNAFeature, is actually correct. DNAFeature seems to be inheriting from some other class, named Range, that we're missing here so if you have that code please offer it as well. In that original class, you need to define the variable SeqName (also, its preferable to keep variables lower-cased) since otherwise self.SeqName will be meaningless. Additionally, unless they're inherited from the Range class, you should also define the methods "setStart" and "setEnd". You're getter should not any additional variables, so feel free to change it to "def getSeqName(self)" instead of adding "s". I'm not sure what else your code is really supposed to do, so I'll hold any further comment.
Additionally, though you stated otherwise in your comment, I have to believe from the naming conventions (and what little I remember from bio) that you actually want GeneModel to be a container for a set of DNAFeature instances. That's different from GeneModel subclassing DNAFeature. If I'm right, then you can try:
Here dnafeatures would just be a list of dnafeature instances. This would then allow you to write methods to access these features and do whatever fun stuff you need to do.
My advice would be to make sure your DNAFeature class is correct and that your model of how you want your problem solved (in terms of what your classes do) and try asking again when its a little clearer. Hope this helps!