|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +## HiC-Pro |
| 4 | +## Copyright (c) 2015 Institut Curie |
| 5 | +## Author(s): Guipeng Li, Nicolas Servant |
| 6 | + |
| 7 | +## This software is distributed without any guarantee under the terms of the BSD-3 licence. |
| 8 | +## See the LICENCE file for details |
| 9 | + |
| 10 | +## |
| 11 | +## Create SGE files |
| 12 | +## |
| 13 | + |
| 14 | +dir=$(dirname $0) |
| 15 | + |
| 16 | +usage() |
| 17 | +{ |
| 18 | + echo "usage: $0 -c CONFIG [-s STEP]" |
| 19 | +} |
| 20 | + |
| 21 | +MAKE_OPTS="" |
| 22 | + |
| 23 | +while [ $# -gt 0 ] |
| 24 | +do |
| 25 | + case "$1" in |
| 26 | + (-c) conf_file=$2; shift;; |
| 27 | + (-s) MAKE_OPTS=$2; shift;; |
| 28 | + (--) shift; break;; |
| 29 | + (-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;; |
| 30 | + (*) suffix=$1; break;; |
| 31 | + esac |
| 32 | + shift |
| 33 | +done |
| 34 | + |
| 35 | +if [ -z "$conf_file" ]; then usage; exit 1; fi |
| 36 | + |
| 37 | +CONF=$conf_file . $dir/hic.inc.sh |
| 38 | +unset FASTQFILE |
| 39 | + |
| 40 | +## Define input files |
| 41 | +if [[ $MAKE_OPTS == "" || $MAKE_OPTS == *"mapping"* ]] |
| 42 | +then |
| 43 | + inputfile=inputfiles_${JOB_NAME}.txt |
| 44 | + get_hic_files $RAW_DIR .fastq | grep $PAIR1_EXT | sed -e "s|$RAW_DIR||" -e "s|^/||" > $inputfile |
| 45 | + count=$(cat $inputfile | wc -l) |
| 46 | +elif [[ $MAKE_OPTS == *"proc_hic"* ]] |
| 47 | +then |
| 48 | + inputfile=inputfiles_${JOB_NAME}.txt |
| 49 | + get_hic_files $RAW_DIR .bam | grep $PAIR1_EXT | sed -e "s|$RAW_DIR||" -e "s|^/||" > $inputfile |
| 50 | + count=$(cat $inputfile | wc -l) |
| 51 | +fi |
| 52 | + |
| 53 | +## Paralelle Implementation |
| 54 | +if [[ $MAKE_OPTS == "" || $MAKE_OPTS == *"mapping"* || $MAKE_OPTS == *"proc_hic"* ]] |
| 55 | +then |
| 56 | + make_target="all_qsub" |
| 57 | + ## Remove per sample steps |
| 58 | + if [[ $MAKE_OPTS != "" ]]; then |
| 59 | + make_target=$(echo $MAKE_OPTS | sed -e 's/,/ /g'); |
| 60 | + make_target=$(echo $make_target | sed -e 's/merge_persample//g'); |
| 61 | + make_target=$(echo $make_target | sed -e 's/build_contact_maps//g'); |
| 62 | + make_target=$(echo $make_target | sed -e 's/ice_norm//g'); |
| 63 | + make_target=$(echo $make_target | sed -e 's/quality_checks//g'); |
| 64 | + fi |
| 65 | + |
| 66 | + ## step 1 - parallel |
| 67 | + sge_script=HiCPro_step1_${JOB_NAME}.sh |
| 68 | + PPN=$(( ${N_CPU} * 2)) |
| 69 | + cat > ${sge_script} <<EOF |
| 70 | +#!/bin/bash |
| 71 | +#$ -l h_vmem=${JOB_MEM} |
| 72 | +#$ -l h_rt=${JOB_WALLTIME} |
| 73 | +#$ -M ${JOB_MAIL} |
| 74 | +#$ -m ae |
| 75 | +#$ -j y |
| 76 | +#$ -N HiCpro_s1_${JOB_NAME} |
| 77 | +##$ -q ${JOB_QUEUE} |
| 78 | +#$ -V |
| 79 | +#$ -t 1-$count |
| 80 | +#$ -pe shm ${PPN} |
| 81 | +#$ -cwd |
| 82 | +
|
| 83 | +FASTQFILE=$inputfile; export FASTQFILE |
| 84 | +make --file ${SCRIPTS}/Makefile CONFIG_FILE=${conf_file} CONFIG_SYS=${INSTALL_PATH}/config-system.txt $make_target 2>&1 |
| 85 | +EOF |
| 86 | + |
| 87 | + chmod +x ${sge_script} |
| 88 | + |
| 89 | + ## User message |
| 90 | + echo "The following command will launch the parallel workflow through $count sge jobs:" |
| 91 | + echo qsub ${sge_script} |
| 92 | +fi |
| 93 | + |
| 94 | + |
| 95 | +## Per sample Implementation |
| 96 | +if [[ $MAKE_OPTS == "" || $MAKE_OPTS == *"build_contact_maps"* || $MAKE_OPTS == *"ice_norm"* || $MAKE_OPTS == *"quality_checks"* ]] |
| 97 | +then |
| 98 | + make_target="all_persample" |
| 99 | + ## Remove parallele mode |
| 100 | + if [[ $MAKE_OPTS != "" ]]; |
| 101 | + then |
| 102 | + make_target=$(echo $MAKE_OPTS | sed -e 's/,/ /g'); |
| 103 | + make_target=$(echo $make_target | sed -e 's/mapping//g'); |
| 104 | + make_target=$(echo $make_target | sed -e 's/proc_hic//g'); |
| 105 | + fi |
| 106 | + |
| 107 | + sge_script_s2=HiCPro_step2_${JOB_NAME}.sh |
| 108 | + cat > ${sge_script_s2} <<EOF |
| 109 | +#!/bin/bash |
| 110 | +#$ -l h_vmem=${JOB_MEM} |
| 111 | +#$ -l h_rt=${JOB_WALLTIME} |
| 112 | +#$ -M ${JOB_MAIL} |
| 113 | +#$ -m ae |
| 114 | +#$ -j y |
| 115 | +#$ -N HiCpro_s2_${JOB_SUFFIX} |
| 116 | +##$ -q ${JOB_QUEUE} |
| 117 | +#$ -V |
| 118 | +#$ -cwd |
| 119 | +
|
| 120 | +make --file ${SCRIPTS}/Makefile CONFIG_FILE=${conf_file} CONFIG_SYS=${INSTALL_PATH}/config-system.txt $make_target 2>&1 |
| 121 | +EOF |
| 122 | + |
| 123 | + chmod +x ${sge_script_s2} |
| 124 | + |
| 125 | + ## User message |
| 126 | + echo "The following command will merge the processed data and run the remaining steps per sample:" |
| 127 | + echo qsub ${sge_script_s2} |
| 128 | +fi |
| 129 | + |
0 commit comments