<commit_before>
library(Seurat)
library(DoubletFinder)

options(future.globals.maxSize= 10779361280)
random.seed=20200107
min.pct=0.5
logfc.threshold=0.6

options_table<-read.table(parSampleFile1, sep="\t", header=F, stringsAsFactors = F)
myoptions<-split(options_table$V1, options_table$V2)

by_sctransform<-ifelse(myoptions$by_sctransform == "0", FALSE, TRUE)
reduction<-myoptions$reduction
npcs<-as.numeric(myoptions$pca_dims)
doublet_rates<-as.numeric(myoptions$doublet_rates)

assay=ifelse(by_sctransform, "SCT", "RNA")
by_harmony<-reduction=="harmony"

prefix<-outFile

if(!exists("obj")){
  obj=readRDS(parFile1)
  if(is.list(obj)){
    obj<-obj$obj
  }
}

sweep.res <- paramSweep_v3(obj, PCs = 1:npcs, sct = by_sctransform)
sweep.stats <- summarizeSweep(sweep.res, GT = FALSE)
bcmvn <- find.pK(sweep.stats)
bcmvn$pK=as.numeric(as.character(bcmvn$pK))

pK=bcmvn$pK
BCmetric=bcmvn$BCmetric
pK_choose = pK[which(BCmetric %in% max(BCmetric))]
pN=0.25

params_df<-data.frame("pN"=pN, "pK"=pK_choose, "doublet_rate"=c(1:10)*0.01)
params_df$nExp = round(ncol(obj) * params_df$doublet_rate)
params_df$label=paste0("DF.classification_", params_df$pN, "_", params_df$pK, "_", params_df$nExp)
write.csv(params_df, paste0(outFile, ".options.csv"), row.names=F)

doublet_rate=0.01
for (doublet_rate in c(1:10) * 0.01){
  cat("doublet_rate=", doublet_rate, "\n")
  nExp <- round(ncol(obj) * doublet_rate)  # expect 4% doublets
  obj <- doubletFinder_v3(obj, pN =pN, pK = pK_choose, nExp = nExp, PCs = 1:npcs)
}

write.csv(<EMAIL>, paste0(outFile, ".meta.csv"))
saveRDS(<EMAIL>, paste0(outFile, ".meta.rds"))

#https://nbisweden.github.io/workshop-scRNAseq/labs/compiled/seurat/seurat_01_qc.html
  <commit_msg>bugfix<commit_after>
library(Seurat)
library(DoubletFinder)

options(future.globals.maxSize= 10779361280)
random.seed=20200107
min.pct=0.5
logfc.threshold=0.6

options_table<-read.table(parSampleFile1, sep="\t", header=F, stringsAsFactors = F)
myoptions<-split(options_table$V1, options_table$V2)

by_sctransform<-ifelse(myoptions$by_sctransform == "0", FALSE, TRUE)
reduction<-myoptions$reduction
npcs<-as.numeric(myoptions$pca_dims)
doublet_rates<-as.numeric(myoptions$doublet_rates)

assay=ifelse(by_sctransform, "SCT", "RNA")
by_harmony<-reduction=="harmony"

prefix<-outFile

if(!exists("obj")){
  obj=readRDS(parFile1)
  if(is.list(obj)){
    obj<-obj$obj
  }
}

sweep.res <- paramSweep_v3(obj, PCs = 1:npcs, sct = by_sctransform)
sweep.stats <- summarizeSweep(sweep.res, GT = FALSE)
bcmvn <- find.pK(sweep.stats)
bcmvn$pK=as.numeric(as.character(bcmvn$pK))

pK=bcmvn$pK
BCmetric=bcmvn$BCmetric
pK_choose = pK[which(BCmetric %in% max(BCmetric))]
pN=0.25

params_df<-data.frame("pN"=pN, "pK"=pK_choose, "doublet_rate"=c(1:10)*0.01)
params_df$nExp = round(ncol(obj) * params_df$doublet_rate)
params_df$label=paste0("DF.classifications_", params_df$pN, "_", params_df$pK, "_", params_df$nExp)
write.csv(params_df, paste0(outFile, ".options.csv"), row.names=F)

doublet_rate=0.01
for (doublet_rate in c(1:10) * 0.01){
  cat("doublet_rate=", doublet_rate, "\n")
  nExp <- round(ncol(obj) * doublet_rate)  # expect 4% doublets
  obj <- doubletFinder_v3(obj, pN =pN, pK = pK_choose, nExp = nExp, PCs = 1:npcs)
}

write.csv(<EMAIL>, paste0(outFile, ".meta.csv"))
saveRDS(<EMAIL>, paste0(outFile, ".meta.rds"))

#https://nbisweden.github.io/workshop-scRNAseq/labs/compiled/seurat/seurat_01_qc.html
  
{'fraction_non_alphanumeric': 0.17470588235294118, 'fraction_numerical': 0.033529411764705884, 'mean_word_length': 6.964871194379391, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4990745', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1494, 'n_words': 194}