-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontigs-ids-length.sh
33 lines (29 loc) · 978 Bytes
/
contigs-ids-length.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
#!/bin/bash
# Raymond Kiu [email protected]
# one-line script to generate length for each contig in a multi-fasta sequence file
usage () {
echo ""
echo "This bash script generates sequence length for each contig in a multifasta file with contig ids"
echo ""
echo "Usage: $0 [options] multifasta.file"
echo "Options:"
echo " -h print usage and exit"
echo " -a print author and exit"
echo " -v print version and exit"
echo ""
}
version () { echo "version 0.1";}
author () { echo "Author: Raymond Kiu [email protected]";}
while getopts ':o:hav' opt;
do
case $opt in
h) usage; exit;;
a) author; exit;;
v) version; exit;;
\?) echo "Invalid option: -$OPTARG" >&2; exit 1;;
:) echo "Missing option argument for -$OPTARG" >&2; exit 1;;
*) echo "Unimplemented option: -$OPTARG" >&2; exit 1;;
esac
done
fasta=$1
awk '$0 ~ ">" {print c; c=0;printf substr($0,2,100) "\t"; } $0 !~ ">" {c+=length($0);} END { print c; }' $fasta