-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardToSoftMask.py
41 lines (30 loc) · 1.32 KB
/
hardToSoftMask.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
import bioio
import argparse
import itertools
from bioio import logger
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--unmasked")
parser.add_argument("--hardmasked")
parser.add_argument("--softmasked")
options = parser.parse_args()
unmasked = open(options.unmasked, 'r')
hardmasked = open(options.hardmasked, 'r')
softmasked = open(options.softmasked, 'w')
for unmaskedInfo, hardmaskedInfo in itertools.izip(bioio.fastaRead(unmasked), bioio.fastaRead(hardmasked)):
unmaskedName, unmaskedSeq = unmaskedInfo
hardmaskedName, hardmaskedSeq = hardmaskedInfo
print("processing sequence: %s" % unmaskedName)
assert unmaskedName == hardmaskedName
softmaskedSeq = ''
for unmaskedBase, hardmaskedBase in zip(unmaskedSeq, hardmaskedSeq):
if unmaskedBase.upper() == hardmaskedBase.upper():
softmaskedBase = unmaskedBase.upper()
else:
if not hardmaskedBase.upper() == 'N':
print("Warning: encountered differing base: %s %s" % (unmaskedBase, hardmaskedBase))
softmaskedBase = unmaskedBase.lower()
softmaskedSeq += softmaskedBase
bioio.fastaWrite(softmasked, unmaskedName, softmaskedSeq)
if __name__ == "__main__":
main()