Module: Ytilib
- Includes:
- REXML
- Defined in:
- lib/sequence_logo/ytilib/infocod.rb,
lib/sequence_logo/ytilib/pm.rb,
lib/sequence_logo/ytilib/pmsd.rb,
lib/sequence_logo/ytilib/ytilib.rb,
lib/sequence_logo/ytilib/ytilib.rb,
lib/sequence_logo/ytilib/bismark.rb,
lib/sequence_logo/ytilib/randoom.rb
Overview
class Integer
@@fact_hash = {}
def log_fact
return 0.0 if self == 0
return nil if self < 0
if self <= 170
@@fact_hash[self] = Math.log( lambda { |k| return k if self.times { |i| k *= i.next } }.call(1) )
else
return self.to_f.log_fact
end unless @@fact_hash.has_key?(self)
return @@fact_hash[self]
end
end
Defined Under Namespace
Modules: Randoom Classes: Bismark, PM, PPM
Constant Summary collapse
- STRAND_DIRECT =
"direct"- STRAND_REVCOMP =
"revcomp"
Class Method Summary collapse
- .mfa2array(input) ⇒ Object
- .new_mysql_conn(database) ⇒ Object
- .read_mfa2array(path) ⇒ Object
- .read_mfa2hash(path) ⇒ Object
- .read_plain2array(path) ⇒ Object
- .read_seqs2array(path) ⇒ Object
- .time ⇒ Object
- .write_mfa(seqs, path, prefix = " ") ⇒ Object
Instance Method Summary collapse
Class Method Details
.mfa2array(input) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 66 def Ytilib.mfa2array(input) seqs, seq_name = [], nil input.each_line { |line| if line[0,1] == ">" seq_name = line[1..-1].strip seqs << "" elsif seq_name != nil seqs.last << line.strip end } return seqs end |
.new_mysql_conn(database) ⇒ Object
137 138 139 140 141 |
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 137 def Ytilib.new_mysql_conn(database) my = Mysql.new(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, database) checkerr("cannot connect to MySQL server") { my.query("select 1").fetch_row[0] != "1" } return my end |
.read_mfa2array(path) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 50 def Ytilib.read_mfa2array(path) input_fasta_f = File.new(path, "r") seqs, seq_name = [], nil input_fasta_f.each_line { |line| if line[0,1] == ">" seq_name = line[1..-1].strip yield seq_name if block_given? seqs << "" elsif seq_name != nil seqs.last << line.strip end } input_fasta_f.close return seqs end |
.read_mfa2hash(path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 33 def Ytilib.read_mfa2hash(path) input_fasta_f = File.new(path, "r") seqs, seq_name = {}, nil input_fasta_f.each_line { |line| if line[0,1] == ">" seq_name = line[1..-1].strip seq_name = yield seq_name if block_given? checkerr("multiple sequences with the same name=#{seq_name}") { seqs[seq_name] } seqs[seq_name] = "" elsif seq_name != nil seqs[seq_name] << line.strip end } input_fasta_f.close return seqs end |
.read_plain2array(path) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 79 def Ytilib.read_plain2array(path) array = [] File.open(path).each_line { |line| array << line.strip if !line.strip.empty? } return array end |
.read_seqs2array(path) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 87 def Ytilib.read_seqs2array(path) type = File.ext_wo_name(path) case type when "mfa", "fasta", "fa" return Ytilib.read_mfa2array(path) when "plain","txt" return Ytilib.read_plain2array(path) else checkerr("unknown sequences-file, ext=#{type}") end end |
.time ⇒ Object
2 3 4 |
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 2 def Ytilib.time return Time.now.strftime('%d %b %H:%M:%S') end |
.write_mfa(seqs, path, prefix = " ") ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 99 def Ytilib.write_mfa(seqs, path, prefix = " ") if seqs.is_a?(Hash) out_fasta_f = File.new(path, "w+") seqs.each_key { |name| out_fasta_f << ">#{prefix}#{name}" << $/ << seqs[name] << $/ } out_fasta_f.close else out_fasta_f = File.new(path, "w+") seqs.each_with_index { |seq, i| out_fasta_f << ">#{prefix}#{i+1}" << $/ << seq << $/ } out_fasta_f.close end end |
Instance Method Details
#get_consensus(seqs) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 115 def get_consensus(seqs) report "consensus creating method should be checked, you are using unsafe code" return 'nil' if seqs.size == 0 conslet = { 'A' => 'A', 'C' => 'C', 'G' => 'G', 'T' => 'T', 'U' => 'U', 'AG' => 'R', 'CT' => 'Y', 'GT' => 'K', 'AC' => 'M', 'CG' => 'S', 'AT' => 'W', 'CGT' => 'B', 'AGT' => 'D', 'ACT' => 'H', 'ACG' => 'V', 'ACGT' => 'N' } new_consensus, letters = '', [] 0.upto(seqs[0].size-1) { |i| seqs.each do |word| letters << word[i] if !letters.include?(word[i]) end letters.sort! letters_string = '' letters.each do |letter| letters_string << letter end checkerr("cannot find consensus letter for a given letter set :#{}") { conslet[letters_string] == nil } new_consensus << conslet[letters_string] letters.clear } return new_consensus end |