Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble with IMC spillover R script` #1

Closed
asasama12 opened this issue Oct 14, 2020 · 13 comments
Closed

Trouble with IMC spillover R script` #1

asasama12 opened this issue Oct 14, 2020 · 13 comments

Comments

@asasama12
Copy link

I've collected IMC images of dotted metal conjugated antibodies and am attempting to use the imc_generatespillmat_long.Rmd script to calculate spillover between channels but am having trouble getting it to run. I am able to load all the packages and data and run the script up to line 125, but when calculating the CATALYST based compensation I get the following error.

Error in CATALYST::assignPrelim(x = ff, y = ss_ms) : unused argument (y = ss_ms) 4. re_from_dat(x, ss_ms = x[!is.na(mass), unique(mass)], minevents = 40, correct_bc = T) 3. FUN(X[[i]], ...) 2. lapply(dats_agg, function(x) re_from_dat(x, ss_ms = x[!is.na(mass), unique(mass)], minevents = 40, correct_bc = T)) 1. lapply(dats_agg, function(x) re_from_dat(x, ss_ms = x[!is.na(mass), unique(mass)], minevents = 40, correct_bc = T))

@votti
Copy link
Collaborator

votti commented Oct 15, 2020

Hi!

The issue underlying this is that CATALYST changed quite a bit since this repository was created. This broke a lot of functionality and is causing the error you are seeing.

I now added a branch with instructions how to install an R environment with an old CATALYST version:
https://github.com/BodenmillerGroup/cyTOFcompensation/tree/environment

Pull request: #2

Installing the Conda environment should allow you to use this scripts - could you give this a try?

Best, Vito

@asasama12
Copy link
Author

Ah! That helped progress past line 125, but I am now getting a different error at line 148:
`Error in check_sm(SM, isotope_list) : The supplied spillover matrix seems to be invalid. All isotopes should appear in isotope_list.

  1. stop("\nThe supplied spillover matrix seems to be invalid.\n", "All isotopes should appear in ", deparse(substitute(l)), ".")
  2. check_sm(SM, isotope_list)
  3. .local(bc_ms, SM, ...)
  4. CATALYST::plotSpillmat(ss_ms, sms[[i]])
  5. CATALYST::plotSpillmat(ss_ms, sms[[i]])`

@votti
Copy link
Collaborator

votti commented Oct 19, 2020

Hi!
I think the problem is that you likely have a non isotope channel (e.g. BCKG153Di or ArAr80Di).

Unfortunately these need to be manually added to the CATALYST isotope list as they are otherwise not supported :/
This is discussed here:
HelenaLC/CATALYST#35

I guess this could be also fixed via running this at the Beginning of the script

CATALYST::isotope_list <-  c(CATALYST::isotope_list, list(BCKG=153, ArAr=80))

(Not entirely sure, let me know if that worked).

@asasama12
Copy link
Author

That does not seem to be the issue, I am using standard isotopes and I went through and checked in isotope_list and they are all present there:
image

I do get an output spreadsheet with what I assume is the spillover matrix

@votti
Copy link
Collaborator

votti commented Oct 19, 2020

Yes, the .csv files are the spillover matrix.
plotSpillmat is indeed just a nicer visualization.

The question is usually rather what channels were selected during acquisitions and are in the files.
This would be the output of:
colnames(sms[[i]])
and
rownames(sms[[i]])

Could well be that instead of Eu153 you acquired BCKG=153 or something like this :/

@asasama12
Copy link
Author

Thank you for all your help in this, I really appreciate it.
I checked colnames(sms[[i]]) and rownames(sms[[i]]) and they cambe back
colnames:
[1] "Y89Di" "Ru100Di" "Ru101Di" "Ru102Di" "Ru104Di" "In113Di" "In115Di" "I127Di" "Xe131Di" "Ba138Di" "La139Di" "Pr141Di" "Nd142Di" "Nd143Di"
[15] "Nd144Di" "Nd145Di" "Nd146Di" "Sm147Di" "Nd148Di" "Sm149Di" "Nd150Di" "Eu151Di" "Sm152Di" "Eu153Di" "Sm154Di" "Gd155Di" "Gd156Di" "Gd158Di"
[29] "Tb159Di" "Gd160Di" "Dy161Di" "Dy162Di" "Dy163Di" "Dy164Di" "Ho165Di" "Er166Di" "Er167Di" "Er168Di" "Tm169Di" "Er170Di" "Yb171Di" "Yb172Di"
[43] "Yb173Di" "Yb174Di" "Lu175Di" "Yb176Di" "BCKG190Di" "Ir191Di" "Ir193Di" "Pb208Di" "Bi209Di"
rownames:
[1] "Er170Di" "Eu151Di" "Eu153Di" "Gd158Di" "La139Di" "Lu175Di" "Nd142Di" "Nd144Di" "Nd148Di" "Nd150Di" "Pr141Di" "Sm147Di" "Sm152Di" "Sm154Di" "Yb171Di" "Yb176Di"

I crossreferenced these with CATALYST::isotope_list and the only one that was missing was BCKG190Di so I added that to isotope_list as you suggested:

`isotope_list <- c(CATALYST::isotope_list, list(BCKG=190))

for (i in seq_along(sms)){
print(names(dats_agg)[i])
ss_ms = dats_agg[[i]][!is.na(mass), unique(mass)]
p = CATALYST::plotSpillmat(ss_ms,sms[[i]])
print(p)
}`

However, I still get the same error message as above - supplied spillover matrix seems to be invalid. all isotopes should appear in isotope_list

@asasama12
Copy link
Author

Solved this with the line p = CATALYST::plotSpillmat(ss_ms,sms[[i]], isotope_list = isotope_list)

I'm now attempting to apply this spillover matrix to my images using the imc_comp_txt_example script, and I'm having the same issue at
img_comp = comp_datimg(img, sm=sm)

Error in check_sm(input_sm, isotope_list) : The supplied spillover matrix seems to be invalid. All isotopes should appear in isotope_list.
19.
stop("\nThe supplied spillover matrix seems to be invalid.\n", "All isotopes should appear in ", deparse(substitute(l)), ".")
18.
check_sm(input_sm, isotope_list)
17.
.local(input_sm, out_chs, ...)
16.
adaptSpillmat(y, flowCore::colnames(x), isotope_list)
15.
adaptSpillmat(y, flowCore::colnames(x), isotope_list)
14.
.local(x, y, ...)
13.
compCytof(x, as.matrix(y), out_path, method)
12.
compCytof(x, as.matrix(y), out_path, method)
11.
.local(x, y, ...)
10.
CATALYST::compCytof(., sm, method = method, ...)
9.
CATALYST::compCytof(., sm, method = method, ...)
8.
function_list[i]
7.
freduce(value, _function_list)
6.
_fseq(_lhs)
5.
eval(quote(_fseq(_lhs)), env, env)
4.
eval(quote(_fseq(_lhs)), env, env)
3.
withVisible(eval(quote(_fseq(_lhs)), env, env))
2.
img_mat %>% flowCore::flowFrame() %>% CATALYST::compCytof(sm, method = method, ...) %>% flowCore::exprs() %>% as.data.table() at spillover_imc_helpers.R#220
1.
comp_datimg(img, sm = sm)

@asasama12
Copy link
Author

Trying to track down this issue,
I updated the isotope_list to include BCKG190 as you suggested which allowed me to run plotSpillmat in the other script,

when I run compCytof(img_comp, sm, isotope_list2) I get the error Error in check_sm(input_sm, isotope_list) : The supplied spillover matrix seems to be invalid. All isotopes should appear in 'isotope_list'

If I run compCytof(img_comp, sm, isotope_list = isotope_list2) I get the error Error in .local(x, y, ... ): unused argument (isotope_list = isotope_list2)

I confirmed that all the metal_names from my colnames(img_mat) are included in isotope_list2 including BCKG190

@votti
Copy link
Collaborator

votti commented Oct 23, 2020

Hi,
So the solution to this is to use img_comp = comp_datimg(img, sm=as.matrix(sm), isotope_list=isotope_list)

Somehow the 'isotope_list` argument is only accepted in the compCytof function if sm is a matrix (as opposed to e.g. a data.frame).

I updated the example code in the environment branch to allways coerce the sm to matrix in the comp_datimg function.

@asasama12
Copy link
Author

That worked for me! Thank you!

@saisomesh2594
Copy link

saisomesh2594 commented Jan 25, 2021

Hey,

I, too, ran into the same issue due to differences in CATALYST version: Error in CATALYST::assignPrelim(x = ff, y = ss_ms) : unused argument (y = ss_ms)

I tried to install the conda environment from the environment branch of this repo and I am running into issues with installation.

Collecting package metadata (repodata.json): done
Solving environment: failed

ResolvePackageNotFound:
  - bioconductor-ebimage
  - bioconductor-flowcore
  - libgfortran
  

Any idea what could be causing this?

Thanks,
Somesh

@laufre
Copy link

laufre commented Jan 26, 2021

Hi,

I'm also experiencing the same problem Error in CATALYST::assignPrelim(x = ff, y = ss_ms) : unused argument (y = ss_ms).
While installing the environment I have the same issue as @saisomesh2594:

`ResolvePackageNotFound:

  • bioconductor-ebimage
  • bioconductor-flowcore
  • libgfortran`

I would really appreciate your help on this, as I would love to try out your IMC spillover script!

@nilseling
Copy link
Contributor

Hi @laufre and @saisomesh2594
not sure if that is still an issue but here are scripts that use the newest version of CATALYST to generate the spillover matrix:

https://bodenmillergroup.github.io/IMCDataAnalysis/spillover-correction.html

@HelenaLC and @votti are you fine with me porting the scripts to the new repo where they are continuously checked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants