Presentation is loading. Please wait.

Presentation is loading. Please wait.

Initial Experience(s) Developing S4 Classes for Medical Imaging Data Brandon Whitcher, PhD GlaxoSmithKline Clinical Imaging Centre.

Similar presentations


Presentation on theme: "Initial Experience(s) Developing S4 Classes for Medical Imaging Data Brandon Whitcher, PhD GlaxoSmithKline Clinical Imaging Centre."— Presentation transcript:

1 Initial Experience(s) Developing S4 Classes for Medical Imaging Data Brandon Whitcher, PhD GlaxoSmithKline Clinical Imaging Centre

2 2 Acknowledgements S4 Classes and MethodsS4 Classes and Methods –Slides by F. Leisch and P. Murrell –Software for Data Analysis by J. Chambers –R Programming for Bioinformatics by R. Gentlemen –R packages nlmenlme kernlabkernlab EBImageEBImage

3 3 OOP and Classes in R One identifies real objects, and the operations on them, that are interesting.One identifies real objects, and the operations on them, that are interesting. –These operations can be systematically implemented. A basic principle (hope) is that by faithfully representing the objects we get easier-to-implement functions.A basic principle (hope) is that by faithfully representing the objects we get easier-to-implement functions. A class is an abstract definition of a concrete real-world object.A class is an abstract definition of a concrete real-world object. A class system is a software infrastructure that is designed to help construct classes and to provide programmatic support for dealing with classes.A class system is a software infrastructure that is designed to help construct classes and to provide programmatic support for dealing with classes.

4 4 Why (S4) Classes for Medical Imaging Data? Context of imaging dataContext of imaging data Interface with data standards and third-party softwareInterface with data standards and third-party software Numerous processing steps involvedNumerous processing steps involved –Multiple information sources Audit trail (internal and external agencies)Audit trail (internal and external agencies) Too easy to make mistakes!Too easy to make mistakes!

5 5 Data Analysis Pipeline Pre-processing Mathematical Modelling Statistical Analysis Data Results Motion correction Warping Co-registration Model building Parameter estimation Test statistics p-values Multiple comparisons

6 6 Medical Imaging Data Slice Thickness; e.g. 5mm Spatial Resolution Size = X × Y; e.g. 256×256 X Y e.g. 0.4mm Chosen parameters depend on many factors: application, scanner, local practice, radiologist preferences, etc. X Z

7 7 Composition of Structural Data convert DICOM X Y Z NIfTI 3D

8 8 Composition of Dynamic Data X Y Z t = 1 X Y Z t = T NIfTI 4D

9 9 The nifti Class Inherits from class arrayInherits from class array Contains 44 “slots” (not counting.Data )Contains 44 “slots” (not counting.Data ) –both numeric and character strings [348 bytes] Also created function nifti() for user-defined slots.Also created function nifti() for user-defined slots. Similar class has been defined for ANALYZE data.Similar class has been defined for ANALYZE data. setClass(“nifti”, representation(“sizeof_hdr”=“numeric”, “data_type”=“character”,...), prototype(“sizeof_hdr”=348, “data_type”=“”,...), contains=“array”)

10 10 Method “show” for nifti Class setMethod(“show”, “nifti”, function(object) { cat(“NIfTI-1 file format”, fill=TRUE) cat(...) }) > ffd NIfTI-1 format Type : nifti Data Type : 4 (INT16) Bits per Pixel : 16 Slice Code : 0 (Unknown) Intent Code : 0 (None) Qform Code : 1 (Scanner_Anat) Sform Code : 0 (Unknown) Dimension : 64 x 64 x 21 x 180 Pixel Dimension : 4 x 4 x 6 x 3 Voxel Units : mm Time Units : sec

11 11 Validity Checking for nifti Class setValidity(“nifti”, function(object) { retval <- NULL... if != 348) retval <- c(retval, “sizeof_hdr != 348”) if %in% c(2^(1:11),768,1280,1536,1792)) retval <- c(retval, “datatype not recognized”)... if == retval <- c(retval, “dim/img mismatch”)... if (is.null(retval)) return(TRUE) else return(retval) })

12 12 Manipulation of Slots The nifti header allows limited text informationThe nifti header allows limited text information –descrip (80 characters) and aux_file (24 characters) –Replacement functions Acessor functions > aux.file(mniLR) [1] "none " > descrip(mniLR) [1] "FSL3.2beta" Slots > [1] "none " > [1] "FSL3.2beta" setMethod(“descrip”, “nifti”, function(object) { }) setGeneric(“descrip<-”, function(x, value) { standardGeneric(“descrip<-”) }) setReplaceMethod(“descrip”, “nifti”, function(x, value) { <- value x })

13 13 Additional Methods readNIfTI() and writeNIfTI()readNIfTI() and writeNIfTI() –IO functions for NIfTI data (100% R ) –Affine transformations image()image() –Forces S3 method into proper generic method –Equivalent to a “lightbox” representation overlay()overlay() –Essentially, the image function for two input arrays orthographic()orthographic() –2×2 matrix of plots: coronal, sagittal, axial –Utilizes “pixel dimension” slot

14 14 ffd <- readNIfTI(“filtered_func_data.nii.gz”) image(ffd, zlim=range(ffd)) # Figure 1 zstat1 <- readNIfti(“zstat1.nii.gz”) overlay(ffd, ifelse(abs(zstat1) > 5, zstat1, NA), zlim.x=range(ffd)) # Figure 2

15 15 mni <- readNIfTI(“avg152T1_LT_nifti.nii.gz”) orthographic(mni, zlim=range(mni)) > mniLR NIfTI-1 format Type : nifti Data Type : 2 (UINT8) Bits per Pixel : 8 Slice Code : 0 (Unknown) Intent Code : 0 (None) Qform Code : 0 (Unknown) Sform Code : 4 (MNI_152) Dimension : 91 x 109 x 91 Pixel Dimension : 2 x 2 x 2 Voxel Units : mm Time Units : sec

16 16 Coercion and Extensions CoercionCoercion –Implicit since nifti class is built on the array class. –But... it will fail validObject(). Allow extensions via the NIfTI-1.1 mechanism.Allow extensions via the NIfTI-1.1 mechanism. –Define new class “niftiExtension” –Implement full audit trail XML document – library(“XML”)XML document – library(“XML”) > A <- array(1:8^3, rep(8,3)) > B <- as(A, “nifti”) > dim(B) [1] > [1]

17 17 Conclusions S4 classes are powerfulS4 classes are powerful –Robust framework –Generics and methods –Validity checking –Inheritance... and difficult... and difficult –Documentation (lack thereof) –Examples (lack thereof) –Slower than S3 (?)

18 18 Todo List Integrate S4 class into image analysis functions.Integrate S4 class into image analysis functions. –Modification of.Data causes modification of slot(s) Use cniftilib to be 100% NIfTI compliantUse cniftilib to be 100% NIfTI compliant –Rniftilib by Oliver Granert ()

19 19 Extra Slides

20 20 Data Formats Digital Imaging and Communications in Medicine (DICOM); 1992.Digital Imaging and Communications in Medicine (DICOM); –Binary file with a dynamic header description. ANALYZE™ 7.5 File Format; 199?.ANALYZE™ 7.5 File Format; 199?. –An image (.img) file –A header (.hdr) file [348 bytes] Neuroimaging Informatics Technology Initiative (NIfTI); 2004.Neuroimaging Informatics Technology Initiative (NIfTI); –Adapted from ANALYZE 7.5 –Dual file (.hdr &.img) –Single file (.nii) [348+ bytes]


Download ppt "Initial Experience(s) Developing S4 Classes for Medical Imaging Data Brandon Whitcher, PhD GlaxoSmithKline Clinical Imaging Centre."

Similar presentations


Ads by Google