R/scanpyBootstrap.R

Defines functions scanpyBootstrap

Documented in scanpyBootstrap

#' @title Executing clustering with scanpy
#' @description This function executes a ubuntu docker that produces a specific number of permutation using scanpy as clustering tool.
#' @param group, a character string. Two options: sudo or docker, depending to which group the user belongs
#' @param scratch.folder, a character string indicating the path of the scratch folder
#' @param file, a character string indicating the path of the file, with file name and extension included
#' @param nPerm, number of permutations to be executed
#' @param permAtTime, number of permutations computed in parallel
#' @param percent, percentage of randomly selected cells removed in each permutation
#' @param separator, separator used in count file, e.g. '\\t', ','
#' @param perplexity, perplexity value for tsne projection
#' @param pca_number, PCA threshold selected using seuratPCAEval function.
#' @param seed, important value to reproduce the same results with same input
#' @param format, output file format csv or txt.  Mandatory because scanpy only accepts sparse matrices

#' @author Luca Alessandri, alessandri [dot] luca1991 [at] gmail [dot] com, University of Torino
#'
#' @return A folder Results containing a folder with the name of the experiment, which contains: VioPlot of silhouette cells value for each number of cluster used, a folder with the number of clusters used for SIMLR clustering, which contains: clusterP file with clustering results for each permutation, killedCell file with removed cells in each permutation, clustering.output a sommarize file with general information for each cells
#' @examples
#' \dontrun{
#' system("wget http://130.192.119.59/public/section4.1_examples.zip")
#' unzip("section4.1_examples.zip")
#' setwd("section4.1_examples")
#' scanpyBootstrap(group="docker",scratch.folder="/data/scratch/",
#'                 file=paste(getwd(), "matrix.mtx", sep="/"), 
#'                 nPerm=160, permAtTime=8, percent=10, separator="\t", 
#'                 perplexity=10, pca_number=6, seed=111, format="txt")
#'}
#' @export

scanpyBootstrap <- function(group=c("sudo","docker"), scratch.folder, file, nPerm, permAtTime, percent, separator, perplexity=40, pca_number=50, seed=111, format="NULL"){


  
   scanpyPermutation(group=group, scratch.folder=scratch.folder, file=file, nPerm=nPerm, permAtTime=permAtTime, percent=percent, separator=separator,pca_number=pca_number,seed=seed,sparse=TRUE,format=format,perplexity=perplexity)
   matrixName=strsplit(dirname(file),"/")[[1]][length(strsplit(dirname(file),"/")[[1]])]
   data.folder=paste(strsplit(dirname(file),"/")[[1]][-length(strsplit(dirname(file),"/")[[1]])],collapse="/")
   cluster.path <- paste(data.folder=data.folder, "Results",strsplit(dirname(file),"/")[[1]][length(strsplit(dirname(file),"/")[[1]])], sep="/")
    
    

    cluster <- as.numeric(list.dirs(cluster.path, full.names = FALSE, recursive = FALSE))
    if(length(cluster)==1){
         permAnalysisSeurat(group=group, scratch.folder=scratch.folder,file=file, nCluster=cluster, separator=separator, sp=0.8,sparse=TRUE,format=format)
    } else{
       cat("\nIt seems that there is more than one cluster folders in the output of seuratPermutation\n")
       cat("Check the results generated by seuratPermutation, and run permAnalysisSeurat selecting the cluster of interest\n")
       system("echo 5 > ExitStatusFile 2>&1")
    return(5)
    }
  
  
  
  
  
  
  
  

} 
kendomaniac/CASC documentation built on Oct. 4, 2023, 11:10 a.m.