-
Notifications
You must be signed in to change notification settings - Fork 5
/
rename_contigs.sh
57 lines (52 loc) · 1.14 KB
/
rename_contigs.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
#!/bin/bash
# Raymond Kiu [email protected]
usage () {
echo ""
echo "This bash script renames contigs in multi-fasta files"
echo ""
echo "Usage: $0 [options] multifasta.file PREFIX"
echo ""
echo "e.g. $0 abc.fasta ABC"
echo ""
echo ">ABC.1"
echo "ATGCATGC"
echo ">ABC.2"
echo "AGGCCTTT"
echo ">ABC.3"
echo "ACCGGGTT"
echo ""
echo "Options:"
echo " -h print usage and exit"
echo " -a print author and exit"
echo " -v print version and exit"
echo ""
}
version () { echo "version 1.0";}
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
name=$2
awk ' \
BEGIN { \
contigIdx = 1; \
} \
{ \
if ($0 ~ /^>/) { \
print ">'$name'."contigIdx; \
contigIdx++; \
} \
else { \
print $0; \
} \
}' $1
exit 0