-
Notifications
You must be signed in to change notification settings - Fork 2
/
remove_gaps.py
44 lines (32 loc) · 900 Bytes
/
remove_gaps.py
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
#!/usr/bin/env python
import argparse
from Bio import SeqIO
from Bio.Alphabet import IUPAC, Gapped
from Bio.Seq import Seq
import os
import re
# Remove all gaps from the sequences in a fasta file.
#
# Matt Gitzendanner
# University of Florida
#
# version: 1.0: Initial release, June 15, 2016
#
# Usage: python remove_gaps.py -i fasta_file.fa -o fasta_file_no_gaps.fa
parser = argparse.ArgumentParser()
parser.add_argument("-i", help="Input fasta file")
parser.add_argument("-o", help="Output fasta file with gaps removed")
args = parser.parse_args()
InFile = args.i
OutFile= args.o
try:
IN=open(InFile, 'r')
except:
print("Can't open infile for reading: %s" %(InFile))
try:
OUT=open(OutFile, 'w')
except:
print("Can't open outfile for writing: %s" %(OutFile))
for Record in SeqIO.parse(IN, "fasta"):
Record.seq=Seq.ungap(Record.seq, gap="-")
SeqIO.write(Record, OUT, "fasta")