-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplitfaa_chai.sh
More file actions
executable file
·47 lines (39 loc) · 934 Bytes
/
splitfaa_chai.sh
File metadata and controls
executable file
·47 lines (39 loc) · 934 Bytes
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
#!/bin/bash
# Check if the input file is provided
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Error: must provide two arguments"
echo "Usage: $(basename $0) [INPUT.fasta] [OUTDIR_NAME]"
exit 1
fi
input_file="$1"
output_dir="$2"
if [[ ! -d $output_dir ]]; then
mkdir -p "${output_dir}"
fi
awk -v outdir="${output_dir}" '
BEGIN {
prev_seqname = ""
}
/^>/{
split($1, arr, ">")
seqname = arr[2]
gsub(/[\.\|]/, "_", seqname)
gsub(/[#%^\*\\+!={}?]/, "", seqname)
if (seqname != prev_seqname && outfile) {
close(outfile)
}
outfile = outdir "/" seqname ".faa"
prev_seqname = seqname
}
{
print $0 >> outfile
}
' "${input_file}"
# rename the fasta headers for chai input
for file in "${output_dir}"/*.faa; do
name=${file##*/}
name=${name%%.*}
sed -i "s#^>.*#>protein|${name}#" "${file}"
done
# mv *.faa ${output_dir}
# mv ${output_dir}/${input_file} .