在 Perl 中创建容器类(使用 Moose)
我正在尝试在 Perl 中创建一个名为 Gene 的容器类,它将存储由另一个类“Cis”创建的对象(例如 Gene1 将存储 Cis1a Cis1b Cis1c,Gene2 将存储 Cis2a Cis2b Cis2c)。这是我到目前为止所拥有的:
package Gene;
use Moose;
has 'bindingsites'=>(
isa=>'ArrayRef[Cis]',
is=>'rw',
default=>sub{[]},
package Cis;
use Moose;
has 'gene'=>(isa=>'Gene', is=>'rw', weak_ref =>1);
我正在查看 驼鹿食谱并尝试使用它,但我不完全确定它是我正在寻找的。使用它,我在 Gene 类中编写了类似的内容:
sub Build{
my(&self,$params)=@_;
foreach my $bindingsite(@{$self->bindingsites}){
$gene->bindingsite($self)}}
但我不确定这就是我需要做的,以及每个 Gene 类如何知道要存储哪些 Cis 对象。
预先感谢您的任何帮助
I'm trying to create a container class in Perl called Gene, which will store objects created by another class 'Cis' (so for example Gene1 will store Cis1a Cis1b Cis1c, and Gene2 will store Cis2a Cis2b Cis2c). This is what I have so far:
package Gene;
use Moose;
has 'bindingsites'=>(
isa=>'ArrayRef[Cis]',
is=>'rw',
default=>sub{[]},
package Cis;
use Moose;
has 'gene'=>(isa=>'Gene', is=>'rw', weak_ref =>1);
I was looking at one of the Moose Recipes and was trying to use that, but I'm not entirely sure it is what I am looking for. Using that I had written something like in the Gene class:
sub Build{
my(&self,$params)=@_;
foreach my $bindingsite(@{$self->bindingsites}){
$gene->bindingsite($self)}}
but I'm not sure that is what I need to do, and how each Gene class will know which Cis objects to store.
Thanks in advance for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望在将 Cis 对象添加到 Gene 类的绑定位点时自动更新基因属性,则可以在 Gene 类中使用 'after' 方法修饰符,例如。
该子程序将在调用
$gene->bindingsites(...)
后运行,并将迭代设置基因属性的 Cis 对象。If you want the gene attribute to be automatically updated when a Cis object is added to a the bindingsites of a Gene class, then you can use an 'after' method modifier in the Gene class, eg.
This sub will be run after a call to
$gene->bindingsites(...)
and will iterate over the Cis objects setting the gene attribute.