-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosra_iterate.sh
61 lines (54 loc) · 1.71 KB
/
osra_iterate.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
#!/bin/bash
# This Bash script iterates through every file in an entire folder as input file (.TIF), with an associated output file (.MOL).
# $1 = Argument #1, the folder path for the input TIF files.
# $2 = Argument #2, the folder path for the output MOL files.
#
# Example command line usage:
# ./osra_iterate.sh ~/Share/input/ ~/Share/output/
if [ ! $# == 2 ]; then
echo "Usage: $0 input_folder output_folder"
exit
fi
echo "$1"
if [ ! -d "$1" ]; then
echo "Input folder does not exist. Exiting..."
exit
else
echo "Input folder exists."
fi
echo "$2"
if [ ! -d "$2" ]; then
echo "Output folder does not exist. Enter credentials to create it now:"
sudo mkdir "$2"
else
echo "Output folder exists."
fi
input_folder="$1"
if [ ${input_folder: -1} == "/" ]; then
# If last character is a slash, remove it to standardize.
input_folder="${input_folder:0:-1}"
fi
output_folder="$2"
if [ ${output_folder: -1} == "/" ]; then
# If last character is a slash, remove it to standardize.
output_folder="${output_folder:0:-1}"
fi
# For each file in the input folder
for file in "$input_folder"/*
do
# Check to make sure it's actually a file.
if [ -f $file ]; then
# Check to make sure it's a TIF file (and not some other file type)
if [ ${file: -4} == ".tif" ] || [ ${file: -4} == ".TIF" ]; then
# Remove the path info between and including the first and last forward slashes.
ifile="${file##/*/}"
# echo "Input file: $ifile"
# Take the input filename, remove last 3 characters (tif or TIF), then add "mol" for output filename
ofile="${ifile:0:-3}mol"
# echo "Output file: $ofile"
echo "$ifile -> $ofile"
# run the OSRA command
osra -w "$output_folder"/"$ofile" -f sdf -p "$input_folder"/"$ifile"
fi
fi
done