-
Notifications
You must be signed in to change notification settings - Fork 2
/
tigger.py
72 lines (51 loc) · 1.57 KB
/
tigger.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Tigger is an experiment in hybrid programming for phylogenetics. It implements
the TIGER algorithm.
Usage:
tigger [--debug] <alignment_file>
tigger --version
Options:
-h --help Show this screen.
--version Show version.
"""
__version__ = '1.0.2'
import logging
log = logging.getLogger("tigger.main")
logging.basicConfig(
format="%(levelname)-8s | %(asctime)s | %(message)s",
level=logging.INFO
)
from docopt import docopt
import sys
from tigger.alignment import Alignment, AlignmentError
from tigger._bounce import TigerDNA
from pathlib import Path
import numpy
def set_verbose():
logging.getLogger("").setLevel(logging.DEBUG)
# Enhance the format
fmt = logging.Formatter(
"%(levelname)-8s | %(asctime)s | %(name)-20s | %(message)s")
logging.getLogger("").handlers[0].setFormatter(fmt)
def main(arguments):
if arguments['--debug']:
set_verbose()
filepath = Path(arguments['<alignment_file>'])
try:
a = Alignment(filepath)
except AlignmentError:
return 0
log.info("Species count %s", a.species_count)
log.info("Alignment size %s", a.sequence_length)
log.info("Beginning analysis --- ")
t = TigerDNA()
t.build_bitsets(a)
rates = t.calc_rates()
output_path = str(filepath.with_suffix('.tigger'))
log.info("Finished analysis --- ")
log.info("Saving file %s", output_path)
numpy.savetxt(output_path, rates, fmt="%5f", delimiter='\n')
return 1
if __name__ == "__main__":
arguments = docopt(__doc__, version=__version__)
sys.exit(main(arguments))