11metricData <- data.frame (dataId = integer(), readsetId = integer(), metricname = character (), metricvalue = numeric ())
22
3- errors <- c()
43for (datasetId in names(seuratObjects )) {
54 seuratObj <- readRDS(seuratObjects [[datasetId ]])
65 metricData <- rbind(metricData , data.frame (dataId = datasetId , readsetId = datasetIdToReadset [[datasetId ]], metricname = ' TotalCells' , metricvalue = ncol(seuratObj )))
76
87 if (length(unique(seuratObj $ DatasetId )) > 1 ) {
9- errors <- c( errors , paste0(' Seurat data prototypes must be a single dataset. Problem ID: ' , datasetId ))
8+ addErrorMessage( paste0(' Seurat data prototypes must be a single dataset. Problem ID: ' , datasetId ))
109 }
1110
1211 if (is.null(usesHashing [[datasetId ]])) {
13- errors <- c( errors , paste0(' No hashing context provided for: ' , datasetId ))
12+ addErrorMessage( paste0(' No hashing context provided for: ' , datasetId ))
1413 break
1514 }
1615
1716 if (usesHashing [[datasetId ]]) {
1817 if (requireHashing && ! (' HTO.Classification' %in% names(seuratObj @ meta.data ))) {
19- errors <- c( errors , paste0(' Missing cell hashing calls for dataset: ' , datasetId ))
18+ addErrorMessage( paste0(' Missing cell hashing calls for dataset: ' , datasetId ))
2019 }
2120
2221 fractionFailedHashing <- 1 - (sum(seuratObj @ meta.data $ HTO.Classification %in% c(' Singlet' , ' Doublet' )) / nrow(seuratObj @ meta.data ))
2322 if (! is.null(maxHashingPctFail ) && fractionFailedHashing > maxHashingPctFail ) {
24- errors <- c( errors , paste0(' Fraction failing cell hashing was : ' , fractionFailedHashing , ' for dataset: ' , datasetId , ' , above threshold of: ' , maxHashingPctFail ))
23+ addErrorMessage( paste0(' Fraction failing cell hashing was : ' , fractionFailedHashing , ' for dataset: ' , datasetId , ' , above threshold of: ' , maxHashingPctFail ))
2524 }
2625
2726 metricData <- rbind(metricData , data.frame (dataId = datasetId , readsetId = datasetIdToReadset [[datasetId ]], metricname = ' FractionFailedHashing' , metricvalue = fractionFailedHashing ))
2827
2928 fractionDiscordantHashing <- 1 - (sum(seuratObj @ meta.data $ HTO.Classification == ' Discordant' ) / nrow(seuratObj @ meta.data ))
3029 if (! is.null(maxHashingPctDiscordant ) && fractionDiscordantHashing > maxHashingPctDiscordant ) {
31- errors <- c( errors , paste0(' Discordant hashing rate was: ' , fractionDiscordantHashing , ' for dataset: ' , datasetId , ' , above threshold of: ' , maxHashingPctDiscordant ))
30+ addErrorMessage( paste0(' Discordant hashing rate was: ' , fractionDiscordantHashing , ' for dataset: ' , datasetId , ' , above threshold of: ' , maxHashingPctDiscordant ))
3231 }
3332
3433 metricData <- rbind(metricData , data.frame (dataId = datasetId , readsetId = datasetIdToReadset [[datasetId ]], metricname = ' FractionDiscordantHashing' , metricvalue = fractionDiscordantHashing ))
3534 }
3635
3736 if (is.null(usesCiteSeq [[datasetId ]])) {
38- errors <- c( errors , paste0(' No CITE-seq context provided for: ' , datasetId ))
37+ addErrorMessage( paste0(' No CITE-seq context provided for: ' , datasetId ))
3938 break
4039 }
4140
4241 if (usesCiteSeq [[datasetId ]] && requireCiteSeq ) {
4342 if (! ' ADT' %in% names(seuratObj @ assays )) {
44- errors <- c( errors , paste0(' Missing ADT data for dataset: ' , datasetId ))
43+ addErrorMessage( paste0(' Missing ADT data for dataset: ' , datasetId ))
4544 }
4645
4746 fractionADTGT0 <- sum(seuratObj @ meta.data $ nCount_ADT > 0 ) / nrow(seuratObj @ meta.data )
@@ -52,29 +51,29 @@ for (datasetId in names(seuratObjects)) {
5251 }
5352
5453 if (requireSaturation && ! ' Saturation.RNA' %in% names(seuratObj @ meta.data )) {
55- errors <- c( errors , paste0(' Missing per-cell RNA saturation data for dataset: ' , datasetId ))
54+ addErrorMessage( paste0(' Missing per-cell RNA saturation data for dataset: ' , datasetId ))
5655 }
5756
5857 if (! is.null(minSaturation )) {
5958 if (! ' Saturation.RNA' %in% names(seuratObj @ meta.data )) {
60- errors <- c( errors , paste0(' Min saturation provided, but missing per-cell RNA saturation data for dataset: ' , datasetId ))
59+ addErrorMessage( paste0(' Min saturation provided, but missing per-cell RNA saturation data for dataset: ' , datasetId ))
6160 }
6261 }
6362
6463 if (' Saturation.RNA' %in% names(seuratObj @ meta.data )) {
6564 meanSaturation.RNA <- mean(seuratObj $ Saturation.RNA )
6665 if (! is.null(minSaturation ) && meanSaturation.RNA < minSaturation ) {
67- errors <- c( errors , paste0(' Mean RNA saturation was: ' , meanSaturation.RNA , ' for dataset: ' , datasetId , ' , below threshold of: ' , minSaturation ))
66+ addErrorMessage( paste0(' Mean RNA saturation was: ' , meanSaturation.RNA , ' for dataset: ' , datasetId , ' , below threshold of: ' , minSaturation ))
6867 }
6968
7069 metricData <- rbind(metricData , data.frame (dataId = datasetId , readsetId = datasetIdToReadset [[datasetId ]], metricname = ' MeanSaturation.RNA' , metricvalue = meanSaturation.RNA ))
7170 }
7271
7372 if (requireSingleR && ! ' dice.label' %in% names(seuratObj @ meta.data )) {
74- errors <- c( errors , paste0(' Missing SingleR DICE labels for dataset: ' , datasetId ))
73+ addErrorMessage( paste0(' Missing SingleR DICE labels for dataset: ' , datasetId ))
7574 }
7675
77- if (length(errors ) > 0 ) {
76+ if (length(errorMessages ) > 0 ) {
7877 break
7978 }
8079
@@ -90,15 +89,6 @@ for (datasetId in names(seuratObjects)) {
9089 gc()
9190}
9291
93- if (length(errors ) > 0 ) {
94- print(' There were errors:' )
95- for (msg in errors ) {
96- print(msg )
97- }
98-
99- write(errors , file = ' seuratErrors.txt' )
100- }
101-
10292if (nrow(metricData ) > 0 ) {
10393 write.table(metricData , file = ' seurat.metrics.txt' , sep = ' \t ' , quote = F , row.names = F , col.names = F )
10494}
0 commit comments