Skip to content

Commit

Permalink
Modifications to allow spectrofloparser to work despite rearranging h…
Browse files Browse the repository at this point in the history
…tml across versions. Hopefully also across Cytek instruments rather than just 5L.
  • Loading branch information
DavidRach committed Dec 17, 2024
1 parent b0aa344 commit 189961b
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 0 deletions.
5 changes: 5 additions & 0 deletions SpectroFloParser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Contained within this folder is the SpectroFloParser.qmd file. A rendered html version can be found on Quarto-Pub at the [following link](https://stepupcytometry.quarto.pub/spectrofloparser/). You will need to provide your own SpectroFlo.EXPT file from your local instrument.

Run the code-blocks to locally create the functions that you will need to retrieve the signatures contained within the SpectroFlo .EXPT file. Then process your experiment file to retrieve the data.

I have added a ggplot2/plotly example as an example for visualization. Note that the "fluorophore signature" generated by the gate placements for this particular experiment vary quite wildly from what they should be. Gentle reminder proper unmixing controls and gate setting are needed for good results :D
159 changes: 159 additions & 0 deletions SpectroFloParser/SpectroFloParser.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
---
title: "Single-color control signature parsing via SpectroFlo .Expt file"
date: "12/17/2024"
layout: full
format:
html: default
toc: true
toc-location: right
embed-resources: TRUE
---

# Load Required Libraries

```{r}
#| message: false
#| warning: false
library(dplyr)
library(purrr)
library(xml2)
```

# Locate Experiment

Manually

```{r}
#| eval: false
experiment <- file.choose()
```

or by file.path
```{r}
experiment <- file.path("UnmixedExperiment.Expt")
```

# Create Functions

Create the required functions locally by running the following code
```{r}
SpectroFloSignatureParser <- function(x, ColumnNames="detector"){
Parsed <- read_xml(x)
Landing <- xml_children(Parsed)
Info <- Landing[xml_name(Landing) == "Info"][[1]]
Info_child <- xml_children(Info)
ExperimentDesc <- Info_child[xml_name(Info_child) == "ExperimentDesc"][[1]]
Experiment_child <- xml_children(ExperimentDesc)
RefSetUp <- Experiment_child[xml_name(Experiment_child) == "_RefSetupResult"][[1]]
RefSetUp_child <- xml_children(RefSetUp)
SpillOverColumn <- RefSetUp_child[xml_name(RefSetUp_child) == "SpilloverColumnList"][[1]]
Spill_child <- xml_children(SpillOverColumn) # Number Children
Data <- map(.x=Spill_child, .f=NormalizedParser) %>% bind_rows()
if (ColumnNames=="detector"){
Data <- ColumnNaming(x=Data)
}
return(Data)
}
NormalizedParser <- function(x){
Parameters <- xml_children(x)
RefControl <- Parameters[xml_name(Parameters) == "_RefControlDesc"]
RefControl_child <- xml_children(RefControl)
FluorophoreFloat <- RefControl_child[xml_name(RefControl_child) == "Fluorochrome"]
Fluorophore <- xml_text(FluorophoreFloat)
Fluorophore <- data.frame(Fluorophore)
Param_child <- Parameters[xml_name(Parameters) == "_SpilloverVectorArea"]
FloatingValues <- xml_find_all(Param_child, ".//d7p1:float", ns = xml_ns(Param_child))
ValueVector <- as.numeric(xml2::xml_text(FloatingValues))
Data <- data.frame(t(ValueVector))
Data <- cbind(Fluorophore, Data)
return(Data)
}
ColumnNaming <- function(x){
TotalDetectors <- ncol(x)-1
The5L <- c("Fluorophore", "UV1", "UV2", "UV3", "UV4", "UV5", "UV6", "UV7", "UV8",
"UV9", "UV10", "UV11", "UV12", "UV13", "UV14", "UV15", "UV16",
"V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8",
"V9", "V10", "V11","V12", "V13", "V14", "V15", "V16",
"B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8",
"B9", "B10", "B11", "B12", "B13", "B14",
"YG1", "YG2", "YG3", "YG4", "YG5", "YG6", "YG7", "YG8", "YG9", "YG10",
"R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8")
The4LUV <- c("Fluorophore", "UV1", "UV2", "UV3", "UV4", "UV5", "UV6", "UV7", "UV8",
"UV9", "UV10", "UV11", "UV12", "UV13", "UV14", "UV15", "UV16",
"V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8",
"V9", "V10", "V11","V12", "V13", "V14", "V15", "V16",
"B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8",
"B9", "B10", "B11", "B12", "B13", "B14",
"R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8")
The4LYG <- c("Fluorophore", "V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8",
"V9", "V10", "V11","V12", "V13", "V14", "V15", "V16",
"B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8",
"B9", "B10", "B11", "B12", "B13", "B14",
"YG1", "YG2", "YG3", "YG4", "YG5", "YG6", "YG7", "YG8", "YG9", "YG10",
"R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8")
The3L <- c("Fluorophore", "V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8",
"V9", "V10", "V11","V12", "V13", "V14", "V15", "V16",
"B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8",
"B9", "B10", "B11", "B12", "B13", "B14",
"R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8")
The2LVB <- c("Fluorophore", "V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8",
"V9", "V10", "V11","V12", "V13", "V14", "V15", "V16",
"B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8",
"B9", "B10", "B11", "B12", "B13", "B14")
The2LBR <- c("Fluorophore", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8",
"B9", "B10", "B11", "B12", "B13", "B14",
"R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8")
The1L <- c("Fluorophore", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8",
"B9", "B10", "B11", "B12", "B13", "B14")
if (TotalDetectors == 64){colnames(x) <- The5L
} else if (TotalDetectors == 54){colnames(x) <- The4LUV
} else if (TotalDetectors == 48){colnames(x) <- The4LYG
} else if (TotalDetectors == 38){colnames(x) <- The3L
} else if (TotalDetectors == 30){colnames(x) <- The2LVB
} else if (TotalDetectors == 22){colnames(x) <- The2LBR
} else if (TotalDetectors == 14){colnames(x) <- The1L
} else {message("Number of Columns didn't match known Instrument")
}
return(x)
}
```

# Data Extraction

Process the .Expt to a data.frame
```{r}
Data <- SpectroFloSignatureParser(experiment)
```


# Plotting
And proceed to plot
```{r}
#| warning: false
#| message: false
library(tidyr)
library(ggplot2)
library(plotly)
```

```{r}
#BV711 <- Data %>% filter(Fluorophore %in% "BV711")
Tidyed <- Data %>% pivot_longer(cols = where(is.numeric), names_to = "Detector", values_to = "Value")
DetectorOrder <- Tidyed %>% pull(Detector) %>% unique()
Tidyed$Detector <- factor(Tidyed$Detector, levels=DetectorOrder)
plot <- ggplot(Tidyed, aes(x = Detector, y = Value, color = Fluorophore, group = Fluorophore)) +
geom_line() + labs(x = "Detector", y = "Normalized MFI", color = "Fluorophore") +
theme_bw() + theme(axis.text.x = element_text(size=5, angle = 70, hjust = 1))
plotly::ggplotly(plot)
```

0 comments on commit 189961b

Please sign in to comment.