1pub use getopts::Options;
2pub use std::fs::File;
3pub use std::io::prelude::*;
4pub use std::io::{BufReader, BufWriter};
5pub use std::path::Path;
6
7pub type Prob = f32;
8pub type Score = Prob;
9pub type Base = usize;
10pub type Basepair = (Base, Base);
11pub type Seq = Vec<Base>;
12
13pub type StackScores = [[[[Score; NUM_BASES]; NUM_BASES]; NUM_BASES]; NUM_BASES];
14pub type TerminalMismatchScores = StackScores;
15pub type BulgeScoresInit = [Score; MAX_2LOOP_LEN + 1];
16pub type HairpinScoresInit = [Score; MAX_HAIRPIN_LEN_EXTRAPOLATION + 1];
17pub type HairpinScoresSpecial = [(Seq, Score); NUM_SPECIAL_HAIRPINS];
18pub type InteriorScoresInit = [Score; MAX_2LOOP_LEN + 1];
19pub type InteriorScoresBonus = [[Score; NUM_BASES]; NUM_BASES];
20pub type InteriorScores1x1 =
21 [[[[[[Score; NUM_BASES]; NUM_BASES]; NUM_BASES]; NUM_BASES]; NUM_BASES]; NUM_BASES];
22pub type Interior1x2 = (Basepair, Base);
23pub type InteriorScores1x2 =
24 [[[[[[[Score; NUM_BASES]; NUM_BASES]; NUM_BASES]; NUM_BASES]; NUM_BASES]; NUM_BASES]; NUM_BASES];
25pub type Interior2x2 = (Basepair, Basepair);
26pub type InteriorScores2x2 = [[[[[[[[Score; NUM_BASES]; NUM_BASES]; NUM_BASES]; NUM_BASES];
27 NUM_BASES]; NUM_BASES]; NUM_BASES]; NUM_BASES];
28pub type DanglingScores = [[[Score; NUM_BASES]; NUM_BASES]; NUM_BASES];
29
30pub type BasepairScores = [[Score; NUM_BASES]; NUM_BASES];
32pub type HairpinScoresLen = [Score; MAX_LOOP_LEN + 1];
33pub type InteriorScoresExplicit = [[Score; MAX_INTERIOR_EXPLICIT]; MAX_INTERIOR_EXPLICIT];
34pub type BulgeScoresLen = [Score; MAX_LOOP_LEN];
35pub type InteriorScoresLen = [Score; MAX_LOOP_LEN - 1];
36pub type InteriorScoresSymmetric = [Score; MAX_INTERIOR_SYMMETRIC];
37pub type InteriorScoresAsymmetric = [Score; MAX_INTERIOR_ASYMMETRIC];
38pub type BulgeScores0x1 = [Score; NUM_BASES];
39pub type InteriorScores1x1Contra = [[Score; NUM_BASES]; NUM_BASES];
40pub type HelixCloseScores = [[Score; NUM_BASES]; NUM_BASES];
41
42type Arg = String;
43pub type Args = Vec<Arg>;
44pub type Char = u8;
45
46pub const NUM_TRANSITS: usize = 3;
47pub const INIT_MULTIBRANCH_BASE: Score = -INVERSE_TEMPERATURE * 9.3;
48pub const COEFF_NUM_BRANCHES: Score = -INVERSE_TEMPERATURE * (-0.9);
49pub const HELIX_AUGU_END_PENALTY: Score = -INVERSE_TEMPERATURE * 0.5;
50pub const NINIO_MAX: Score = -INVERSE_TEMPERATURE * 3.;
51pub const NINIO_COEFF: Score = -INVERSE_TEMPERATURE * 0.6;
52pub const GAS_CONST: Score = 1.98717 / KILO; pub const K0: Score = 273.15; pub const TEMPERATURE: Score = 37. + K0; pub const MAX_HAIRPIN_LEN_EXTRAPOLATION: usize = 1_000_000;
56pub const MAX_2LOOP_LEN: usize = 30;
57pub const KILO: Score = 1000.;
58pub const INVERSE_TEMPERATURE: Score = 1. / (GAS_CONST as Score * TEMPERATURE as Score); pub const A: Base = 0;
60pub const C: Base = 1;
61pub const G: Base = 2;
62pub const U: Base = 3;
63pub const NUM_BASES: usize = 4;
64pub const AA: Basepair = (A, A);
65pub const AC: Basepair = (A, C);
66pub const AG: Basepair = (A, G);
67pub const AU: Basepair = (A, U);
68pub const CA: Basepair = (C, A);
69pub const CC: Basepair = (C, C);
70pub const CG: Basepair = (C, G);
71pub const CU: Basepair = (C, U);
72pub const GA: Basepair = (G, A);
73pub const GC: Basepair = (G, C);
74pub const GG: Basepair = (G, G);
75pub const GU: Basepair = (G, U);
76pub const UA: Basepair = (U, A);
77pub const UC: Basepair = (U, C);
78pub const UG: Basepair = (U, G);
79pub const UU: Basepair = (U, U);
80pub const NEG_INF: Score = -1_000_000_000_000_000.;
81
82pub const NUM_SPECIAL_HAIRPINS: usize = 22;
83pub const MIN_HAIRPIN_LEN: usize = 3;
84pub const MIN_SPAN_HAIRPIN_CLOSE: usize = MIN_HAIRPIN_LEN + 2;
85pub const MIN_HAIRPIN_LEN_EXTRAPOLATION: usize = 10;
86pub const COEFF_HAIRPIN_LEN_EXTRAPOLATION: Score =
87 -INVERSE_TEMPERATURE * 1.75 * GAS_CONST * TEMPERATURE; lazy_static! {
89 pub static ref HAIRPIN_SCORES_SPECIAL: HairpinScoresSpecial = {
90 [
91 (vec![C, A, A, C, G], scale(6.8)),
92 (vec![G, U, U, A, C], scale(6.9)),
93 (vec![C, U, A, C, G, G], scale(2.8)),
94 (vec![C, U, C, C, G, G], scale(2.7)),
95 (vec![C, U, U, C, G, G], scale(3.7)),
96 (vec![C, U, U, U, G, G], scale(3.7)),
97 (vec![C, C, A, A, G, G], scale(3.3)),
98 (vec![C, C, C, A, G, G], scale(3.4)),
99 (vec![C, C, G, A, G, G], scale(3.5)),
100 (vec![C, C, U, A, G, G], scale(3.7)),
101 (vec![C, C, A, C, G, G], scale(3.7)),
102 (vec![C, C, G, C, G, G], scale(3.6)),
103 (vec![C, C, U, C, G, G], scale(2.5)),
104 (vec![C, U, A, A, G, G], scale(3.6)),
105 (vec![C, U, C, A, G, G], scale(3.7)),
106 (vec![C, U, U, A, G, G], scale(3.5)),
107 (vec![C, U, G, C, G, G], scale(2.8)),
108 (vec![C, A, A, C, G, G], scale(5.5)),
109 (vec![A, C, A, G, U, G, C, U], scale(2.9)),
110 (vec![A, C, A, G, U, G, A, U], scale(3.6)),
111 (vec![A, C, A, G, U, G, U, U], scale(1.8)),
112 (vec![A, C, A, G, U, A, C, U], scale(2.8)),
113 ]
114 };
115}
116
117pub const MAX_LOOP_LEN: usize = 30;
118pub const MAX_INTERIOR_EXPLICIT: usize = 4;
119pub const MAX_INTERIOR_SYMMETRIC: usize = MAX_LOOP_LEN / 2;
120pub const MAX_INTERIOR_ASYMMETRIC: usize = MAX_LOOP_LEN - 2;
121
122pub const A_LOWER: u8 = b'a';
123pub const A_UPPER: u8 = b'A';
124pub const C_LOWER: u8 = b'c';
125pub const C_UPPER: u8 = b'C';
126pub const G_LOWER: u8 = b'g';
127pub const G_UPPER: u8 = b'G';
128pub const U_LOWER: u8 = b'u';
129pub const U_UPPER: u8 = b'U';
130
131pub fn scale(x: Score) -> Score {
132 -INVERSE_TEMPERATURE * x
133}
134
135pub fn print_program_usage(program_name: &str, opts: &Options) {
136 let program_usage = format!("The usage of this program: {} [options]", program_name);
137 print!("{}", opts.usage(&program_usage));
138}
139
140pub fn char2base(x: Char) -> Base {
141 match x {
142 A_LOWER | A_UPPER => A,
143 C_LOWER | C_UPPER => C,
144 G_LOWER | G_UPPER => G,
145 U_LOWER | U_UPPER => U,
146 _ => {
147 panic!();
148 }
149 }
150}