File: prok-geneseek

package info (click to toggle)
python-biotools 1.2.12-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 348 kB
  • sloc: python: 2,373; sh: 21; makefile: 4
file content (102 lines) | stat: -rwxr-xr-x 2,920 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python3

# 1. predict
# 2. cluster
# 3. rename
# 4. snps

import biotools.analysis.run as pr
import biotools.analysis.cluster as cw
import biotools.analysis.renamer as mv
import biotools.analysis.variance as cs
import biotools.analysis.options as op
import biotools.analysis.loaddata as ld
import sys
import os


if __name__ == "__main__":
    op.parse(sys.argv[1:])
    if len(op.args) < 2:
        op.help()
        exit(0)

    direc = op.DIRECTORY
    plotter = op.PLOTTER
    database = op.args[0]
    names = op.args[1:]
    sep = os.sep

    predict = op.predicting
    cluster = op.clustering
    rename = op.renaming
    plot = op.plotting
    report = op.reporting
    calculate = op.calculating

    rename = rename and (cluster or not predict)
    calculate = calculate and (cluster or not predict)
    plot = plot and (calculate or not (predict or cluster))
    report = report and calculate

    if not (predict or cluster or rename or calculate or plot or report):
        print("I don't know what you want, I give up.")
        exit(0)

    if predict:
        names = pr.run(database, names)
        print("Homologous sequences written to " + direc + 'sequences' + sep)

    if cluster:
        names = cw.run(direc + 'clusters' + sep, names)
        print("Clustalw files written to " + direc + "clusters" + sep)

    if rename:
        names = mv.rename(direc + 'clusters' + sep, database, names)

    if plot and plotter.lower() != 'none':
        try:
            cv = __import__(plotter, globals(), locals(), ['plot'], -1)
        except ImportError:
            try:
                if not plotter.endswith('.py'):
                    plotter += '.py'
                open(plotter, 'r')
            except:
                plot = False
            else:
                p = plotter.rfind(sep)
                if p > -1:
                    sys.path.append(plotter[:p])
                plotter = plotter[p + len(sep):]

                try:
                    cv = __import__(plotter, globals(), locals(), ['plot'], -1)
                except ImportError:
                    plot = False

    if calculate:
        gen = cs.var(names)
    elif plot:
        gen = (ld.parse(s) for s in names)
    else:
        gen = []
    for entry in gen:
        plotdata = entry['plotdata']
        metadata = entry['metadata']
        if plot:
            try:
                cv.plot(plotdata, direc + 'plots' + sep,
                        filename=metadata['filename'])
            except Exception as e:
                print(metadata['filename'], e)
        if report:
            try:
                os.mkdir(direc + 'data' + sep)
            except:
                pass

            fh = open(direc + 'data' + sep + metadata['strain'] + '.py', 'w')
            fh.write('plotdata = ' + repr(plotdata) + '\n')
            fh.write('metadata = ' + repr(metadata) + '\n')
    print("Done")