<commit_before>#!/usr/bin/env bash

#######################################################################
#######################################################################
## RNAseq based Myeloma Purity Calculator
##
## Copyright (c) 2021 Translational Genomics Research Institute
##
## This software may be modified and distributed under the terms
## of the MIT license.  See the LICENSE file for details.
##
## Major Contributors: <NAME>
## Minor Contributors:
#######################################################################
#######################################################################

# Set the build directory, this makes it more dynamic
# Capture the current script path to dynamically link to required graphing script
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
BUILD_DIR=`dirname ${SCRIPT_PATH}`
echo BUILD DIRECTORY = ${BUILD_DIR}
#BUILD_DIR=/home/jkeats/toolkit_jkeats/myelomaPurityChecker/

##############################
##
## Require applications, these must be in your $PATH at runtime
##
##############################


# Samtools is required (http://www.htslib.org/)
# Needed for idxstats step
#module load samtools/1.9

# Featurecounts is required (http://subread.sourceforge.net/)
# It is used because it is an extremely fast counting application
#module load subread/2.0.0
#FEATURECOUNTS=/home/jkeats/downloads/subread-1.4.6-source/bin/featureCounts

# Add R to your path at TGEN
#module load R/3.6.1-phoenix
# R and the ggplot2 package are required
# Tested with R version 3.1.1 (2014-07-10) -- "Sock it to Me"
# ggplot2 version 0.9.3.1
# These must be availalbe in your path
# To Test enter the following commands
# R			# Starts R
# library(ggplot2)	# Loads ggplot2 library
# q()			# Exits R

usage()
{
  # `cat << EOF` This means that cat should stop reading when EOF is detected
  cat << EOF

  Usage: $0 [ -bph options]
  -h      Display Help
  -b      Inpute RNAseq BAM file from STAR alignment
  -p      Prepare Resource Files (Yes/No)
  -g      Input GTF (only needed to prepare resource files)
  -l      List of Genes not expressed in B-cells (only needed to prepare resource files)
  -i      Immunoglobulin Loci in GTF format (only needed to prepare resource files)
  -d      Cleanup Temp files (Yes/No) - Set to "no" to debug

EOF
# EOF is found above and hence cat command stops reading. This is equivalent to echo but much neater when printing out.
  exit 2
}

while getopts 'b:p:g:l:i:d:?h' flag
do
    case ${flag} in
        b) bam=${OPTARG};;
        p) BUILD_FILES=${OPTARG};;
        g) GTF=${OPTARG};;
        l) NON_BCELL_CONTAMINATION_GENELIST=${OPTARG};;
        i) IG_LOCI_REGIONS=${OPTARG};;
        d) REMOVE_TEMP_FILES=${OPTARG};;
        h|?) usage;;
    esac
done

echo The bam name is: $bam
echo The prepare status is: $BUILD_FILES
echo The GTF is: $GTF
echo The non B-cell Gene list is: $NON_BCELL_CONTAMINATION_GENELIST
echo The Immunoglobulin loci file is: $IG_LOCI_REGIONS
echo The File Cleanup setting is: $REMOVE_TEMP_FILES

##############################
##
## Required Variables
##
##############################


# Table for verbose tabulated results
RESULTS_TABLE=purityChecker.txt



# Set the path to the immunoglobulin loci GTF for the respective genome version
#IG_LOCI_REGIONS=${BUILD_DIR}Immunoglobulin_GRCh37_Loci.gtf
#IG_LOCI_REGIONS=${BUILD_DIR}Immunoglobulin_GRCh38_Loci.gtf

# The geometric mean is calculated from the RPKM of the non-B cell contamination genes
CALCULATE_GEOMEAN_R=${BUILD_DIR}calculate_geomean.R

# Two graphs will be automatically generated, this code is provided but the path needs to be updated
IGH_GRAPH_R=${BUILD_DIR}igh_graph.R

# This is only used in the first run to build all the needed files
#GTF=/home/tgenref/pecan/ensembl_v74/Homo_sapiens.GRCh37.74.gtf.hs37d5.EGFRvIII.gtf

#NON_BCELL_CONTAMINATION_GENELIST=${BUILD_DIR}Non_Bcell_Contamination_GeneList_e98.txt

# These are created in the first run using the code provided below
IGH_CONSTANT_GENES=${BUILD_DIR}IgH_Constant_Genes.txt
IGH_VARIABLE_GENES=${BUILD_DIR}IgH_Variable_Genes.txt
IGK_CONSTANT_GENES=${BUILD_DIR}IgK_Constant_Genes.txt
IGK_VARIABLE_GENES=${BUILD_DIR}IgK_Variable_Genes.txt
IGL_CONSTANT_GENES=${BUILD_DIR}IgL_Constant_Genes.txt
IGL_VARIABLE_GENES=${BUILD_DIR}IgL_Variable_Genes.txt
IG_GTF=${BUILD_DIR}Immunoglobulin_RegionsToCount.gtf

## CODE TO GENERATE NEEDED FILES FROM INPUT GTF FILE ##

#BUILD_FILES=No
#BUILD_FILES=Yes

if [ ${BUILD_FILES} == "Yes" ]
then
	echo
	echo<commit_msg>fixed builddir path adding "/"<commit_after>#!/usr/bin/env bash

#######################################################################
#######################################################################
## RNAseq based Myeloma Purity Calculator
##
## Copyright (c) 2021 Translational Genomics Research Institute
##
## This software may be modified and distributed under the terms
## of the MIT license.  See the LICENSE file for details.
##
## Major Contributors: <NAME>
## Minor Contributors:
#######################################################################
#######################################################################

# Set the build directory, this makes it more dynamic
# Capture the current script path to dynamically link to required graphing script
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
BUILD_DIR=`dirname ${SCRIPT_PATH}`
echo BUILD DIRECTORY = ${BUILD_DIR}
#BUILD_DIR=/home/jkeats/toolkit_jkeats/myelomaPurityChecker/

##############################
##
## Require applications, these must be in your $PATH at runtime
##
##############################


# Samtools is required (http://www.htslib.org/)
# Needed for idxstats step
#module load samtools/1.9

# Featurecounts is required (http://subread.sourceforge.net/)
# It is used because it is an extremely fast counting application
#module load subread/2.0.0
#FEATURECOUNTS=/home/jkeats/downloads/subread-1.4.6-source/bin/featureCounts

# Add R to your path at TGEN
#module load R/3.6.1-phoenix
# R and the ggplot2 package are required
# Tested with R version 3.1.1 (2014-07-10) -- "Sock it to Me"
# ggplot2 version 0.9.3.1
# These must be availalbe in your path
# To Test enter the following commands
# R			# Starts R
# library(ggplot2)	# Loads ggplot2 library
# q()			# Exits R

usage()
{
  # `cat << EOF` This means that cat should stop reading when EOF is detected
  cat << EOF

  Usage: $0 [ -bph options]
  -h      Display Help
  -b      Inpute RNAseq BAM file from STAR alignment
  -p      Prepare Resource Files (Yes/No)
  -g      Input GTF (only needed to prepare resource files)
  -l      List of Genes not expressed in B-cells (only needed to prepare resource files)
  -i      Immunoglobulin Loci in GTF format (only needed to prepare resource files)
  -d      Cleanup Temp files (Yes/No) - Set to "no" to debug

EOF
# EOF is found above and hence cat command stops reading. This is equivalent to echo but much neater when printing out.
  exit 2
}

while getopts 'b:p:g:l:i:d:?h' flag
do
    case ${flag} in
        b) bam=${OPTARG};;
        p) BUILD_FILES=${OPTARG};;
        g) GTF=${OPTARG};;
        l) NON_BCELL_CONTAMINATION_GENELIST=${OPTARG};;
        i) IG_LOCI_REGIONS=${OPTARG};;
        d) REMOVE_TEMP_FILES=${OPTARG};;
        h|?) usage;;
    esac
done

echo The bam name is: $bam
echo The prepare status is: $BUILD_FILES
echo The GTF is: $GTF
echo The non B-cell Gene list is: $NON_BCELL_CONTAMINATION_GENELIST
echo The Immunoglobulin loci file is: $IG_LOCI_REGIONS
echo The File Cleanup setting is: $REMOVE_TEMP_FILES

##############################
##
## Required Variables
##
##############################


# Table for verbose tabulated results
RESULTS_TABLE=purityChecker.txt



# Set the path to the immunoglobulin loci GTF for the respective genome version
#IG_LOCI_REGIONS=${BUILD_DIR}/Immunoglobulin_GRCh37_Loci.gtf
#IG_LOCI_REGIONS=${BUILD_DIR}/Immunoglobulin_GRCh38_Loci.gtf

# The geometric mean is calculated from the RPKM of the non-B cell contamination genes
CALCULATE_GEOMEAN_R=${BUILD_DIR}/calculate_geomean.R

# Two graphs will be automatically generated, this code is provided but the path needs to be updated
IGH_GRAPH_R=${BUILD_DIR}/igh_graph.R

# This is only used in the first run to build all the needed files
#GTF=/home/tgenref/pecan/ensembl_v74/Homo_sapiens.GRCh37.74.gtf.hs37d5.EGFRvIII.gtf

#NON_BCELL_CONTAMINATION_GENELIST=${BUILD_DIR}/Non_Bcell_Contamination_GeneList_e98.txt

# These are created in the first run using the code provided below
IGH_CONSTANT_GENES=${BUILD_DIR}/IgH_Constant_Genes.txt
IGH_VARIABLE_GENES=${BUILD_DIR}/IgH_Variable_Genes.txt
IGK_CONSTANT_GENES=${BUILD_DIR}/IgK_Constant_Genes.txt
IGK_VARIABLE_GENES=${BUILD_DIR}/IgK_Variable_Genes.txt
IGL_CONSTANT_GENES=${BUILD_DIR}/IgL_Constant_Genes.txt
IGL_VARIABLE_GENES=${BUILD_DIR}/IgL_Variable_Genes.txt
IG_GTF=${BUILD_DIR}/Immunoglobulin_RegionsToCount.gtf

## CODE TO GENERATE NEEDED FILES FROM INPUT GTF FILE ##

#BUILD_FILES=No
#BUILD_FILES=Yes

if [ ${BUILD_FILES} == "Yes" ]
then
	echo
	echo
{'fraction_non_alphanumeric': 0.1759534014726893, 'fraction_numerical': 0.011649631827673371, 'mean_word_length': 5.026490066225166, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2012246', 'n_tokens_mistral': 3119, 'n_tokens_neox': 2906, 'n_words': 885}