DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
61 stars 13 forks source link

Applying FCS-integrated compensation #56

Closed Mieszkol closed 4 years ago

Mieszkol commented 4 years ago

Hi Dillon,

Is there a way to apply FCS-integrated compensation matrix to the gating set? It'd be really helpful!

Best Mieszko

DillonHammill commented 4 years ago

@Mieszkol, this is already supported by cyto_compensate(). If you do not supply the name of a spillover matrix csv file to spillover, the spillover matrix attached to the first sample will be applied to all samples by default. You can control which matrix is applied through the select argument, and you can set select = NULL to apply the spillover matrix attached to each fcs file. I would be careful doing things this way as I have often run into cases where the modified spillover matrix has not been attached to certain samples (and hence are incorrectly compensated using this approach). You can check this by first running cyto_spillover_extract() which will pull out the attached spillover matrix from each file.

# Check spillover matrices - gs is a GatingSet
cyto_spillover_extract(gs)

# Apply spillover matrix attached to each file
gs <- cyto_compensate(gs, select = NULL)

# Apply the first spillover matrix to all samples (default)
gs <- cyto_compensate(gs, select = 1)

It is not currently documented but you can also supply a particular matrix object to the spillover argument and this will apply the supplied matrix to all samples. For example:

# Get list of spillover matrices
spill_list <- cyto_spillover_extract(gs)

# Pull out spillover matrix from fifth sample
spill <- spill_list[[5]]

# Apply spillover matrix to samples
gs <- cyto_compensate(gs, spillover = spill)

I will update the docs to include this last option.

Mieszkol commented 4 years ago

It works, thank you!