DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
60 stars 13 forks source link

cyto_stats_compute cannot recognize multiple gating set file #159

Closed kim619 closed 1 year ago

kim619 commented 1 year ago

Hi I would like to make a mann whitney U test to compare my gated data for my gating set, I tried to use the cyto_stats_compute to save statistical data, though it did not allow me to use multiple file in one coding.

> > cyto_stats_compute(gs1[1:25],
> +                    alias=c("R6 GFP+RFP Pi","R6 GFP+RFP Px"),
> +                    channels=c("PE-A"),
> +                    stat="mean",
> +                    format="long"
> +                    )
> Error in get_cytoset_from_node(obj@pointer, y) : R6 GFP+RFP Px not found!

However when I assigned the specific element to the alias, it works perfectly fine.

> > cyto_stats_compute(gs1[3],
> +                    alias=c("R6 GFP+RFP Px"),
> +                    channels=c("PE-A"),
> +                    stat="mean",
> +                    format="long"
> +                    )
> # A tibble: 1 × 4
>   name           Population    Marker    MFI
>   <fct>          <chr>         <chr>   <dbl>
> 1 05-Well-A5.fcs R6 GFP+RFP Px PE-A   73472.

PS: Is there a method I can unite all my gating set data without specifying the []?

DillonHammill commented 1 year ago

@kim619, it seems like one or more of your samples is missing the "R6 GFP+RFP Px" gate? Are these gates created with cyto_gate_draw()? Perhaps you used [ when you drew the gates? You can't use [ or [[ in cyto_gate_draw() otherwise you will only apply the gates to a subset of the samples, you should instead use the select argument (which is much more flexible anyways).

[ and [[ are simply subset operators which return a subset of the original GatingSet - i.e. gs[3] will return a GatingSet containing only the third sample. Theselectargument does the same thing internally but allows internal access to the entire GatingSet if required, as is the case incyto_gate_draw()`.

Do you think it is likely that this may have happened? Otherwise I can help track down the erroneous sample(s)...

P.S. I would recommend using median instead of mean to get a better idea of the central tendency of distributions which may have a significant proportion of events outside the detection limit (i.e. piled up on the axes limits).

kim619 commented 1 year ago

Thanks so much! I will try it, but I run into another problem, the axes limit of the cyto_gate_draw seems so different once I switch to using select () function.

For example, when I used the [] function to select the data, it gives me automatically with the nice domain to select. like the graph below. image

When I used select () function, it gave me weird domain, and I don't see the log transform function in the help session, it would be great if you can help me with this!

cyto_gate_draw(gs1,parent="root",
               alias = "GFPR6",
               select="05-Well-C1.fcs",
               channels = c("FITC-A"),
               type="interval",
               gatingTemplate="GatingTemplate3.csv",
               plot=TRUE,
               popup=FALSE,
               xlim=c(0,6e5))
Screen Shot 2022-09-05 at 01 46 44
DillonHammill commented 1 year ago

@kim619, it looks like you haven't transformed the data in the second image prior to gating. The select argument doesn't fiddle with transformations so you may have forgotten to transform the data with cyto_transform() before gating.

select also accepts indices so you can simply supply the indices as you did previously within [ but instead pass them to select.

kim619 commented 1 year ago

Thanks!! Everything works now :) Though I wonder if there is a command to do a statistical test on the population like t-test or Mann-Whitney U test? Since there is only the cyto_stats_compute() I found from the vignettes page. Or if I put it another way, if there is any method that I can extract the gated data into a CSV file?

DillonHammill commented 1 year ago

That's good to hear! Take a look at cyto_extract() to pull out population-level data into a matrix that you can write to a csv using write.csv().

Statistical tests such as these are coming to version 2.0.0 of CytoExploreR which will be released soon (so exciting!). For now you will need to do this by hand as you propose.

P.S. cyto_extract() will become cyto_data_extract() in the new version of CytoExploreR.