-
Notifications
You must be signed in to change notification settings - Fork 7
/
3_export_intermediate.sh
129 lines (110 loc) · 3.61 KB
/
3_export_intermediate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
set -beEuo pipefail
SRCNAME=$(readlink -f $0)
SRCDIR=$(dirname ${SRCNAME})
PROGNAME=$(basename $SRCNAME)
VERSION="0.0.1"
NUM_POS_ARGS="1"
ml load snpnet_yt/dev
# ml load snpnet
############################################################
# functions
############################################################
show_default_helper () {
cat ${SRCNAME} | grep -n Default | tail -n+3 | awk -v FS=':' '{print $1}' | tr "\n" "\t"
}
show_default () {
cat ${SRCNAME} \
| tail -n+$(show_default_helper | awk -v FS='\t' '{print $1+1}') \
| head -n$(show_default_helper | awk -v FS='\t' '{print $2-$1-1}')
}
usage () {
cat <<- EOF
$PROGNAME (version $VERSION)
Export intermediate results from snpnet
Usage: $PROGNAME [options] results_dir
results_dir The output directory for the snpnet
Options:
--nCores (-t) Number of CPU cores
--memory (-m) The memory amount
Default configurations:
snpnet_dir=${snpnet_dir}
EOF
show_default | awk -v spacer=" " '{print spacer $0}'
}
############################################################
# tmp dir
############################################################
tmp_dir_root="$LOCAL_SCRATCH"
if [ ! -d ${tmp_dir_root} ] ; then mkdir -p $tmp_dir_root ; fi
tmp_dir="$(mktemp -p ${tmp_dir_root} -d tmp-$(basename $0)-$(date +%Y%m%d-%H%M%S)-XXXXXXXXXX)"
# echo "tmp_dir = $tmp_dir" >&2
handler_exit () { rm -rf $tmp_dir ; }
trap handler_exit EXIT
############################################################
# parser start
############################################################
## == Default parameters (start) == ##
nCores=4
memory=30000
genotype_pfile="@@@@@@@@@@@@@@@@@@@"
phenotype_name="_AUTO_"
## == Default parameters (end) == ##
declare -a params=()
for OPT in "$@" ; do
case "$OPT" in
'-h' | '--help' )
usage >&2 ; exit 0 ;
;;
'-v' | '--version' )
echo $VERSION ; exit 0 ;
;;
'-t' | '--nCores' )
nCores=$2 ; shift 2 ;
;;
'-m' | '--memory' )
memory=$2 ; shift 2 ;
;;
'--genotype_pfile' )
genotype_pfile=$2 ; shift 2 ;
;;
'--phenotype_name' )
phenotype_name=$2 ; shift 2 ;
;;
'--'|'-' )
shift 1 ; params+=( "$@" ) ; break
;;
-*)
echo "$PROGNAME: illegal option -- '$(echo $1 | sed 's/^-*//')'" 1>&2 ; exit 1
;;
*)
if [[ $# -gt 0 ]] && [[ ! "$1" =~ ^-+ ]]; then
params+=( "$1" ) ; shift 1
fi
;;
esac
done
if [ ${#params[@]} -lt ${NUM_POS_ARGS} ]; then
echo "${PROGNAME}: ${NUM_POS_ARGS} positional arguments are required" >&2
usage >&2 ; exit 1 ;
fi
results_dir="${params[0]}"
############################################################
source "${snpnet_dir}/helpers/snpnet_misc.sh"
############################################################
if [ "${phenotype_name}" == "_AUTO_" ] ; then
phenotype_name=$(basename ${results_dir})
fi
if [ ! -f "${results_dir}/snpnet.RData" ] ; then
prevIter="$(find_prevIter ${results_dir})"
RData_f="${results_dir}/results/output_iter_${prevIter}.RData"
if [ ! -f "${RData_f%.RData}.tsv" ] ; then
Rscript ${snpnet_dir}/helpers/export_betas.R ${RData_f} ${genotype_pfile}
fi
for ext in covars.tsv tsv ; do
if [ -f "${RData_f%.RData}.${ext}" ] ; then
ln -sf ${RData_f%.RData}.${ext} ${results_dir}/snpnet.${ext}
fi
done
plink_score ${results_dir} ${phenotype_name} ${genotype_pfile} ${nCores} ${memory}
fi