开发者

In R, how do I set an S4 class based on another object's class

开发者 https://www.devze.com 2022-12-21 11:12 出处:网络
I need to create an object of type ShortReadQ from Bioconductor\'s ShortRead library. ShortReadQ \'signature(sread = \"DNAStringSet\", quality =

I need to create an object of type ShortReadQ from Bioconductor's ShortRead library.

ShortReadQ 'signature(sread = "DNAStringSet", quality =
          "QualityScore", id = "BStringSet")'

The quality slot needs to be an object inheriting from QualityScore, of which I can easily determine from another ShortReadQ object that I wish to emulate.

> class(quality(anotherObject))
[1] "SF开发者_运维技巧astqQuality"
attr(,"package")
[1] "ShortRead"

What is the best way to use that information ("SFastqQuality") in the contructor argument?

newObject<-ShortReadQ(sread=...,
             quality=SFastqQuality(...), 
             id=...)


Does this do what you want?

quality = new(class(old.quality.obj)[[1]]))


You might want the get function:

a <- get(class(object))
a(...)


thanks for your responses. they lead me to a solution that works

newObject<-ShortReadQ(sread=...,
             quality=new(Class=class(quality(anotherObject)),theFirstParameter=...), 
             id=...)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号