@@ -591,6 +591,225 @@ RetrievedData <- Coereba::Coereba_FCS_Reversal(Coereba=FCSPath)
591591head(RetrievedData, 5)
592592```
593593
594+ ## Normalization Bypass
595+
596+ Alternatively, if you are planning to normalize the files with CytoNorm, you don't want to return a concatenated file, but individual cytoframe objects. Here is an example workflow:
597+
598+ ``` {r}
599+ #| label: ListOfFlowFrames
600+ CoerebaFlowFrame <- Utility_Coereba(gs=UnmixedGatingSet, subsets="root",
601+ sample.name="GROUPNAME", reference=CheckedGates, starter="Comp-PE-Vio770-A",
602+ inverse.transform = TRUE, returnType="flowframe", Individual=TRUE, outpath=NULL,
603+ columns = MarkersForToday)
604+ ```
605+
606+ ``` {r}
607+ CoerebaFlowFrame1 <- unlist(CoerebaFlowFrame)
608+
609+ FlowSet <- flowCore::flowSet(CoerebaFlowFrame1)
610+ FlowGS <- GatingSet(FlowSet)
611+
612+ MarkersUpdated <- gsub("Comp-", "", MarkersForToday)
613+ ```
614+
615+ ``` {r}
616+ MyBiexponentialTransform <- flowjo_biexp_trans(channelRange = 256, maxValue = 1000000,
617+ pos = 4.5, neg = 0, widthBasis = -1000)
618+ TransformList <- transformerList(MarkersUpdated, MyBiexponentialTransform)
619+
620+ InverseBiexponential <- flowjo_biexp(inverse=TRUE, channelRange=256, maxValue=1000000, pos=5.25, neg=0, width=-1000)
621+ ReverseBiexponential <- transformList(MarkersUpdated, InverseBiexponential)
622+
623+ FlowSet_Transformed <- transform(FlowGS, TransformList)
624+ ```
625+
626+ ``` {r}
627+ ShinyGatesSplitpoints2 <- ShinyGatesSplitpoints
628+ colnames(ShinyGatesSplitpoints2) <- gsub("Comp-", "", colnames(ShinyGatesSplitpoints2))
629+
630+ PostCoereba <- Utility_NbyNPlots(x=FlowGS[4], sample.name=c("GROUPNAME"), experiment="ABs",
631+ condition="DNs", removestrings=".fcs", marginsubset="root", gatesubset="root",
632+ ycolumn="PE-Vio770-A", bins=150, clearance=0.1,
633+ gatelines=TRUE, reference=ShinyGatesSplitpoints2, outpath=StorageLocationForPlotPDF, returntype="patchwork")
634+ ```
635+
636+ ``` {r}
637+ PostCoereba
638+ ```
639+
640+ ### Readding filtering data
641+
642+ ``` {r}
643+ Specimen <- function(x){
644+ pattern <- "([A-Z]+[0-9]+_[0-9]+)(?=_SEB)"
645+ result <- stringr::str_extract(x, pattern)
646+ result <- data.frame(Specimen = result)
647+ return(result)
648+ }
649+
650+ Experiment <- function(x){
651+ pattern <- "(?<=_)AB_[0-9]{2}(?=_)"
652+ result <- stringr::str_extract(x, pattern)
653+ result <- data.frame(Experiment = result)
654+ return(result)
655+ }
656+ ```
657+
658+ ``` {r}
659+ OriginalPD <- pData(UnmixedGatingSet)
660+ ValuesOriginal <- OriginalPD |> pull(name)
661+ TheSpecimen <- map(ValuesOriginal, .f=Specimen) %>% bind_rows()
662+ TheExperiment <- map(ValuesOriginal, .f=Experiment) %>% bind_rows()
663+ ```
664+
665+ ``` {r}
666+ OtherPD <- pData(FlowGS)
667+ UpdatedPD <- cbind(OtherPD, TheSpecimen, TheExperiment)
668+ UpdatedPD <- UpdatedPD |> mutate(Donor = str_replace(Specimen, "_[0-9]+$", ""))
669+ pData(FlowGS) <- UpdatedPD
670+ ```
671+
672+ ### Subsetting Controls
673+
674+ ``` {r}
675+ TheNormies <- subset(FlowGS, Donor=="NY068")
676+ #pData(TheNormies)
677+ NormCounts <- gs_pop_get_stats(TheNormies, nodes="root", type="count")
678+ TheCount <- sum(NormCounts$count)
679+ NormiesCS <- gs_cyto_data(TheNormies)
680+ #pData(NormiesCS)
681+ TheNewNormies <- cytoset_to_flowSet(NormiesCS)
682+ ```
683+
684+ ``` {r}
685+ Batch <- pData(TheNewNormies)$Experiment
686+ ```
687+
688+ ``` {r}
689+ library(CytoNorm)
690+
691+ NormPath <- file.path("C:", "Users", "12692", "Desktop", "CytoNorm")
692+
693+ model <- CytoNorm.train(files=TheNewNormies,
694+ labels=Batch,
695+ channels=MarkersUpdated,
696+ transformList=NULL,
697+ seed=1989,
698+ plot=TRUE,
699+ verbose=TRUE,
700+ normMethod.train = "QuantileNorm.train",
701+ normParams = list(nQ = 99),
702+ FlowSOM.params = list(nCells = TheCount,
703+ xdim = 15, ydim = 15, nClus = 9,
704+ scale = FALSE, colsToUse = MarkersUpdated),
705+ outputDir = NormPath,
706+ clean = TRUE,
707+ recompute = TRUE)
708+ ```
709+
710+ ``` {r}
711+ LongTermStorage <- file.path(NormPath, "SmallModel.rds")
712+ saveRDS(object = model, file = LongTermStorage)
713+ ```
714+
715+ ``` {r}
716+ LongTermStorage <- file.path(NormPath, "SmallModel.rds")
717+ previousModel <- readRDS(LongTermStorage)
718+ goal_q <- getCytoNormQuantiles(previousModel)
719+ Batch <- pData(TheNormies)$Experiment
720+ #ForClustering1 <- GetChannels(object = NormalizeGS2[[1]], markers = ForClustering)
721+
722+ model_Distribution <- CytoNorm.train(files=TheNewNormies,
723+ labels=Batch,
724+ channels=MarkersUpdated,
725+ transformList=NULL,
726+ seed=1989,
727+ plot=TRUE,
728+ verbose=TRUE,
729+ normParams = list("goal" = goal_q),
730+ FlowSOM.params = list(nCells = TheCount,
731+ xdim = 15, ydim = 15, nClus = 9,
732+ scale = FALSE, colsToUse=MarkersUpdated),
733+ outputDir = NormPath,
734+ clean = TRUE,
735+ recompute = TRUE)
736+ ```
737+
738+
739+ And finally, we normalize everyone else
740+ ``` {r}
741+ AllNormies <- FlowGS
742+ AllCS <- gs_cyto_data(AllNormies)
743+ AllFS <- cytoset_to_flowSet(AllCS)
744+
745+ Batch <- pData(AllFS)$Experiment
746+
747+ # Use model or model_Distribution
748+
749+ NormalizeAttempt <- CytoNorm.normalize(model=model,
750+ files=AllFS,
751+ labels=Batch,
752+ transformList = NULL,
753+ verbose=TRUE,
754+ prefix="Norm_",
755+ transformList.reverse = NULL,
756+ outputDir= NormPath,
757+ clean = TRUE,
758+ write = FALSE)
759+ ```
760+
761+ And finally, we update the metadata for the new GatingSet
762+ ``` {r}
763+ pd3 <- pData(NormalizeAttempt)
764+ colnames(pd3) <- "thename"
765+
766+ pd <- pData(FlowGS)
767+ UpdatedPD <- cbind(pd3, pd)
768+
769+ pData(NormalizeAttempt) <- UpdatedPD
770+ ```
771+
772+ ``` {r}
773+ #| eval: FALSE
774+ Population <- "TestSet"
775+ UpdatedGS <- GatingSet(NormalizeAttempt)
776+ pData(UpdatedGS)
777+ filename <- paste0(Population, "_Norm")
778+
779+ Utility_RidgePlots(gs=UpdatedGS, subset="root", TheY="Specimen", TheFill="Experiment", outpath=NormPath, returntype="pdf", filename = filename, therows = 1)
780+
781+ NormedND <- subset(UpdatedGS, Donor == "NY068")
782+
783+ filename <- paste0(Population, "_Norm_ND006")
784+
785+ Utility_RidgePlots(gs=NormedND, subset="root", TheY="Specimen", TheFill="Experiment", outpath=NormPath, returntype="pdf", filename = filename, therows = 1)
786+ ```
787+
788+ ### Reverse Biexponential
789+ ``` {r}
790+ ReversedGS <- transform(NormalizeAttempt, ReverseBiexponential)
791+ ThisWork <- GatingSet(ReversedGS)
792+ ```
793+
794+ ``` {r}
795+ NormedNotND <- subset(ThisWork, Donor != "NY068")
796+ pData(NormedNotND)
797+ TheCalcs <- gs_pop_get_stats(NormedNotND, nodes="root", type="count")
798+ min(TheCalcs$count)
799+ # 1000
800+ ```
801+
802+ # Out to FCS File
803+
804+ ``` {r}
805+ Goodbye <- Coereba_Concatenate(Set=NormedNotND, metadata_cols=c("Experiment", "Donor"), outpath="C:/Users/12692/Desktop", filename="DidItWork")
806+ ```
807+
808+
809+
810+
811+
812+
594813# Generating a Summarized Experiment File
595814
596815Taking the ` Utility_Coereba() ` output, we can combine it with metadata and panel information into a SummarizedExperiment object. This will permit us in turn to tie in to a lot of the existing Bioconductor project analysis infrastructure. We do this through the ` Coereba_Processing() ` function.
0 commit comments