-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboltzfaa_chunker.sh
More file actions
executable file
·63 lines (54 loc) · 1.42 KB
/
boltzfaa_chunker.sh
File metadata and controls
executable file
·63 lines (54 loc) · 1.42 KB
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
#!/usr/bin/bash
# WARN: multi-fasta file and a3m dir name have to share the same name
# take input fasta
input_file="$1"
# set path to MSAs generated by colabfold_search
PATHTOMSAS='./msas/nife_msas'
# Check if the input file is provided
if [ -z "$1" ]; then
echo "Error: must provide one argument"
echo "Usage: $(basename $0) [INPUT.fasta]"
exit 1
fi
# create output_dir
output_dir=${input_file%.*}
file_name=${output_dir##*/}
mkdir -p "${output_dir}"
# awk funciton to split fastas
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 ".fasta"
prev_seqname = seqname
}
{
print $0 >> outfile
}
' "${input_file}"
# rename the fasta headers for boltz input
for file in "${output_dir}"/*.fasta; do
name=${file##*/}
name=${name%%.*}
sed -i "/>/ s#^>.*#>A|protein|${PATHTOMSAS}/${name}.a3m#" "${file}"
done
# split the fasta files into chunks of 5000 between new dirs
chunksize=2500
file_count=0
for file in "${output_dir}"/*.fasta; do
chunk_dir=CHUNK$(printf %03d $((file_count / chunksize)))
dir="${output_dir}"/"${chunk_dir}"
mkdir -p "$dir"
mv "$file" "$dir"
((file_count++))
done
# mv *.faa ${output_dir}
# mv ${output_dir}/${input_file} .