Problem with assigning experimental runs

155 views
Skip to first unread message

Shad Arf

unread,
Sep 8, 2021, 11:24:23 AM9/8/21
to Cardinal MSI Help
Dear Cardinal Developers and users, 
I am using Cardinal to perform supervised SSC classification, the method works fine for me. However, the image outputs are not separated based on the different experimental runs. Although, I defined the runs with sample names. 
below is what I would like to achieve: 

ExperimentalRun.PNG

in the above image, one m/z value is provided, but two image outputs are generated based on the simulated image. 

What I get after the classification is :

OUtput.png



below is the code I wrote to read in the MSI dataset and then define the runs. 


# __________________ Code Blocks__________________________


# Set working directory to the current one:

invisible(setwd())

# (1)  Load Required Libraries Here:

RequirLibs <- c("viridisLite","stringr","dplyr","caret",

                "Cardinal", "plyr");invisible(lapply(RequirLibs,require, character.only = T))

# ___________________________________________________________________________

# (2) Load file:

selectFile <- file.choose() %>% basename() %>%  tools::file_path_sans_ext()

 # ___________________________________________________________________________

 # (3) Convert to MSI using Cardinal::readImzML

# Convert to MSImagingExperiment _ Function _

ReadMSI           <-function(FromFile){

  DataSet         <- Cardinal::readImzML(FromFile, attach.only = F

                                         ) # False for Dense Matrix and working with RAM, True for sparse matrix.

  # toMSImagingExp  <- as(DataSet, "MSImagingExperiment")

  # toMSImagingExp

}

# Convert Data

RawData <-     selectFile %>% ReadMSI()   %>% invisible          # gets RawData, and converts it to MSImaging experiment

# ______________________________________________________________________________

# () Pre-Process FTICR_MSI data:

 # Peak Alignment => Normalisation => Filteration

myDat_ref <- function(RawData){

  Cardinal::peakAlign(RawData,

                      tolerance = 0.5, units= "mz",

  ) %>%

    Cardinal::normalize(method="rms") %>%   # "tic"

    # use mean peak as a reference for alignment, a tolerance and mz as units

    Cardinal::peakFilter(freq.min = 0.01, rm.zero = T) %>%

    Cardinal::process()

}

pkAlndData <- myDat_ref(RawData = RawData) %>% invisible()

# ______________________________________________________________________________

# pkAlndData_Vectorise <- saveRDS(object = pkAlndData, file = "PreProcessed.RData", compress = TRUE)

# ______________________________________________________________________________

# Make Selections

# Run 1

# mt_1 the upper right corner with a cone shaped tumour region

mt_1  <- Cardinal::selectROI(pkAlndData, mz = 300, key = NA,

                             contrast.enhance="histogram", normalize.image="linear")

# the upper left corner Normal

nmt_1  <- Cardinal::selectROI(pkAlndData, mz = 300, key = NA,

                             contrast.enhance="histogram", normalize.image="linear")

# Run 2 : lower right corner Tumour

mt_2  <- Cardinal::selectROI(pkAlndData, mz = 300,key = NA,

                             contrast.enhance="histogram", normalize.image="linear")

# lower left corner (Normal)

nmt_2  <- Cardinal::selectROI(pkAlndData, mz = 300,key = NA,

                             contrast.enhance="histogram", normalize.image="linear")

# Join Regions, using makeFactor() function:

T_regnz <- Cardinal::makeFactor(Sample1 = mt_1,

                                Sample2 = nmt_1,

                                Sample3 = mt_2,

                                Sample4 = nmt_2)

# define runs below

run(pkAlndData) = T_regnz

# Add Diagnosis classes below:  

mt1_slct <- pkAlndData[mt_1]; pData(mt1_slct)$Diagnosis = "mt"

nmt1_slct <- pkAlndData[nmt_1]; pData(nmt1_slct)$Diagnosis = "nmt"

mt2_slct <- pkAlndData[mt_2]; pData(mt2_slct)$Diagnosis = "mt"

nmt2_slct <- pkAlndData[nmt_2]; pData(nmt2_slct)$Diagnosis = "nmt"

 # Join regions using cbind() Function.

T_regns_bound <- cbind(mt1_slct, mt1_1_slct,

                       nmt1_slct, nmt1_1_slct,

                       mt2_slct, mt2_1_slct,

                       nmt2_slct, nmt2_1_slct)

 # Subset the images based on pixels to include only those pixels that are diagnosed as mt and nmt

Subsetted  <- T_regns_bound %>% Cardinal::subsetPixels(!is.na(Diagnosis))

 

 

# Proceed to SSC_Cross_Validation


# ______________________ END ___________________________________


I would greatly appreciate your kind clarifications and answers about how to get around this issue, 
Thanks in advance, 
Shad. 



 








 

Gordon Luu

unread,
Sep 8, 2021, 5:09:21 PM9/8/21
to Cardinal MSI Help
Hi Shad,

I've been having a similar issue with my data (timsTOF flex, converted using SCiLS Lab 2020). I was wondering, what instrument are you using and what program are you using to convert the data to imzML?

- Gordon

Shad Arf

unread,
Sep 9, 2021, 3:43:33 AM9/9/21
to Cardinal MSI Help
Hi Gordon, 

I also used  SCiLS Lab 2020 to convert mis files to .imzML format, and it is FTICR data. Did you manage to fix the problem, though ? if yes, could you kindly let me know how ? 

Thanks in advance,
Shad 

Gordon Luu

unread,
Sep 9, 2021, 7:28:42 PM9/9/21
to Cardinal MSI Help
Hi Shad,

I do not have a fix yet, though I think it may be related to SCiLS's imzML export algorithm. I'm currently thinking of a way to fix/sidestep this issue.

Melanie Föll

unread,
Oct 4, 2021, 8:59:44 AM10/4/21
to Cardinal MSI Help
Hi Shad,

sorry for the late reply.

To define runs and then obtain separate ion images for each run, you need to annotate run(pkAlndData) with a character or factor (vector) of the length of the number of spectra/pixel. Metadata added as new column to pData is not considered a new run and therefore it will not split the ion image.

I assume run(pkAlndData) <- c(mt1_slct, mt1_1_slct,  nmt1_slct, nmt1_1_slct,  mt2_slct, mt2_1_slct,  nmt2_slct, nmt2_1_slct) should do the job for you.

Best,
Melanie

Shad Arf

unread,
Oct 7, 2021, 4:44:46 AM10/7/21
to Cardinal MSI Help
Hi Melanie, 
Thank you very much for your kind reply, 
The solution you provided works fine for assigning the runs, but the images are stacked together in one sheet, they are not separated. 
Also, if I try combining images from separate experimental runs via cbind() or combine() function the runs are assigned, but the images are stacked, I tried finding a way to offset the images but I couldn't find an offset function in Cardinal. 

Thanks again for your answer, 
Best regards, 
Shad 

Melanie Föll

unread,
Oct 11, 2021, 4:18:46 PM10/11/21
to Cardinal MSI Help
Hi Shad,

for trouble shooting can you please provide the output of unique(run(pkAlndData)) and the code you used to generate the image and the image itself?

Thanks,
Melanie

Gordon Luu

unread,
Oct 11, 2021, 4:35:57 PM10/11/21
to Cardinal MSI Help
Hi all,

Regarding the blank/white pixels problem after SSC segmentation, I've confirmed on my timsTOF flex dataset that the issue is caused by data conversion using SCiLS. Shad, I believe you will need another program to convert raw data to imzML for it run properly.

- Gordon
Reply all
Reply to author
Forward
0 new messages