0
|
1 #!/bin/bash
|
|
2 dir="$(cd "$(dirname "$0")" && pwd)"
|
|
3
|
|
4 args=("$@")
|
|
5 output=$1
|
|
6 inputs=("${args[@]:1}")
|
|
7
|
|
8 workdir="$PWD"
|
|
9
|
|
10 echo "Output: $output"
|
|
11 echo "Inputs: ${inputs[@]}"
|
|
12
|
|
13 mkdir "$workdir/output"
|
|
14
|
|
15 function imgt_unpack {
|
|
16 local imgt_zip=$1
|
|
17 local outdir=$2
|
|
18 if [ ! -d "$outdir" ]; then
|
|
19 mkdir "$outdir"
|
|
20 fi
|
|
21 local type="`file $imgt_zip`"
|
|
22 if [[ "$type" == *"Zip archive"* ]] ; then
|
|
23 unzip $imgt_zip -d $outdir
|
|
24 elif [[ "$type" == *"XZ compressed data"* ]] ; then
|
|
25 mkdir -p $outdir
|
|
26 echo "tar -xJf $imgt_zip -C $outdir"
|
|
27 tar -xJf $imgt_zip -C $outdir
|
|
28 fi
|
|
29 }
|
|
30
|
|
31 function concat_imgt_files {
|
|
32 indir=$1
|
|
33 outdir=$2
|
|
34 start_line=$3 #line # to start at, 2 to skip header
|
1
|
35 id=$4
|
|
36 cat `find $indir/ -name "1_*"` | tail -n+${start_line} | awk -v id=$id '{ if($1 !~ /^header/) {$2=$2id; } print}' >> "$outdir/1_Summary.txt"
|
|
37 cat `find $indir/ -name "2_*"` | tail -n+${start_line} | awk -v id=$id '{ if($1 !~ /^header/) {$2=$2id; } print}' >> "$outdir/2_IMGT-gapped-nt-sequences.txt"
|
|
38 cat `find $indir/ -name "3_*"` | tail -n+${start_line} | awk -v id=$id '{ if($1 !~ /^header/) {$2=$2id; } print}' >> "$outdir/3_Nt-sequences.txt"
|
|
39 cat `find $indir/ -name "4_*"` | tail -n+${start_line} | awk -v id=$id '{ if($1 !~ /^header/) {$2=$2id; } print}' >> "$outdir/4_IMGT-gapped-AA-sequences.txt"
|
|
40 cat `find $indir/ -name "5_*"` | tail -n+${start_line} | awk -v id=$id '{ if($1 !~ /^header/) {$2=$2id; } print}' >> "$outdir/5_AA-sequences.txt"
|
|
41 cat `find $indir/ -name "6_*"` | tail -n+${start_line} | awk -v id=$id '{ if($1 !~ /^header/) {$2=$2id; } print}' >> "$outdir/6_Junction.txt"
|
|
42 cat `find $indir/ -name "7_*"` | tail -n+${start_line} | awk -v id=$id '{ if($1 !~ /^header/) {$2=$2id; } print}' >> "$outdir/7_V-REGION-mutation-and-AA-change-table.txt"
|
|
43 cat `find $indir/ -name "8_*"` | tail -n+${start_line} | awk -v id=$id '{ if($1 !~ /^header/) {$2=$2id; } print}' >> "$outdir/8_V-REGION-nt-mutation-statistics.txt"
|
|
44 cat `find $indir/ -name "9_*"` | tail -n+${start_line} | awk -v id=$id '{ if($1 !~ /^header/) {$2=$2id; } print}' >> "$outdir/9_V-REGION-AA-change-statistics.txt"
|
|
45 cat `find $indir/ -name "10_*"` | tail -n+${start_line} | awk -v id=$id '{ if($1 !~ /^header/) {$2=$2id; } print}' >> "$outdir/10_V-REGION-mutation-hotspots.txt"
|
0
|
46 }
|
|
47
|
|
48 echo "Unpacking IMGT file 1.."
|
|
49 imgt_unpack ${inputs[0]} "$workdir/input1"
|
|
50
|
|
51 echo "Concatenating IMGT file 1..."
|
1
|
52 id=${inputs[1]}
|
|
53 concat_imgt_files "$workdir/input1" "$workdir/output" 1 $id
|
0
|
54
|
1
|
55 remaining_inputs=("${inputs[@]:2}")
|
0
|
56
|
1
|
57 i="0"
|
|
58 while [ $i -lt ${#remaining_inputs[@]} ]; do
|
|
59 j=$((i+1))
|
|
60 input="${remaining_inputs[$i]}"
|
|
61 id="${remaining_inputs[$j]}"
|
|
62
|
|
63 echo "Unpacking IMGT file $j.."
|
0
|
64 current_dir="$workdir/input${i}"
|
|
65 imgt_unpack "${input}" "${current_dir}"
|
|
66 echo "Concatenating IMGT file $1..."
|
1
|
67 concat_imgt_files "${current_dir}" "$workdir/output" 2 $id
|
|
68 i=$((i+2))
|
0
|
69 done
|
|
70
|
1
|
71
|
0
|
72 echo "Creating new IMGT zip"
|
|
73 cd "$workdir/output"
|
|
74 tar cfJ "$output" *
|
|
75
|
|
76 #awk to fix the sequence numbers repeating?
|
|
77
|
|
78 echo "Done"
|
1
|
79
|
|
80 exit 0
|
|
81
|
|
82 i="1"
|
|
83 for input in "${remaining_inputs[@]}"
|
|
84 do
|
|
85 echo "Unpacking IMGT file $i.."
|
|
86 current_dir="$workdir/input${i}"
|
|
87 imgt_unpack "${input}" "${current_dir}"
|
|
88 echo "Concatenating IMGT file $1..."
|
|
89 concat_imgt_files "${current_dir}" "$workdir/output" 2 $id
|
|
90 i=$((i+1))
|
|
91 done
|
|
92
|