Skip to content

Commit

Permalink
Merge pull request #45 from CostaLab/devel
Browse files Browse the repository at this point in the history
Updated namespace
  • Loading branch information
grasshoffm authored Oct 15, 2024
2 parents d514d9a + a32ad59 commit e880916
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: sigurd
Type: Package
Title: Single cell Genotyping Using RNA Data
Version: 0.3.4
Version: 0.3.6
Authors@R: c(
person(given = "Martin",
family = "Grasshoff",
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export(CalculateConsensus)
export(CalculateCorrelationPValue)
export(CalculateCoverage)
export(CalculateFisherTestPValue)
export(CalculateForwardReads)
export(CalculateQuality)
export(CalculateRefReads)
export(CalculateReverseReads)
export(CalculateStrandCorrelation)
export(CallSupport)
export(ClonalDefinition)
Expand All @@ -21,6 +23,7 @@ export(GetCellInfoPerVariant)
export(GetVariantInfo)
export(HeatmapVoi)
export(LoadingMAEGATK_typewise)
export(LoadingMGATK_typewise)
export(LoadingRawMatrix_typewise)
export(LoadingVCF_typewise)
export(LoadingVarTrix_typewise)
Expand All @@ -38,6 +41,7 @@ export(VariantQuantileThresholding_Combined)
export(VariantSelection_Group)
export(VariantSelection_Quantile)
export(VariantSelection_TopCells)
export(VariantSelection_VMR)
export(VariantWiseCorrelation)
export(VariantWiseFisherTest)
export(char_to_numeric)
Expand Down Expand Up @@ -70,6 +74,7 @@ importFrom(Matrix,rowSums)
importFrom(Matrix,sparseMatrix)
importFrom(Matrix,summary)
importFrom(Matrix,t)
importFrom(MatrixGenerics,rowVars)
importFrom(S4Vectors,DataFrame)
importFrom(S4Vectors,merge)
importFrom(S4Vectors,metadata)
Expand Down
10 changes: 7 additions & 3 deletions R/RowWiseSplit.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
#'Performing the correlation or Fisher test association for a SummarizedExperiment object requires extreme amounts of memory.
#'To reduce the amount of memory necessary, we instead get the individual rows from the consensus assay.
#'We can then remove the NoCalls (no reads) from the individual vectors, further reducing the amount of memory needed.
#'
#'When the NoCalls are removed, the repective cells are also removed if a different assay is selected.
#'@importFrom parallel mclapply
#'@importFrom SummarizedExperiment assays
#'@param se SummarizedExperiment object.
#'@param n_cores Number of cores to use.
#'@param remove_nocalls Do you want to remove NoCall cells?
#'@param assay_to_split Which assay to you want to split?
#'@export
RowWiseSplit <- function(se, n_cores = 1, minimum_reads, remove_nocalls = TRUE){
consensus <- SummarizedExperiment::assays(se)$consensus
consensus_list <- parallel::mclapply(rownames(se), SeparatingMatrixToList, total_matrix = consensus, remove_nocalls = remove_nocalls, mc.cores = n_cores)
RowWiseSplit <- function(se, n_cores = 1, assay_to_split = "consensus", remove_nocalls = TRUE){
selected_assay <- SummarizedExperiment::assays(se)[[assay_to_split]]
consensus <- SummarizedExperiment::assays(se)[["consensus"]]
consensus_list <- parallel::mclapply(rownames(se), SeparatingMatrixToList, total_matrix = selected_assay, assay_to_split = assay_to_split, consensus = consensus, remove_nocalls = remove_nocalls, mc.cores = n_cores)
names(consensus_list) <- rownames(se)
return(consensus_list)
}
19 changes: 13 additions & 6 deletions R/SeparatingMatrixToList.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@
#'@importFrom stats na.omit
#'@param row_use The row the separate.
#'@param total_matrix The matrix to be split.
#'@param assay_to_split Which assay are we splitting?
#'@param remove_nocalls Do you want to remove NoCall cells?
#'@export
SeparatingMatrixToList <- function(row_use, total_matrix, remove_nocalls = TRUE){
SeparatingMatrixToList <- function(row_use, total_matrix, consensus, assay_to_split = "consensus", remove_nocalls = TRUE){
selected_row <- total_matrix[row_use,]
selected_row <- stats::na.omit(selected_row)

if(remove_nocalls == TRUE){
# We remove the NoCall cells.
selected_row <- selected_row[selected_row != 0]
selected_row[selected_row == 1] <- 0
selected_row[selected_row >= 2] <- 1
selected_consensus <- consensus[row_use,]
selected_consensus <- stats::na.omit(selected_consensus)
selected_row <- selected_row[selected_consensus != 0]
if(assay_to_split == "consensus"){
selected_row[selected_row == 1] <- 0
selected_row[selected_row >= 2] <- 1
}
} else if(remove_nocalls == FALSE){
selected_row[selected_row <= 1] <- 0
selected_row[selected_row >= 2] <- 1
if(assay_to_split == "consensus"){
selected_row[selected_row <= 1] <- 0
selected_row[selected_row >= 2] <- 1
}
}
return(selected_row)
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The mutation data was obtained from the Sanger Institute Catalogue Of Somatic Mu
```

# Current Features v0.3.4
# Current Features v0.3.6

- Loading data from VarTrix and MAEGATK.
- Transforming the data to be compatible for joint analysis.
Expand Down
11 changes: 10 additions & 1 deletion man/RowWiseSplit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion man/SeparatingMatrixToList.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/testthat/test-SeparatingMatrixToList.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ test_that("Testing SeparatingMatrixToList.R", {
test2 <- sigurd::SeparatingMatrixToList("chrM_2_A_G", input_matrix, remove_nocalls = FALSE)
test3 <- sigurd::SeparatingMatrixToList("chrM_2_A_T", input_matrix, remove_nocalls = FALSE)
test4 <- sigurd::SeparatingMatrixToList("chrM_4_C_G", input_matrix, remove_nocalls = FALSE)
test1_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_1_G_A", input_matrix, remove_nocalls = TRUE)
test2_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_2_A_G", input_matrix, remove_nocalls = TRUE)
test3_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_2_A_T", input_matrix, remove_nocalls = TRUE)
test4_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_4_C_G", input_matrix, remove_nocalls = TRUE)
test1_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_1_G_A", input_matrix, consensus = input_matrix, remove_nocalls = TRUE)
test2_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_2_A_G", input_matrix, consensus = input_matrix, remove_nocalls = TRUE)
test3_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_2_A_T", input_matrix, consensus = input_matrix, remove_nocalls = TRUE)
test4_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_4_C_G", input_matrix, consensus = input_matrix, remove_nocalls = TRUE)
# We generate the expected outputs.
expected_result1 <- c(Cell_1 = 0, Cell_2 = 1, Cell_3 = 1, Cell_4 = 0)
expected_result2 <- c(Cell_1 = 0, Cell_2 = 1, Cell_3 = 1, Cell_4 = 0)
Expand Down

0 comments on commit e880916

Please sign in to comment.