-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsv2splitfaa.sh
More file actions
executable file
·36 lines (27 loc) · 875 Bytes
/
tsv2splitfaa.sh
File metadata and controls
executable file
·36 lines (27 loc) · 875 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
# BASH file manipulation
# splitting .tsv cluster output into separate fasta files
#usage: tsv2splitfastas.sh <input.tsv>
INPUT_TSV=$1
N=10
if [[ ! -d ./${INPUT_TSV}-splitfaa ]]; then
mkdir -p ./${INPUT_TSV}-splitfaa
echo "made output dir"
fi
echo "splitting fastas now..."
# split tsv into separate fasta files based on shared cluster name ($1)
awk -F'\t' '
NR>1{
gsub(/[^a-zA-Z0-9]/, "-", $1)
printf ">%s\n%s\n", $2,$NF > $1
}
}' ${INPUT_TSV}
echo "renaming fastas..."
# rename file with number of fastas in headers
for file in *.faa; do
COUNT=$(grep -c "^>" ${file})
perl-rename "s/^/${COUNT}-seqsincluster-/" ${file}
done
# keep the top N number of split fasta file clusters, and remove the rest
ls -la | grep .faa | awk '{print $NF}' | sort -gr | tail -n+$((${N} + 1)) | xargs rm
mv *.faa ./${INPUT_TSV}-splitfaa
echo "done"