-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfasta_cleanner.py
50 lines (37 loc) · 1.58 KB
/
fasta_cleanner.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
45
46
47
48
49
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
###############################################################################
#### Goal: remove "-" from begining of lines in FASTA files
#### Usage: python fasta_cleaner.py /path/to/directory_wt_all_files/
#### Note: provide full path!
###############################################################################
import argparse
import fileinput
import os, sys
parser=argparse.ArgumentParser(
description='''Goal: remove "-" from begining of lines in FASTA files.''')
__file__ = "orf_annotation.py"
__author__ = 'Sandra Godinho Silva ([email protected])'
__version__ = '0.2'
__date__ = '05-12-2020'
parser.add_argument('inputDirectory',
help='Specify the directory containing *.fa files')
# Execute parse_args()
args = parser.parse_args()
inputDirectory = sys.argv[1]
###############################################################################
curdir = inputDirectory
os.chdir(curdir)
entries = os.listdir(curdir)
print("Starting...")
for filename in entries:
if ".fa" in filename:
filepath = os.path.join(curdir, filename)
with fileinput.FileInput(filepath, inplace=True) as file:
for line in file:
if line.strip().startswith("-"):
line = line.replace("-", "")
sys.stdout.write(line)
fileinput.close()
print("Removed '-' from the beginning of all lines that started with it.")
###############################################################################