-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresfinder_batch.sh
77 lines (61 loc) · 2.11 KB
/
resfinder_batch.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# This script is used to run ResFinder for multiple E. coli strains (FASTA-files) at once
# Creates and output folder, also creates a subfolder for each strain to avoid overwriting of results
# VALIDATE INPUT
function usage(){
errorString="This script requires 2 parameters: 1. Full path to folder with input FASTA files. 2. Full path to output folder (will create if it doens't exist yet).";
echo -e ${errorString};
exit 1;
}
if [ "$#" -ne 2 ]; then
usage
fi
# 1. INPUT FOLDER CONTAINING .fasta files
inputFolder=$1;
# Remove trailing slash if this is last char
len=${#inputFolder};
lastPos=$(expr $len - 1);
lastChar=${inputFolder:$lastPos:1};
if [[ $lastChar == '/' ]]; then
inputFolder=${inputFolder:0:$lastPos};
fi
# 2. OUTPUT FOLDER
outputFolder=$2
# Check if the directory exists
if [ ! -d "$outputFolder" ]; then
# If it doesn't exist, create it
mkdir -p "$outputFolder"
echo "Output folder created."
else
echo "Output folder already exists."
fi
# 3. RUN RESFINDER FOR ALL E.COLI STRAINS
# Concatenate filenames
for i in $(ls ${inputFolder}/*.fasta); do
inputFile="${i}";
# Remove .fasta
posKeep=$(expr ${#i} - 6);
baseNameTmp=${i:0:$posKeep};
# Remove path to get strain number for output folder
baseName=${baseNameTmp/"$inputFolder"/""};
# Remove leading slash, if present
baseName="${baseName#/}";
# Make an output-subfolder for each strain to avoid overwriting
outputFolderStrain="${outputFolder}/${baseName}";
mkdir -p ${outputFolderStrain};
# Show inputfiles
echo "### Inputfile: $inputFile (basename: $baseName) ###";
echo "### Running ResFinder ###";
# Compose command
Command="python -m resfinder -ifa ${inputFile} -o ${outputFolderStrain} -b /usr/bin/blastn -s 'Escherichia coli' -db_res /home/guest/BIT11_Traineeship/Ecoli_AMR/ResFinder_2/resfinder_db -acq -c -db_point /home/guest/BIT11_Traineeship/Ecoli_AMR/ResFinder_2/pointfinder_db -u";
if [ "$4" = "y" ]; then
Command="$Command -x"
fi
#
# Show command
echo -e "$Command";
# Execute
output=$(eval $Command);
# Show output
echo -e "$output";
done