annotate imgt_concatenate.sh @ 0:d3cf09f5a1a6 draft

Uploaded
author davidvanzessen
date Mon, 29 Aug 2016 05:46:28 -0400
parents
children b360a373835f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
1 #!/bin/bash
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
2 dir="$(cd "$(dirname "$0")" && pwd)"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
3
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
4 args=("$@")
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
5 output=$1
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
6 inputs=("${args[@]:1}")
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
7
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
8 workdir="$PWD"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
9
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
10 echo "Output: $output"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
11 echo "Inputs: ${inputs[@]}"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
12
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
13 mkdir "$workdir/output"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
14
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
15 function imgt_unpack {
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
16 local imgt_zip=$1
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
17 local outdir=$2
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
18 if [ ! -d "$outdir" ]; then
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
19 mkdir "$outdir"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
20 fi
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
21 local type="`file $imgt_zip`"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
22 if [[ "$type" == *"Zip archive"* ]] ; then
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
23 unzip $imgt_zip -d $outdir
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
24 elif [[ "$type" == *"XZ compressed data"* ]] ; then
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
25 mkdir -p $outdir
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
26 echo "tar -xJf $imgt_zip -C $outdir"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
27 tar -xJf $imgt_zip -C $outdir
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
28 fi
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
29 }
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
30
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
31 function concat_imgt_files {
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
32 indir=$1
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
33 outdir=$2
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
34 start_line=$3 #line # to start at, 2 to skip header
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
35 cat `find $indir/ -name "1_*"` | tail -n+${start_line} >> "$outdir/1_Summary.txt"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
36 cat `find $indir/ -name "2_*"` | tail -n+${start_line} >> "$outdir/2_IMGT-gapped-nt-sequences.txt"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
37 cat `find $indir/ -name "3_*"` | tail -n+${start_line} >> "$outdir/3_Nt-sequences.txt"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
38 cat `find $indir/ -name "4_*"` | tail -n+${start_line} >> "$outdir/4_IMGT-gapped-AA-sequences.txt"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
39 cat `find $indir/ -name "5_*"` | tail -n+${start_line} >> "$outdir/5_AA-sequences.txt"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
40 cat `find $indir/ -name "6_*"` | tail -n+${start_line} >> "$outdir/6_Junction.txt"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
41 cat `find $indir/ -name "7_*"` | tail -n+${start_line} >> "$outdir/7_V-REGION-mutation-and-AA-change-table.txt"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
42 cat `find $indir/ -name "8_*"` | tail -n+${start_line} >> "$outdir/8_V-REGION-nt-mutation-statistics.txt"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
43 cat `find $indir/ -name "9_*"` | tail -n+${start_line} >> "$outdir/9_V-REGION-AA-change-statistics.txt"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
44 cat `find $indir/ -name "10_*"` | tail -n+${start_line} >> "$outdir/10_V-REGION-mutation-hotspots.txt"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
45 }
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
46
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
47 echo "Unpacking IMGT file 1.."
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
48 imgt_unpack ${inputs[0]} "$workdir/input1"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
49
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
50 echo "Concatenating IMGT file 1..."
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
51 concat_imgt_files "$workdir/input1" "$workdir/output" 1
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
52
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
53 remaining_inputs=("${inputs[@]:1}")
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
54
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
55 i="2"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
56 for input in "${remaining_inputs[@]}"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
57 do
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
58 echo "Unpacking IMGT file $i.."
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
59 current_dir="$workdir/input${i}"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
60 imgt_unpack "${input}" "${current_dir}"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
61 echo "Concatenating IMGT file $1..."
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
62 concat_imgt_files "${current_dir}" "$workdir/output" 2
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
63 i=$((i+1))
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
64 done
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
65
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
66 echo "Creating new IMGT zip"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
67 cd "$workdir/output"
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
68 tar cfJ "$output" *
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
69
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
70 #awk to fix the sequence numbers repeating?
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
71
d3cf09f5a1a6 Uploaded
davidvanzessen
parents:
diff changeset
72 echo "Done"