aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/my_pylmm/pyLMM/gn2.py
blob: 4702c670418f6888672121f44d9e448f33f26f15 (plain)
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
# Genenetwork2 specific methods and callback handler
#
# Copyright (C) 2015  Pjotr Prins (pjotr.prins@thebird.nl)
#

from __future__ import absolute_import, print_function, division

import numpy as np
import sys
import logging

# logging.basicConfig(level=logging.DEBUG)
# np.set_printoptions()

def progress(location, count, total):
    """
    Progress update
    """
    logging.info("Progress: %s %d%%" % (location,round(count*100.0/total)))

def mprint(msg,data):
    """
    Array/matrix print function
    """
    m = np.array(data)
    print(msg,m.shape,"=\n",m)

def callbacks():
    return dict(
        write = sys.stdout.write,
        writeln = print,
        debug = logging.debug,
        info = logging.info,
        warning = logging.warning,
        error = logging.error,
        critical = logging.critical,
        progress = progress,
        mprint = mprint
    )
    
# ----- Minor test cases:

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    logging.debug("Test %i" % (1))
    d = callbacks()['debug']
    d("TEST")
    wrln = callbacks()['writeln']
    wrln("Hello %i" % 34)
    progress = callbacks()['progress']
    progress("I am half way",50,100)