removing matrix regions from dataset

Skip to first unread message

Jun 19, 2023, 8:55:54 AM6/19/23
to Cardinal MSI Help

I have performed spatialKmean on the processed MSI dataset and the results shows the clustering can distinguish matrix region from tissue region. Therefore I used the pixel data of spatialKmean output file (you can find the SpatialKmean map in attachement), that I saved as R object to subset the original dataset, considering the only tissue specific clusters.

 I checked the subset dataset by generating a picture with image() and I have got the following maps. the matrix regions are disappeared but the map is very strange. 

Here the script:
#loading the kmean file
image(readRDS("F:/Imaging data/Laura project/Kmean/230221_PC_ID 1427_21_MSI.R"))

#subsetting the dataset based on cluster specific picxels
readRDS("F:/Imaging data/Laura project/Kmean/230221_PC_ID 1427_21_MSI.R")
image(readRDS("F:/Imaging data/Laura project/Kmean/230221_PC_ID 1427_21_MSI.R"))
## here i take the pixeldata from the clustering kmean output
clusters <- readRDS("F:/Imaging data/Laura project/Kmean/230221_PC_ID 1427_21_MSI.R")@resultData@listData[[1]][["cluster"]]
##  i labelled the pixels of the imaging dataset
ID1427 <- readMSIData("F:/Imaging data/Laura project/analysis Cardinal/230221_PC_ID 1427_21_MSI.imzML")
pData(ID1427)$clusters <- clusters
## subsetting the dataset baseo on pixels of the cluster 2
a <- ID1427@elementMetadata@listData[["clusters"]]== c("1","2","4","5")
tissue <- subset(ID1427)[,a]
image(tissue, mz=191.01)

Did Anybody have already this issue? How did you solve? what does mean having this strange single ion map?

Thank you in advance and best regards

Jun 19, 2023, 12:09:44 PM6/19/23
to Cardinal MSI Help
problem solved

I need the subset singularly with each cluster and then combine the datasets

## subsetting the dataset baseo on pixels of the multiple clusters
k1 <- ID1427@elementMetadata@listData[["clusters"]]== "1"
k2 <- ID1427@elementMetadata@listData[["clusters"]]== "2"
k4 <- ID1427@elementMetadata@listData[["clusters"]]== "4"
k5 <- ID1427@elementMetadata@listData[["clusters"]]== "5"

tissuek1 <- subset(ID1427)[,k1]
tissuek2 <- subset(ID1427)[,k2]
tissuek4 <- subset(ID1427)[,k4]
tissuek5 <- subset(ID1427)[,k5]

centroided(tissuek5) <- FALSE

tissue <- Cardinal::combine(tissuek1, tissuek2, tissuek4, tissuek5)

Marco Fidaleo

Mar 3, 2024, 10:34:39 AMMar 3
to Cardinal MSI Help
I want to select an area of interest of my MSI sample (basically with the aim to remove the area where I don't have sample). I understood the function selectROI but then, how can I create ad new object considering my sample and the ROI selected?
I tried:
> ROI <- selectROI(mse, mz=500)
select pixels; press ESC or 2nd mouse button to stop
new_obj <- mse[ROI]

but I obtained the following error:

Error in validObject(.Object) :
  invalid class “atoms” object: lengths of 'source' [0], 'type' [0], 'offset' [0], 'extent' [0], and 'group' [1] must all be equal


Marco Fidaleo

Mar 3, 2024, 11:59:36 AMMar 3
to Cardinal MSI Help
I solved it! 
this is the right code:

ROI1 <- selectROI(object, mode="region")

new_object <-object[ROI1]


Marco Fidaleo

Mar 10, 2024, 7:49:30 PMMar 10
to Cardinal MSI Help
I'm still encountering an issue with selecting a portion of the image using SelectROI. I've noticed that when I make a selection of my image in this way:

mseROI <- selectROI(mse, mz=500, plusminus=5, mode = "region")

and then try to crop the image:

mse_crop <- mse[mseROI]

and visualize it:

image(mse_crop, mz=500, plusminus=5)

What I end up with is not the selection I made, but something different. How can I improve this? Please see the attached images. I've experimented with various samples, including both large and small datasets, using both R and RStudio, both on PC and Mac. How can I remove the non-sample space from an MSI image? I've downloaded several datasets where the space not occupied by the sample is white.

Thank you for your help folk!

Screenshot 2024-03-11 003750.png
Screenshot 2024-03-11 003644.png


Mar 11, 2024, 2:28:40 PMMar 11
to Cardinal MSI Help
Thanks for bringing this one to my attention with an example. It took a little investigating, but a fix will be available in a few days.

Last release, the library I relied on for determining if a pixel is contained within the vertices of the selected polygon was deprecated, so I had to re-implement it in-house.

Unfortunately, my unit test cases were symmetric and failed to catch that the x/y coordinates were flipped when passed to the inner C function.

It may take a couple days to build and become available from the Bioconductor servers.


Reply all
Reply to author
0 new messages