split_study.sh 2.26 KB
Newer Older
Venkat Malladi's avatar
Venkat Malladi committed
1
2
3
4
5
6
7
#!/bin/bash

#SBATCH -p super
#SBATCH --job-name GUDMAP-RBK_Study
#SBATCH -t 7-0:0:0


Venkat Malladi's avatar
Venkat Malladi committed
8
script_name="split_study.sh"
Venkat Malladi's avatar
Venkat Malladi committed
9

Venkat Malladi's avatar
Venkat Malladi committed
10
11
12
13
14
#Help function
usage() {
  echo "-h  --Help documentation for $script_name"
  echo "-r  --Study_RID."
  echo "-t  --Tag of pipelne"
Venkat Malladi's avatar
Venkat Malladi committed
15
  echo "-e  --Email on failure"
Venkat Malladi's avatar
Venkat Malladi committed
16
  echo "-o  --Path to output directory"
Venkat Malladi's avatar
Venkat Malladi committed
17
  echo "Example: $script_name -r 16-1ZP0 -t 0.1.0 -e 'first.last@utsouthwestern.edu' -o '/path/to/output/dir/'"
Venkat Malladi's avatar
Venkat Malladi committed
18
19
  exit 1
}
Venkat Malladi's avatar
Venkat Malladi committed
20

Venkat Malladi's avatar
Venkat Malladi committed
21
22
23
24
25
26
27
28
29
main(){

    # Load required modules
    module load python/3.6.4-anaconda
    module load nextflow/20.01.0
    module load singularity/3.5.3

    # Parsing options
    OPTIND=1 # Reset OPTIND
Venkat Malladi's avatar
Venkat Malladi committed
30
    while getopts :r:t:e:o:h opt
Venkat Malladi's avatar
Venkat Malladi committed
31
32
33
34
        do
            case $opt in
                r) rid=$OPTARG;;
                t) tag=$OPTARG;;
Venkat Malladi's avatar
Venkat Malladi committed
35
                e) email=$OPTARG;;
Venkat Malladi's avatar
Venkat Malladi committed
36
                o) out=$OPTARG;;
Venkat Malladi's avatar
Venkat Malladi committed
37
38
39
40
41
42
43
                h) usage;;
            esac
        done

    shift $(($OPTIND -1))

    # Check for mandatory options
Venkat Malladi's avatar
Venkat Malladi committed
44
    if [[ -z $rid ]] || [[ -z $tag ]] || [[ -z $email ]] || [[ -z $out ]]; then
Venkat Malladi's avatar
Venkat Malladi committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
        usage
    fi

    # query GUDMAP/RBK for study RID
    echo "curl --location --request GET 'https://www.gudmap.org/ermrest/catalog/2/entity/RNASeq:Replicate/Study_RID="${rid}"'" | bash > $rid\_studyRID.json

  # extract replicate RIDs

  python3 ./scripts/split_study.py -s $rid

  # cleanup study RID files
  rm $rid\_studyRID.json

  # make dir for study
Venkat Malladi's avatar
Venkat Malladi committed
59
60
61
  mkdir $out/$rid
  mv $rid\_studyRID.csv $out/$rid
  cd $out/$rid
Venkat Malladi's avatar
Venkat Malladi committed
62
63
64
65
66
67
68
69
70
71
72
73
74

  # download version of RNA-seq pipelne
  existed_in_remote=$( git ls-remote --tags git@git.biohpc.swmed.edu:gudmap_rbk/rna-seq.git ${tag})

  if [[ -z ${existed_in_remote} ]]; then
      echo "The tag ${tag} doesn't exist."
      exit 1
  fi

  git clone -b $tag --depth 1 git@git.biohpc.swmed.edu:gudmap_rbk/rna-seq.git
  cd rna-seq

  # run pipeline on replicate RIDs in parallel
Venkat Malladi's avatar
Venkat Malladi committed
75
  while read repRID; do echo ${repRID}; sleep 30; done < "../${rid}_studyRID.csv" | xargs -P 5 -I {} nextflow -q run workflow/rna-seq.nf --repRID {} --source production --deriva /project/BICF/BICF_Core/shared/gudmap/test_data/auth/credential.json --bdbag /project/BICF/BICF_Core/shared/gudmap/test_data/auth/cookies.txt --dev false --upload true --email ${email} -with-report ./output/{}_report.html -with-timeline ./output/{}_timeline.html
Venkat Malladi's avatar
Venkat Malladi committed
76
77
78
}

main "$@"