Debian Codegraph @

scripts/convert_gz_2_bgz.sh

raw
1 #!/bin/bash
2
3 # Copyright [2015-2024] EMBL-European Bioinformatics Institute
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 script_name="convert_gz_2_bgz.sh"
18
19
20 if [ -z "$1" ]; then
21 echo "Usage: $script_name gzipped_file|directory_with_gz_files [bgzip_program]"
22 exit 1
23 fi
24
25
26 if [ -z "$2" ]; then
27 bgzip="bgzip"
28 else
29 bgzip=$(cd "$(dirname "$2")" && pwd)/$(basename "$2")
30 echo "Using user specified bgzip:$bgzip"
31 fi
32
33 #check for presence of programs as required
34 if !(hash gzip 2>/dev/null;) then
35 echo "$script_name: GZIP not found, exiting"
36 exit 1
37 fi
38
39 if !(hash $bgzip 2>/dev/null;) then
40 echo "$script_name: BGZIP not found, exiting"
41 exit 1
42 fi
43
44 #process
45 if [ -f "$1" ]; then
46 dir="${1%/*}"
47 file="${1##*/}"
48 filename="${1%.*}"
49 echo "Making bgzip file $filename from $file"
50 cd $dir
51 gzip -d $file
52 $bgzip $filename
53 cd -
54 elif [ -d "$1" ]; then
55 cd $1
56 find . -name "*.gz" -print0 | while read -d $'\0' file
57 do
58 echo $file
59 filename="${file%.*}"
60 gzip -d $file
61 $bgzip $filename
62 done
63 cd -
64 else
65 echo "$script_name: argument $1 not found"
66 exit 1
67 fi
68
69 exit $?
70
71
72
73