Unverified Commit 991165d5 authored by cziegenhain's avatar cziegenhain Committed by GitHub
Browse files

Merge pull request #195 from gringer/yaml-noedit

Create shadow YAML file for correcting errors, warn about changes
parents bcac30f4 7ae52839
Loading
Loading
Loading
Loading
+37 −32
Original line number Original line Diff line number Diff line
#!/usr/bin/env Rscript
#!/usr/bin/env Rscript


suppressMessages(require(yaml))
suppressMessages(
    if(!require(yaml)){
        stop("Library 'yaml' is needed by R; please install it");
    })
y<-commandArgs(trailingOnly = T)
y<-commandArgs(trailingOnly = T)


inp<-try(read_yaml(y),silent =  T)
inp<-try(read_yaml(y),silent =  T)
@@ -10,7 +13,7 @@ e=0
if(grepl("try-error",class(inp))) {
if(grepl("try-error",class(inp))) {
  e=1
  e=1
  print(e)
  print(e)
  stop()
  stop("Syntax error loading yaml file")
}
}




@@ -60,7 +63,8 @@ print(
           function(x) {
           function(x) {
             if(is.null(unlist(inp$sequence_files[[x]]$name)))  {
             if(is.null(unlist(inp$sequence_files[[x]]$name)))  {
               e=1
               e=1
               print(paste(print(names(inp$sequence_files[x])),": You need to provide path to the input file")) 
               print(paste(print(names(inp$sequence_files[x])),
                           ": You need to provide a path for this input file"))
               }else{ print("")}
               }else{ print("")}
             })
             })
))
))
@@ -70,7 +74,8 @@ print(
         function(x) {
         function(x) {
           if(is.null(unlist(inp$sequence_files[[x]]$base_definition))) {
           if(is.null(unlist(inp$sequence_files[[x]]$base_definition))) {
             e=1
             e=1
             print(paste(print(names(inp$sequence_files[x])),": You need to provide base definitions for this input file"))}
             print(paste(print(names(inp$sequence_files[x])),
                         ": You need to provide base definitions for this input file"))}
         })
         })
  )
  )
)
)
@@ -80,7 +85,7 @@ lapply(inp$sequence_files,
         if(!is.null(x$base_definition)) {
         if(!is.null(x$base_definition)) {
           if(any(!grepl("^BC|^UMI|^cDNA",x$base_definition)))  {
           if(any(!grepl("^BC|^UMI|^cDNA",x$base_definition)))  {
             e=1
             e=1
             print("The base definition can only be BC/cDNA/UMI. Check if you have a typo/special characters in your base definition or you forgot to add /space/ after -. Refer to the example yaml.")
             print("The base definition can only be BC/cDNA/UMI. Check if you have a typo/special characters in your base definition or you forgot to add /space/ after -. Refer to the example yaml in the zUMIs installation directory.")
           }
           }
         }
         }
       })
       })
+172 −173
Original line number Original line Diff line number Diff line
@@ -4,16 +4,18 @@
# Authors: Swati Parekh, Christoph Ziegenhain, Beate Vieth & Ines Hellmann
# Authors: Swati Parekh, Christoph Ziegenhain, Beate Vieth & Ines Hellmann
# Contact: sparekh@age.mpg.de or christoph.ziegenhain@ki.se
# Contact: sparekh@age.mpg.de or christoph.ziegenhain@ki.se
vers=2.8.3
vers=2.8.3
currentv=`curl -s https://raw.githubusercontent.com/sdparekh/zUMIs/master/zUMIs-master.sh | grep '^vers=' | cut -f2 -d "="`
currentv=$(curl -s https://raw.githubusercontent.com/sdparekh/zUMIs/master/zUMIs-master.sh | grep '^vers=' | cut -f2 -d "=")
if [ "$currentv" != "$vers" ]; then echo -e "------------- \n\n Good news! A newer version of zUMIs is available at https://github.com/sdparekh/zUMIs \n\n-------------"; fi
if [ "$currentv" != "$vers" ] ; then
    echo -e "------------- \n\n Good news! A newer version of zUMIs is available at https://github.com/sdparekh/zUMIs \n\n-------------";
fi


function check_opts() {
function check_opts() {
    value=$1
    value=$1
    name=$2
    name=$2
    flag=$3
    flag=$3


    if [[ -z "$value" ]]
    if [[ -z "${value}" ]] ; then
    then failure "No $name!! One can not run this pipeline without $flag option."
        failure "No ${name}!! One can not run this pipeline without ${flag} option."
    fi
    fi
}
}


@@ -28,7 +30,7 @@ zumis=$0
function usage () {
function usage () {
    cat >&2 <<EOF
    cat >&2 <<EOF


  USAGE: $zumis [options]
  USAGE: ${zumis} [options]
	-h  Print the usage info.
	-h  Print the usage info.


## Required parameters ##
## Required parameters ##
@@ -42,238 +44,239 @@ function usage () {


  -c : Use zUMIs dependencies in the preinstalled conda enviroment.
  -c : Use zUMIs dependencies in the preinstalled conda enviroment.


zUMIs version $vers
zUMIs version ${vers}


EOF
EOF
}
}


# Define the default variables #
# Define the default variables #
zumisdir=$(dirname `readlink -f $0`)
zumisdir=$(dirname $(readlink -f $0))




while getopts ":y:d:ch" options; do #Putting <:> between keys implies that they can not be called without an argument.
while getopts ":y:d:ch" options; do #Putting <:> between keys implies that they can not be called without an argument.
  case $options in
  case ${options} in
  y ) yaml=$OPTARG;;
  y ) yaml=${OPTARG};;
  d ) zumisdir=$OPTARG;;
  d ) zumisdir=${OPTARG};;
  c ) conda=true;;
  c ) conda=true;;
  h ) usage
  h ) usage
          exit 1;;
          exit 1;;
  \? ) echo -e "\n This key is not available! Please check the usage again: -$OPTARG"
  \? ) echo -e "\n This key is not available! Please check the usage again: -${OPTARG}"
  	usage
  	usage
  	exit 1;;
  	exit 1;;
  esac
  esac
done
done


if [[ $OPTIND -eq 1 ]] ; then
if [[ ${OPTIND} -eq 1 ]] ; then
    usage
    usage
    exit 1
    exit 1
fi
fi


check_opts "$yaml" "YAML" "-y"
check_opts "${yaml}" "YAML" "-y"

# create temporary YAML file for corrected options
yaml_orig=${yaml}
yaml=$(dirname ${yaml})/$(basename ${yaml} .yaml).corrected.yaml
cp ${yaml_orig} ${yaml}


#now get some variables from YAML
#now get some variables from YAML
num_threads=`grep 'num_threads' $yaml | awk '{print $2}'`
num_threads=$(grep 'num_threads' ${yaml} | awk '{print $2}')
project=`grep 'project:' $yaml | awk '{print $2}'`
project=$(grep 'project:' ${yaml} | awk '{print $2}')
whichStage=`grep 'which_Stage:' $yaml | awk '{print $2}'`
whichStage=$(grep 'which_Stage:' ${yaml} | awk '{print $2}')
outdir=`grep 'out_dir' $yaml | awk '{print $2}'`
outdir=$(grep 'out_dir' ${yaml} | awk '{print $2}')
genomedir=`grep 'STAR_index:' $yaml | awk '{print $2}'`
genomedir=$(grep 'STAR_index:' ${yaml} | awk '{print $2}')
mem_limit=`grep 'mem_limit:' $yaml | awk '{print $2}'`
mem_limit=$(grep 'mem_limit:' ${yaml} | awk '{print $2}')
isstats=`grep 'make_stats:' $yaml | awk '{print $2}'`
isstats=$(grep 'make_stats:' ${yaml} | awk '{print $2}')
fqfiles=`grep 'name:' $yaml | awk '{print $2}'`
fqfiles=$(grep 'name:' ${yaml} | awk '{print $2}')
velo=`grep 'velocyto:' $yaml | awk '{print $2}'`
velo=$(grep 'velocyto:' ${yaml} | awk '{print $2}')
staridxdir=`grep 'STAR_index:' $yaml | awk '{print $2}'`
staridxdir=$(grep 'STAR_index:' ${yaml} | awk '{print $2}')




if grep -q 'samtools_exec:' $yaml
if grep -q 'samtools_exec:' ${yaml} ; then
  then
    samtoolsexc=$(grep 'samtools_exec' ${yaml} | awk '{print $2}')
    samtoolsexc=`grep 'samtools_exec' $yaml | awk '{print $2}'`
else
else
    samtoolsexc=samtools
    samtoolsexc=samtools
    echo "samtools_exec: $samtoolsexc" >> $yaml
    echo "samtools_exec: ${samtoolsexc}" >> ${yaml}
fi
fi


if grep -q 'pigz_exec:' $yaml
if grep -q 'pigz_exec:' ${yaml} ; then
  then
    pigzexc=$(grep 'pigz_exec' ${yaml} | awk '{print $2}')
    pigzexc=`grep 'pigz_exec' $yaml | awk '{print $2}'`
else
else
    echo "Warning: YAML file doesn't include 'pigz_exec' option; setting to 'pigz'"
    pigzexc=pigz
    pigzexc=pigz
    echo "pigz_exec: $pigzexc" >> $yaml
    echo "pigz_exec: ${pigzexc}" >> ${yaml}
fi
fi


if grep -q 'STAR_exec:' $yaml
if grep -q 'STAR_exec:' ${yaml} ; then
  then
    starexc=$(grep 'STAR_exec' ${yaml} | awk '{print $2}')
    starexc=`grep 'STAR_exec' $yaml | awk '{print $2}'`
else
else
    echo "Warning: YAML file doesn't include 'STAR_exec' option; setting to 'STAR'"
    starexc=STAR
    starexc=STAR
    echo "STAR_exec: $starexc" >> $yaml
    echo "STAR_exec: ${starexc}" >> ${yaml}
fi
fi


if grep -q 'Rscript_exec:' $yaml
if grep -q 'Rscript_exec:' ${yaml} ; then
  then
    Rexc=$(grep 'Rscript_exec' ${yaml} | awk '{print $2}')
    Rexc=`grep 'Rscript_exec' $yaml | awk '{print $2}'`
else
else
    echo "Warning: YAML file doesn't include 'Rscript_exec' option; setting to 'Rscript'"
    Rexc=Rscript
    Rexc=Rscript
    echo "Rscript_exec: $Rexc" >> $yaml
    echo "Rscript_exec: ${Rexc}" >> ${yaml}
fi
fi


#check for conda usage!
#check for conda usage!
if [[ $conda = true ]]; then
if [[ ${conda} = true ]] ; then
  echo "Using miniconda environment for zUMIs!"
  echo "Using miniconda environment for zUMIs!"
  echo " note: internal executables will be used instead of those specified in the YAML file!"
  samtoolsexc=samtools
  samtoolsexc=samtools
  if grep -q 'samtools_exec:' $yaml; then
  if grep -q 'samtools_exec:' ${yaml} ; then
      sed -i '/samtools_exec:/d' $yaml
      sed -i '/samtools_exec:/d' ${yaml}
  fi
  fi
  echo "samtools_exec: $samtoolsexc" >> $yaml
  echo "samtools_exec: ${samtoolsexc}" >> ${yaml}
  pigzexc=pigz
  pigzexc=pigz
  if grep -q 'pigz_exec:' $yaml; then
  if grep -q 'pigz_exec:' ${yaml} ; then
      sed -i '/pigz_exec:/d' $yaml
      sed -i '/pigz_exec:/d' ${yaml}
  fi
  fi
  echo "pigz_exec: $pigzexc" >> $yaml
  echo "pigz_exec: ${pigzexc}" >> ${yaml}
  starexc=STAR
  starexc=STAR
  if grep -q 'STAR_exec:' $yaml; then
  if grep -q 'STAR_exec:' ${yaml} ; then
      sed -i '/STAR_exec:/d' $yaml
      sed -i '/STAR_exec:/d' ${yaml}
  fi
  fi
  echo "STAR_exec: $starexc" >> $yaml
  echo "STAR_exec: ${starexc}" >> ${yaml}
  Rexc=Rscript
  Rexc=Rscript
  if grep -q 'Rscript_exec:' $yaml; then
  if grep -q 'Rscript_exec:' ${yaml} ; then
      sed -i '/Rscript_exec:/d' $yaml
      sed -i '/Rscript_exec:/d' ${yaml}
  fi
  fi
  echo "Rscript_exec: $Rexc" >> $yaml
  echo "Rscript_exec: ${Rexc}" >> ${yaml}


  zumisenv=$zumisdir/zUMIs-env
  zumisenv=${zumisdir}/zUMIs-env
  miniconda=$zumisdir/zUMIs-miniconda.tar.bz2
  miniconda=${zumisdir}/zUMIs-miniconda.tar.bz2
  #check if zUMIs environment has been unpacked from tar
  #check if zUMIs environment has been unpacked from tar
  if [[ ! -d $zumisenv ]] || [[ $zumisdir/zUMIs-miniconda.partaa -nt $zumisenv ]] ; then
  if [[ ! -d ${zumisenv} ]] || [[ ${zumisdir}/zUMIs-miniconda.partaa -nt ${zumisenv} ]] ; then
    [ -d $zumisenv ] || mkdir -p $zumisenv
    [ -d ${zumisenv} ] || mkdir -p ${zumisenv}
    cat $zumisdir/zUMIs-miniconda.parta* > $miniconda
    cat ${zumisdir}/zUMIs-miniconda.parta* > ${miniconda}
    tar -xj --overwrite -f $miniconda -C $zumisenv
    tar -xj --overwrite -f ${miniconda} -C ${zumisenv}
  fi
  fi
  #activate zUMIs environment!
  #activate zUMIs environment!
  unset PYTHONPATH
  unset PYTHONPATH
  unset PYTHONHOME
  unset PYTHONHOME
  source $zumisenv/bin/activate
  source ${zumisenv}/bin/activate
  conda-unpack
  conda-unpack
fi
fi


if grep -q 'zUMIs_directory:' $yaml
if grep -q 'zUMIs_directory:' ${yaml} ; then
  then
    sed -i "s|zUMIs_directory:.*|zUMIs_directory: ${zumisdir}|" ${yaml}
    sed -i "s|zUMIs_directory:.*|zUMIs_directory: $zumisdir|" $yaml
else
else
    echo "zUMIs_directory: $zumisdir" >> $yaml
    echo "zUMIs_directory: ${zumisdir}" >> ${yaml}
fi
fi


$Rexc $zumisdir/checkyaml.R $yaml > $project.zUMIs_YAMLerror.log
${Rexc} ${zumisdir}/checkyaml.R ${yaml} > ${project}.zUMIs_YAMLerror.log
iserror=`tail $project.zUMIs_YAMLerror.log -n1 | awk '{print $2}'`
iserror=$(tail ${project}.zUMIs_YAMLerror.log -n1 | awk '{print $2}')


if [[ $iserror -eq 1 ]] ; then
if [[ ${iserror} -eq 1 ]] ; then
    echo "YAML file has an error. Look at the zUMIs_YAMLerror.log or contact developers."
    echo "YAML file has an error. Look at the zUMIs_YAMLerror.log or contact developers."
    exit 1
    exit 1
fi
fi




echo -e "\n\n You provided these parameters:
echo -e "\n\n You provided these parameters:
 YAML file:	$yaml
 YAML file:	${yaml_orig}
 zUMIs directory:		$zumisdir
 zUMIs directory:		${zumisdir}
 STAR executable		$starexc
 STAR executable		${starexc}
 samtools executable		$samtoolsexc
 samtools executable		${samtoolsexc}
 pigz executable		$pigzexc
 pigz executable		${pigzexc}
 Rscript executable		$Rexc
 Rscript executable		${Rexc}
 RAM limit:   $mem_limit
 RAM limit:   ${mem_limit}
 zUMIs version $vers \n\n" | tee "$outdir/$project.zUMIs_runlog.txt"
 zUMIs version ${vers} \n\n" | tee "${outdir}/${project}.zUMIs_runlog.txt"
date
date


#check for executables
#check for executables
sam_exc_check=`which $samtoolsexc`
sam_exc_check=$(which ${samtoolsexc})
pigz_exc_check=`which $pigzexc`
pigz_exc_check=$(which ${pigzexc})
r_exc_check=`which $Rexc`
r_exc_check=$(which ${Rexc})
star_exc_check=`which $starexc`
star_exc_check=$(which ${starexc})


if [[ -z "$sam_exc_check" ]] ||
if [[ -z "${sam_exc_check}" ]] ||
   [[ -z "$pigz_exc_check" ]] ||
   [[ -z "${pigz_exc_check}" ]] ||
   [[ -z "$r_exc_check" ]] ||
   [[ -z "${r_exc_check}" ]] ||
   [[ -z "$star_exc_check" ]]
   [[ -z "${star_exc_check}" ]] ; then
 then
    echo "One or more of your executables were not found. Please check back."
    echo "One or more of your executables were not found. Please check back."
    exit 1
    exit 1
fi
fi


# Check if the STAR version used for mapping and the one in the provided STAR index are the same
# Check if the STAR version used for mapping and the one in the provided STAR index are the same
starver=`$starexc --version | sed 's/STAR_//g' | sed 's/\s+//g'`
starver=$(${starexc} --version | sed 's/STAR_//g' | sed 's/\s+//g')
staridxver=`grep "versionGenome" $staridxdir/genomeParameters.txt | awk '{print $2}' | sed 's/\s+//g'`
staridxver=$(grep "versionGenome" ${staridxdir}/genomeParameters.txt | awk '{print $2}' | sed 's/\s+//g')


if [[ "$starver" != "$staridxver" ]]; then
if [[ "${starver}" != "${staridxver}" ]] ; then
  echo "WARNING: The STAR version used for mapping is $starver and the STAR index was created using the version $staridxver. This may lead to an error while mapping. If you encounter any errors at the mapping stage, please make sure to create the STAR index using STAR $starver."
  echo "WARNING: The STAR version used for mapping is ${starver} and the STAR index was created using the version ${staridxver}. This may lead to an error while mapping. If you encounter any errors at the mapping stage, please make sure to create the STAR index using STAR ${starver}."
  #exit 1
  #exit 1
fi
fi


#create output folders
#create output folders
outdir=`grep 'out_dir' $yaml | awk '{print $2}'`
outdir=$(grep 'out_dir' ${yaml} | awk '{print $2}')
#[ -d $outdir ] || mkdir $outdir
#[ -d ${outdir} ] || mkdir ${outdir}
[ -d $outdir/zUMIs_output/ ] || mkdir -p $outdir/zUMIs_output/
[ -d ${outdir}/zUMIs_output/ ] || mkdir -p ${outdir}/zUMIs_output/
[ -d $outdir/zUMIs_output/expression ] || mkdir -p $outdir/zUMIs_output/expression
[ -d ${outdir}/zUMIs_output/expression ] || mkdir -p ${outdir}/zUMIs_output/expression
[ -d $outdir/zUMIs_output/stats ] || mkdir -p $outdir/zUMIs_output/stats
[ -d ${outdir}/zUMIs_output/stats ] || mkdir -p ${outdir}/zUMIs_output/stats
[ -d $outdir/zUMIs_output/.tmpMerge ] || mkdir -p $outdir/zUMIs_output/.tmpMerge
[ -d ${outdir}/zUMIs_output/.tmpMerge ] || mkdir -p ${outdir}/zUMIs_output/.tmpMerge


if [[ ! -d $outdir ]]; then
if [[ ! -d ${outdir} ]] ; then
  mkdir -p $outdir
  mkdir -p ${outdir}
  if [ $? -ne 0 ] ; then
  if [ $? -ne 0 ] ; then
      echo "Please provide a valide output directory path."
      echo "Please provide a valide output directory path."
      exit 1
      exit 1
  fi
  fi
fi
fi


if
if [[ "${whichStage}" == "Filtering" ]] ; then
[[ "$whichStage" == "Filtering" ]]
then
  echo "Filtering..."
  echo "Filtering..."


  f=`cut -d' ' -f1 <(echo $fqfiles)` # the first fastq file to determine gzip status
  f=$(cut -d' ' -f1 <(echo ${fqfiles})) # the first fastq file to determine gzip status
  fullsize=`stat -L --printf="%s" $f`
  fullsize=$(stat -L --printf="%s" ${f})


  tmpMerge=$outdir/zUMIs_output/.tmpMerge/
  tmpMerge=${outdir}/zUMIs_output/.tmpMerge/


    if [[ $f =~ \.gz$ ]]; then
  if [[ ${f} =~ \.gz$ ]] ; then
      $pigzexc -dc $f | head -n 4000000 | $pigzexc > $tmpMerge/$project.1mio.check.fq.gz
      ${pigzexc} -dc ${f} | head -n 4000000 | ${pigzexc} > ${tmpMerge}/${project}.1mio.check.fq.gz
      smallsize=`stat --printf="%s" $tmpMerge/$project.1mio.check.fq.gz`
      smallsize=$(stat --printf="%s" ${tmpMerge}/${project}.1mio.check.fq.gz)
      rm $tmpMerge/$project.1mio.check.fq.gz
      rm ${tmpMerge}/${project}.1mio.check.fq.gz
      nreads=`expr $fullsize \* 1000000 / $smallsize`
      nreads=$(expr ${fullsize} \* 1000000 / ${smallsize})


      for i in $fqfiles;do bash $zumisdir/splitfq.sh $i $pigzexc $num_threads $tmpMerge splitfqgz $project $nreads & done
      for i in ${fqfiles} ; do bash ${zumisdir}/splitfq.sh ${i} ${pigzexc} ${num_threads} ${tmpMerge} splitfqgz ${project} ${nreads} & done
      wait
      wait
      pref=`basename $f .gz`
      pref=$(basename ${f} .gz)
      l=`ls $tmpMerge$pref* | sed "s|$tmpMerge$pref||" | sed 's/.gz//'`
      l=$(ls ${tmpMerge}${pref}* | sed "s|${tmpMerge}${pref}||" | sed 's/.gz//')
  else
  else
      cat $f | head -n 4000000 > $tmpMerge/$project.1mio.check.fq
      cat ${f} | head -n 4000000 > ${tmpMerge}/${project}.1mio.check.fq
      smallsize=`stat --printf="%s" $tmpMerge/$project.1mio.check.fq`
      smallsize=$(stat --printf="%s" ${tmpMerge}/${project}.1mio.check.fq)
      rm $tmpMerge/$project.1mio.check.fq
      rm ${tmpMerge}/${project}.1mio.check.fq
      nreads=`expr $fullsize \* 1000000 / $smallsize`
      nreads=$(expr ${fullsize} \* 1000000 / ${smallsize})


      for i in $fqfiles;do bash $zumisdir/splitfq.sh $i $pigzexc $num_threads $tmpMerge splitfq $project $nreads & done
      for i in ${fqfiles} ; do bash ${zumisdir}/splitfq.sh ${i} ${pigzexc} ${num_threads} ${tmpMerge} splitfq ${project} ${nreads} & done
      wait
      wait
      pref=`basename $f`
      pref=$(basename ${f})
      l=`ls $tmpMerge$pref* | sed "s|$tmpMerge$pref||"`
      l=$(ls ${tmpMerge}${pref}* | sed "s|${tmpMerge}${pref}||")
  fi
  fi


    for x in $l; do perl $zumisdir/fqfilter_v2.pl $yaml $samtoolsexc $Rexc $pigzexc $zumisdir $x & done
  for x in ${l} ; do perl ${zumisdir}/fqfilter_v2.pl ${yaml} ${samtoolsexc} ${Rexc} ${pigzexc} ${zumisdir} ${x} & done
  wait
  wait
    bash $zumisdir/mergeBAM.sh $zumisdir $tmpMerge $num_threads $project $outdir $yaml $samtoolsexc
  bash ${zumisdir}/mergeBAM.sh ${zumisdir} ${tmpMerge} ${num_threads} ${project} ${outdir} ${yaml} ${samtoolsexc}
    for i in $fqfiles; do
  for i in ${fqfiles} ; do
      pref=`basename $i | sed 's/.fastq.gz//' | sed 's/.fq.gz//'`
      pref=$(basename ${i} | sed 's/.fastq.gz//' | sed 's/.fq.gz//')
      rm $tmpMerge$pref*gz
      rm ${tmpMerge}${pref}*gz
  done
  done
  date
  date


  #run barcode detection
  #run barcode detection
    $Rexc $zumisdir/zUMIs-BCdetection.R $yaml
  ${Rexc} ${zumisdir}/zUMIs-BCdetection.R ${yaml}


  #check if BC correction should be performed!
  #check if BC correction should be performed!
    BCbinTable=$outdir/zUMIs_output/"$project".BCbinning.txt
  BCbinTable=${outdir}/zUMIs_output/"${project}".BCbinning.txt
    if [[ -f "$BCbinTable" ]]; then
  if [[ -f "${BCbinTable}" ]] ; then
      for x in $l; do
      for x in ${l} ; do
        rawbam="$tmpMerge/$project.$x.raw.tagged.bam"
        rawbam="${tmpMerge}/${project}.${x}.raw.tagged.bam"
        fixedbam="$tmpMerge/$project.$x.filtered.tagged.bam"
        fixedbam="${tmpMerge}/${project}.${x}.filtered.tagged.bam"
        mv $fixedbam $rawbam
        mv ${fixedbam} ${rawbam}
        perl $zumisdir/correct_BCtag.pl $rawbam $fixedbam $BCbinTable $samtoolsexc &
        perl ${zumisdir}/correct_BCtag.pl ${rawbam} ${fixedbam} ${BCbinTable} ${samtoolsexc} &
      done
      done
      wait
      wait
  fi
  fi
@@ -281,44 +284,40 @@ then
fi
fi


if
if
[[ "$whichStage" == "Filtering" ]] ||
[[ "${whichStage}" == "Filtering" ]] ||
[[ "$whichStage" == "Mapping" ]]
[[ "${whichStage}" == "Mapping" ]] ; then
then
  echo "Mapping..."
  echo "Mapping..."
    $Rexc $zumisdir/zUMIs-mapping.R $yaml
    ${Rexc} ${zumisdir}/zUMIs-mapping.R ${yaml}
  date
  date
fi
fi


if
if
[[ "$whichStage" == "Filtering" ]] ||
[[ "${whichStage}" == "Filtering" ]] ||
[[ "$whichStage" == "Mapping" ]] ||
[[ "${whichStage}" == "Mapping" ]] ||
[[ "$whichStage" == "Counting" ]]
[[ "${whichStage}" == "Counting" ]] ; then
then
  echo "Counting..."
  echo "Counting..."
  $Rexc $zumisdir/zUMIs-dge2.R $yaml
  ${Rexc} ${zumisdir}/zUMIs-dge2.R ${yaml}
  date
  date
  $Rexc $zumisdir/misc/rds2loom.R $yaml
  ${Rexc} ${zumisdir}/misc/rds2loom.R ${yaml}
  date
  date
  if [[ "$velo" == "yes" ]]; then
  if [[ "${velo}" == "yes" ]] ; then
    $Rexc $zumisdir/runVelocyto.R $yaml
    ${Rexc} ${zumisdir}/runVelocyto.R ${yaml}
  fi
  fi
fi
fi


if
if
[[ "$whichStage" == "Filtering" ]] ||
[[ "${whichStage}" == "Filtering" ]] ||
[[ "$whichStage" == "Mapping" ]] ||
[[ "${whichStage}" == "Mapping" ]] ||
[[ "$whichStage" == "Counting" ]] ||
[[ "${whichStage}" == "Counting" ]] ||
[[ "$whichStage" == "Summarising" ]]
[[ "${whichStage}" == "Summarising" ]] ; then
then
  if [[ "${isstats}" == "yes" ]] ; then
  if [[ "$isstats" == "yes" ]]; then
    echo "Descriptive statistics..."
    echo "Descriptive statistics..."
      $Rexc $zumisdir/zUMIs-stats2.R $yaml
      ${Rexc} ${zumisdir}/zUMIs-stats2.R ${yaml}
  fi
  fi
  date
  date
fi
fi



#close conda enviroment if necessary
#close conda enviroment if necessary
if [[ $conda = true ]]; then
if [[ ${conda} = true ]] ; then
  source $zumisenv/bin/deactivate
  source ${zumisenv}/bin/deactivate
fi
fi