This repository has been archived by the owner on Dec 22, 2023. It is now read-only.
forked from LinearFold/LinearPartition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linearpartition
executable file
·88 lines (75 loc) · 4.67 KB
/
linearpartition
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
#!/usr/bin/env python2
import gflags as flags
import subprocess
import sys
import os
FLAGS = flags.FLAGS
def setgflags():
flags.DEFINE_integer('beamsize', 100, "set beam size", short_name='b')
flags.DEFINE_boolean('Vienna', False, "use vienna parameters", short_name='V')
flags.DEFINE_boolean('sharpturn', False, "enable sharp turn in prediction")
flags.DEFINE_boolean('verbose', False, "print out beamsize, Log Partition Coefficient (default mode) or free energy of ensumble (-V mode) and runtime information")
flags.DEFINE_string('output', '', "output base pairing probability matrix to a file with user specified name", short_name="o") # output mode
flags.DEFINE_string('prefix', '', "output base pairing probability matrices to file(s) with user specified prefix name") # prefix of file name
flags.DEFINE_boolean('part', False, "only do partition function calculation", short_name='p') # adding partition function mode
flags.DEFINE_string('rewrite', '', "output base pairing probability matrix to a file with user specified name (rewrite if the file exists)", short_name='r') # output (rewrite) mode
flags.DEFINE_float('cutoff', None, "only output base pair probability bigger than user specified threshold between 0 and 1", short_name='c') # bpp cutoff
flags.DEFINE_string("dumpforest", "", "dump forest (all nodes with inside [and outside] log partition functions but no hyperedges) for downstream tasks such as sampling and accessibility (DEFAULT=None)", short_name="f") # output (rewrite) mode
flags.DEFINE_boolean('mea', False, "get MEA structure", short_name='M')
flags.DEFINE_float('gamma', 3.0, "set MEA gamma", short_name='g')
flags.DEFINE_string('mea_prefix', '', "output MEA structure(s) to file(s) with user specified prefix name") # output (rewrite) mode
flags.DEFINE_boolean('bpseq', False, "output MEA structure(s) in bpseq format instead of dot-bracket format") # output (rewrite) mode
flags.DEFINE_boolean('threshknot', False, "get ThreshKnot structure", short_name='T')
flags.DEFINE_float('threshold', 0.3, "set ThreshKnot threshold")
flags.DEFINE_string('threshknot_prefix', '', "output ThreshKnot structure(s) to file(s) in bpseq format with user specified prefix name") # prefix of file name
flags.DEFINE_string('shape', '', "import SHAPE data for SHAPE guided LinearPartition (DEFAULT: not use SHAPE data)") # SHAPE
flags.DEFINE_boolean('fasta', False, "input is in fasta format") # FASTA format
argv = FLAGS(sys.argv)
def main():
use_vienna = FLAGS.V
beamsize = str(FLAGS.b)
is_sharpturn = '1' if FLAGS.sharpturn else '0'
is_verbose = '1' if FLAGS.verbose else '0'
bpp_file = str(FLAGS.o)
bpp_prefix = str(FLAGS.prefix) + "_" if FLAGS.prefix else ''
pf_only = '1' if (FLAGS.p and not (FLAGS.mea or FLAGS.threshknot)) else '0'
bpp_cutoff = str(FLAGS.c)
forest_file = str(FLAGS.dumpforest)
mea = '1' if FLAGS.mea else '0'
gamma = str(FLAGS.g)
MEA_bpseq = '1' if FLAGS.bpseq else '0'
MEA_prefix = str(FLAGS.mea_prefix) + "_" if FLAGS.mea_prefix else ''
TK = '1' if FLAGS.threshknot else '0'
threshold = str(FLAGS.threshold)
ThreshKnot_prefix = str(FLAGS.threshknot_prefix) + "_" if FLAGS.threshknot_prefix else ''
shape_file_path = str(FLAGS.shape)
is_fasta = '1' if FLAGS.fasta else '0'
if FLAGS.p and (FLAGS.o or FLAGS.prefix):
print("\nWARNING: -p mode has no output for base pairing probability matrix!\n");
if FLAGS.o and FLAGS.r:
print("WARNING: choose either -o mode or -r mode!\n");
print("Exit!\n");
exit();
if (FLAGS.o or FLAGS.r) and FLAGS.prefix:
print("WARNING: choose either -o/-r mode or --prefix mode!\n");
print("Exit!\n");
exit();
if FLAGS.o:
if os.path.exists(bpp_file):
print("WARNING: this file name has already be taken. Choose another name or use -r mode.\n");
print("Exit!\n");
exit();
if FLAGS.r:
bpp_file = str(FLAGS.r)
if os.path.exists(bpp_file): os.remove(bpp_file)
if FLAGS.c:
if float(bpp_cutoff) < 0.0 or float(bpp_cutoff) > 1.0:
print("WARNING: base pair probability cutoff should be between 0.0 and 1.0\n");
print("Exit!\n");
exit();
path = os.path.dirname(os.path.abspath(__file__))
cmd = ["%s/%s" % (path, ('bin/linearpartition_v' if use_vienna else 'bin/linearpartition_c')), beamsize, is_sharpturn, is_verbose, bpp_file, bpp_prefix, pf_only, bpp_cutoff, forest_file, mea, gamma, TK, threshold, ThreshKnot_prefix, MEA_prefix, MEA_bpseq, shape_file_path, is_fasta]
subprocess.call(cmd, stdin=sys.stdin)
if __name__ == '__main__':
setgflags()
main()