|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +#' This script is used to run GENOSCORES on a single chromosome in a HPC |
| 4 | +#' environment with qsub |
| 5 | +## ============================================================================ |
| 6 | + |
| 7 | +## Read the path for the directory where the results are to be stored. Typically |
| 8 | +## it is on scratch space on HPC |
| 9 | +outputdir=$1 |
| 10 | + |
| 11 | +## Read the base name (with full path) of the input file (excluding ID). |
| 12 | +## Example: if files are called /home/user/cohort_chr<1-22>.bim|bed|fam, |
| 13 | +## set basename="/home/user/cohort_chr" |
| 14 | +basename=$2 |
| 15 | + |
| 16 | +## Read path to the GENOSCORES analysis R script. Here you can use |
| 17 | +## example.analysis.R |
| 18 | +## Example: gscript="/home/user/example.analysis.R" |
| 19 | +gscript=$3 |
| 20 | + |
| 21 | +echo "GENOSCORES analysis script: $gscript will be executed." |
| 22 | + |
| 23 | +## Read chromosome number from command line |
| 24 | +chr=$4 |
| 25 | + |
| 26 | +## Function to process one chromosome at a time. |
| 27 | +## If you target file has suffixes after chromosome ID, for example: |
| 28 | +## 'cohort_chr21_filtered', they need to be manually added to inputfile: |
| 29 | +## inputfile="${basename}/cohort_chr${chr}_filtered" |
| 30 | +processchrom() { |
| 31 | + inputfile="${basename}/${chr}" |
| 32 | + chromdir="${outputdir}/${chr}" |
| 33 | + |
| 34 | + if [[ ! -d "${chromdir}" ]]; then |
| 35 | + mkdir -p "${chromdir}" |
| 36 | + fi |
| 37 | + |
| 38 | + logfile="${chromdir}"/log.Rout |
| 39 | + |
| 40 | + echo "Processing chromosome: ${chr}" |
| 41 | + echo "Input file: ${inputfile}" |
| 42 | + echo "Saving results to: ${chromdir} ..." |
| 43 | + |
| 44 | + ## Run main GENOSCORES script with CLI options: |
| 45 | + ## chromdir: subdirectory in the output directory to store results from |
| 46 | + ## the analysis for the current chromosome. |
| 47 | + ## inputfile: PLINK file with the current chromosome. |
| 48 | + ## logfile: file to store the logs from GENOSCORES. |
| 49 | + Rscript --no-save --no-restore --verbose "$(realpath "${gscript}")" \ |
| 50 | + "${chromdir}" "${inputfile}" 2> "${logfile}" > /dev/null |
| 51 | + echo "Done." |
| 52 | +} |
| 53 | + |
| 54 | +processchrom |
| 55 | + |
| 56 | +echo "All analyses have been executed." |
0 commit comments