-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbiosample_complete.sh
executable file
·63 lines (52 loc) · 1.57 KB
/
biosample_complete.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
#!/bin/bash
#
# Usage: ./biosample_complete.sh -f BIOSAMPLEIDFILE -n NGSQCFILE -b BCO_ID -s SCHEMA_VERSION
WORKING_DIR=biosample_$(date "+%Y%m%d_%H%M%S")
mkdir -p $WORKING_DIR
while getopts "f:n:b:s:d" opt; do
case $opt in
f | file)
sampleidfile=$OPTARG
;;
n | ngsqc_file )
ngsqcfile=$OPTARG
;;
b | bco_id )
bco_id=$OPTARG
;;
s | schema )
schema=$OPTARG
;;
d | debug )
debug=true
;;
esac
done
# Read sample id file into an array
IDLINES=($(cat $sampleidfile))
for biosample_id in ${IDLINES[@]}
do
echo "Retrieving biosample metadata for $biosample_id"
# Retrieve biosample metadata
esearch -db biosample -query $biosample_id | efetch -format xml > $WORKING_DIR/biosample_meta_$biosample_id.xml
# parse metadata
echo ...Parsing XML biosample metadata to create tsv
python3 ./sra_sample_parser.py -n $ngsqcfile -f $WORKING_DIR/biosample_meta_$biosample_id.xml -b $bco_id -s $schema > $WORKING_DIR/biosample_meta_$biosample_id.tsv
done
echo Biosample metadata files are located at $WORKING_DIR
TSVFILENAME=$WORKING_DIR/${WORKING_DIR}_meta_combined.tsv
echo Creating TSV file...
echo ...Adding header line
head -n 1 $WORKING_DIR/biosample_meta_${IDLINES[0]}.tsv > $TSVFILENAME
echo ...looping through data lines
for biosample_id in ${IDLINES[@]}
do
tail -n +2 $WORKING_DIR/biosample_meta_$biosample_id.tsv >> $TSVFILENAME
done
# Clean up if $debug is NOT set
if [ -z $debug ]
then
echo "Cleaning up..."
rm $WORKING_DIR/biosample_meta*
fi
echo Combined tsv file is located at $TSVFILENAME