DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
60 stars 13 forks source link

Can't apply built-in spill matrix #196

Closed rwbaer closed 4 months ago

rwbaer commented 4 months ago

Briefly describe what you hope to achieve: I am trying to extract the spill matrix created by the cell sorter from the first data file and apply it to the whole gating set rather than creating a new one from scratch. I thought this would be staight forward with cyto_spillover_extract, but I don't know why it returns NULL rather than a list. The proper keyword on my system is $SPILLOVER.

I feel like I'm really missing something here :-( I'm also not undrstanding why the error message is referring to transformer objects. I was planning to transform after spill correction.

Outline the steps taken to attempt to reach this goal (paste code below):

Show us our channels and markers

cyto_channels(gsSamp)

[1] "TIME_MSW" "TIME_LSW" "FSC-HEIGHT" "FSC-AREA" "FSC-WIDTH" "SSC-HEIGHT" "SSC-AREA"

[8] "SSC-WIDTH" "FL1-AREA" "FL2-AREA" "FL4-AREA"

cyto_markers(gsSamp)

TIME_LSW FSC-HEIGHT FSC-AREA SSC-AREA FL1-AREA FL2-AREA

"TIME" "FSC-HEIGHT" "FSC-AREA" "SSC-AREA" "CD-271-AREA" "CD44-AREA"

FL4-AREA

"SytoxAAD-AREA"

cyto_fluor_channels(gsSamp)

[1] "FL1-AREA" "FL2-AREA" "FL4-AREA"

get spill matrix saved by cell sorter but returns NULL

spillmat = cyto_spillover_extract(gsSamp[[1]]) # use cell sorter spillover matrix from 1st sample spillmat # evaluates to NULL

try brute force

ff = cyto_extract(gsSamp[[1]]) sm = keyword(ff)$$SPILLOVER # spill matrix sm

FL1-AREA FL2-AREA FL3-AREA FL4-AREA

[1,] 1.000000 0.111111 0 0.074074

[2,] 0.000815 1.000000 0 0.053790

[3,] 0.000000 0.000000 1 0.000000

[4,] 0.002513 0.000000 0 1.000000

Apply compensation

gsSamp <- cyto_spillover_compute(gsSamp, parent = root, spillover = spillmat)

Error: 'trans' must be a list of transformer objects (generated by scales::trans_new method)

Apply compensation

gsSamp <- cyto_spillover_compute(gsSamp, parent = root, spillover = sm)

Error: 'trans' must be a list of transformer objects (generated by scales::trans_new method)



**Include any associated screenshots or images here:**
rwbaer commented 4 months ago

Follow-up I went to bioconductor and upgraded flowworkspace, etc. and this has improved the errors and cytExploreR is working more as I might have expected.

I now see cyto_spillover_compute() is not the function I need as it does what exactly its name says. I'm more looking for a function like cyto_spillover_apply(), I guess. Clearly, I don't understand what's going on under the hood with gatingset objects. I don't know what has been applied or what is applied on the fly during calculations, I guess.

My understanding is that logicle or arcsinh like transforms are "hard applied" in CytoExploreR and that is why we are stuck with one try only. Then graphs are adjusted to match the transforms at the plotting stage. If you save a gating set that has been transformed it is saved as 'transformed numbers" not "original numbers", but there is no indication of same (at least yet?).

It seem like gsSamp <- cyto_compensate(gsSamp, spillover = sm[-3,-3]) might do it since I don't use FL3-AREA but it is not quite there yet. I guess the spillover argument requires a .csv of a format I've not approximated.

When and how is spill correction applied? IF I do cyto_spillover_edit() it does not recognize the matricies in $SPILLOVER and give the error message: "Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent"

Thanks for helping me out of my confusion. In the past, I've not tried to make any use of the built in $SPILLOVER keyword and have worked straight from spill samples.

rwbaer commented 4 months ago

I'm closing this because I think my built in spill matrix is corrupt and that is what is causing me problems. The diagonal is 0 and not 1 for the FL4-AREA channel. Sorry for the noise.