split_study.sh 2.22 KB
Newer Older
Venkat Malladi's avatar
Venkat Malladi committed
1
2
3
#!/bin/bash


Venkat Malladi's avatar
Venkat Malladi committed
4
script_name="split_study.sh"
Venkat Malladi's avatar
Venkat Malladi committed
5

Venkat Malladi's avatar
Venkat Malladi committed
6
7
8
9
10
#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
11
  echo "-e  --Email on failure"
Venkat Malladi's avatar
Venkat Malladi committed
12
  echo "-o  --Path to output directory"
Venkat Malladi's avatar
Venkat Malladi committed
13
  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
14
15
  exit 1
}
Venkat Malladi's avatar
Venkat Malladi committed
16

Venkat Malladi's avatar
Venkat Malladi committed
17
18
19
20
21
22
23
24
25
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
26
    while getopts :r:t:e:o:h opt
Venkat Malladi's avatar
Venkat Malladi committed
27
28
29
30
        do
            case $opt in
                r) rid=$OPTARG;;
                t) tag=$OPTARG;;
Venkat Malladi's avatar
Venkat Malladi committed
31
                e) email=$OPTARG;;
Venkat Malladi's avatar
Venkat Malladi committed
32
                o) out=$OPTARG;;
Venkat Malladi's avatar
Venkat Malladi committed
33
34
35
36
37
38
39
                h) usage;;
            esac
        done

    shift $(($OPTIND -1))

    # Check for mandatory options
Venkat Malladi's avatar
Venkat Malladi committed
40
    if [[ -z $rid ]] || [[ -z $tag ]] || [[ -z $email ]] || [[ -z $out ]]; then
Venkat Malladi's avatar
Venkat Malladi committed
41
42
43
44
45
46
        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

Venkat Malladi's avatar
Venkat Malladi committed
47
    # extract replicate RIDs
Venkat Malladi's avatar
Venkat Malladi committed
48

Venkat Malladi's avatar
Venkat Malladi committed
49
    python3 ./scripts/split_study.py -s $rid
Venkat Malladi's avatar
Venkat Malladi committed
50

Venkat Malladi's avatar
Venkat Malladi committed
51
52
    # cleanup study RID files
    rm $rid\_studyRID.json
Venkat Malladi's avatar
Venkat Malladi committed
53

Venkat Malladi's avatar
Venkat Malladi committed
54
55
56
57
    # make dir for study
    mkdir $out/$rid
    mv $rid\_studyRID.csv $out/$rid
    cd $out/$rid
Venkat Malladi's avatar
Venkat Malladi committed
58

Venkat Malladi's avatar
Venkat Malladi committed
59
60
    # download version of RNA-seq pipelne
    existed_in_remote=$( git ls-remote --tags git@git.biohpc.swmed.edu:gudmap_rbk/rna-seq.git ${tag})
Venkat Malladi's avatar
Venkat Malladi committed
61

Venkat Malladi's avatar
Venkat Malladi committed
62
63
64
65
66
67
68
    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
Venkat Malladi's avatar
Venkat Malladi committed
69

Venkat Malladi's avatar
Venkat Malladi committed
70
71
    # run pipeline on replicate RIDs in parallel
    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
72
73
74
75

}

main "$@"