-
Notifications
You must be signed in to change notification settings - Fork 0
/
splc.py
executable file
·42 lines (30 loc) · 954 Bytes
/
splc.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
#! /usr/bin/python3
import sys
import argparse
import signal
import tools
def main(args):
inputs = tools.io.read_fasta(sys.stdin)
inputs = (''.join(seq) for _, seq in inputs)
dna = next(inputs)
introns = list(inputs)
for intron in introns:
assert dna.count(intron) == 1
dna = dna.replace(intron, '')
codon_table = tools.dna.codon_table()
codons = tools.helpers.split_string(dna, 3)
codons = list(codons)
assert codon_table[codons[-1]] == 'Stop'
codons = codons[:-1]
protein = map(codon_table.get, codons)
print(''.join(protein))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='description',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
args = parser.parse_args()
try:
main(args)
except BrokenPipeError:
sys.exit(128 + signal.SIGPIPE)
except KeyboardInterrupt:
sys.exit(128 + signal.SIGINT)