|
12 | 12 | #' @param device Desired storage format, default is "png" |
13 | 13 | #' @param width Desired height for saved plot, default is 15 |
14 | 14 | #' @param height Desired height for saved plot, default is 15 |
| 15 | +#' @param NumberDetectors Default NULL, used when unstained is NULL |
15 | 16 | #' |
16 | 17 | #' @importFrom dplyr mutate |
17 | 18 | #' @importFrom dplyr relocate |
|
43 | 44 | #' @noRd |
44 | 45 | MagesCauldron <- function(panelfluors, unstained, returnType="plot", savePlot=FALSE, |
45 | 46 | outpath=NULL, filename=NULL, device="png", width=15, height=15, swapname=NULL, |
46 | | - swapvalue=NULL){ |
| 47 | + swapvalue=NULL, NumberDetectors=NULL){ |
47 | 48 |
|
| 49 | + if (!is.null(unstained)){ |
48 | 50 | DetectorLength <- ncol(unstained) |
49 | 51 |
|
50 | 52 | if (any(unstained > 1)){ |
51 | 53 | unstained[unstained < 0] <- 0 |
52 | 54 | A <- do.call(pmax, unstained) |
53 | 55 | unstained <- unstained/A |
54 | 56 | } |
| 57 | + |
| 58 | + TheUnstained <- unstained |> mutate(Fluorophore="Unstained") |> |
| 59 | + relocate(Fluorophore, .before=1) |
| 60 | + } else { |
| 61 | + if (is.null(NumberDetectors)){ |
| 62 | + stop("When not providing unstained, provide NumberDetectors argument") |
| 63 | + } |
| 64 | + DetectorLength <- NumberDetectors |
| 65 | + } |
55 | 66 |
|
56 | 67 | Vaiya <- InstrumentReferences(NumberDetectors = DetectorLength) |
57 | | - TheUnstained <- unstained |> mutate(Fluorophore="Unstained") |> |
58 | | - relocate(Fluorophore, .before=1) |
59 | 68 | TheseFluorophores <- panelfluors |
60 | 69 | Data <- Vaiya |> filter(Fluorophore %in% TheseFluorophores) |
61 | 70 | Data <- Data |> select(-Instrument) |
62 | 71 | Data <- Data |> pivot_wider(names_from="Detector", |
63 | 72 | values_from="AdjustedY") |
| 73 | + |
| 74 | + if (!is.null(unstained)){ |
64 | 75 | colnames(TheUnstained) <- gsub("-A", "", gsub("-H", "", colnames(TheUnstained))) |
65 | 76 | Data <- bind_rows(Data, TheUnstained) |
66 | 77 | TheseFluorophores <- c(TheseFluorophores, paste0("Unstained", seq_len(nrow(unstained)))) |
| 78 | + } |
| 79 | + |
67 | 80 | Data$Fluorophore <- factor(Data$Fluorophore, levels=TheseFluorophores) |
68 | 81 | Data <- Data |> arrange(desc(Fluorophore)) |
69 | 82 | Data <- Data |> arrange(Fluorophore) |
|
0 commit comments