บทบาทของ S4 ใน Bioconductor

Bioconductor เบื้องต้นใน R

James Chapman

Curriculum Manager, DataCamp

S3

ข้อดี

  • CRAN ใช้งานง่ายแต่มีประสิทธิภาพ
  • ยืดหยุ่นและโต้ตอบได้
  • ใช้ generic function
  • ฟังก์ชันการทำงานขึ้นอยู่กับ argument แรก
  • ตัวอย่าง: plot() และ methods(plot)

ข้อเสีย

  • ตรวจสอบประเภทและการตั้งชื่อได้ไม่ดี (dot หรือไม่ dot?)
  • การสืบทอดทำงานได้ แต่ขึ้นอยู่กับ input
Bioconductor เบื้องต้นใน R

S4

ข้อดี

  • กำหนด class อย่างเป็นทางการ
  • นำกลับมาใช้ใหม่ได้ใน Bioconductor
  • ตรวจสอบประเภทข้อมูลได้
  • มีรูปแบบการตั้งชื่อที่ชัดเจน

ตัวอย่าง: myDescriptor <- new("GenomeDescription")

ข้อเสีย

  • โครงสร้างซับซ้อนกว่า S3
Bioconductor เบื้องต้นใน R

เป็น S4 หรือไม่?

ตรวจสอบว่า object เป็น S4 หรือไม่

isS4(myDescriptor)
TRUE

str ของ S4 object จะขึ้นต้นด้วย Formal class

str(myDescriptor)
Formal class 'GenomeDescription' [package "GenomeInfoDb"] with 7 slots
...
Bioconductor เบื้องต้นใน R

การกำหนด S4 class

class ใช้อธิบาย representation ที่ประกอบด้วย

  • name
  • slots (เมธอด/ฟิลด์)
  • contains (การกำหนดการสืบทอด)
MyEpicProject <- setClass(# Define class name with UpperCamelCase
                          "MyEpicProject",
                          # Define slots, helpful for validation
                          slots = c(ini = "Date", 
                                    end = "Date", 
                                    milestone = "character"),
                          # Define inheritance        
                          contains = "MyProject")
Bioconductor เบื้องต้นใน R
.S4methods(class = "GenomeDescription")
 [1] coerce          commonName      organism        provider       
 [5] providerVersion releaseDate     releaseName     seqinfo        
 [9] seqnames        show            toString        bsgenomeName   
see '?methods' for accessing help and source code
showMethods(classes = "GenomeDescription", where = search())

สรุป object

show(myDescriptor)
| organism:  ()
| provider: 
| provider version: 
| release date: 
| release name: 
| ---
| seqlengths:
Bioconductor เบื้องต้นใน R

มาฝึกกันเถอะ!

Bioconductor เบื้องต้นใน R

Preparing Video For Download...