Top Level Namespace
Defined Under Namespace
Modules: Magick, REXML, SequenceLogo, Ytilib
Classes: Array, File, Float, IUPAC, Integer, Object, PPM, String
Constant Summary
Constants included
from Ytilib
Ytilib::STRAND_DIRECT, Ytilib::STRAND_REVCOMP
Instance Method Summary
collapse
Methods included from Ytilib
#get_consensus, mfa2array, new_mysql_conn, read_mfa2array, read_mfa2hash, read_plain2array, read_seqs2array, time, write_mfa
Instance Method Details
#arglist_augmented_with_stdin(argv) ⇒ Object
19
20
21
22
23
|
# File 'lib/sequence_logo/exec/sequence_logo.rb', line 19
def arglist_augmented_with_stdin(argv)
result = argv
result += $stdin.read.shellsplit unless $stdin.tty?
result
end
|
#checkerr(message = "checkerr failed") ⇒ Object
21
22
23
24
25
26
|
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 21
def checkerr(message = "checkerr failed")
if !block_given? || yield
puts "LLIB #{Ytilib.time} [error]\t#{message}" unless $NO_REPORT
raise "LLIB #{Ytilib.time} #{$program_name}\n\t#{message}\n"
end
end
|
#direct_output_filename(output_file) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/sequence_logo/exec/glue_logos.rb', line 50
def direct_output_filename(output_file)
extname = File.extname(output_file)
basename = File.basename_wo_extname(output_file)
dirname = File.dirname(output_file)
File.join(dirname, "#{basename}_direct#{extname}")
end
|
#get_ppm_from_file(in_file_name) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/sequence_logo/ytilib/ppm_support.rb', line 7
def get_ppm_from_file(in_file_name)
case File.ext_wo_name(in_file_name)
when 'pat', 'pcm'
pm = PM.load(in_file_name)
pm.fixwc if pm.words_count
when 'mfa', 'fasta', 'plain'
pm = PM.new_pcm(Ytilib.read_seqs2array(in_file_name))
when 'xml'
pm = PM.from_bismark(Bismark.new(in_file_name).elements["//PPM"])
when in_file_name
pm = PPM.from_IUPAC(in_file_name.upcase)
end
pm.get_ppm
rescue
nil
end
|
#in_necessary_orientations(objects_to_render, orientation, logo_folder) ⇒ Object
- {renderable: , name: }
-
–> [{renderable: , filename: }]
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/sequence_logo/exec/sequence_logo.rb', line 5
def in_necessary_orientations(objects_to_render, orientation, logo_folder)
objects_to_render.map do |infos|
case orientation
when :direct
{renderable: infos[:renderable], filename: "#{infos[:name]}.png" }
when :revcomp
{renderable: infos[:renderable].revcomp, filename: "#{infos[:name]}.png" }
when :both
[ {renderable: infos[:renderable], filename: "#{infos[:name]}_direct.png" },
{renderable: infos[:renderable].revcomp, filename: "#{infos[:name]}_revcomp.png" } ]
end
end.flatten
end
|
#load_alignment_infos(alignment_lines) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/sequence_logo/exec/glue_logos.rb', line 5
def load_alignment_infos(alignment_lines)
alignment_lines.map{|line|
filename, shift, orientation, motif_name = line.strip.split("\t")
motif_name ||= File.basename(filename, File.extname(filename))
shift = shift.to_i
orientation = orientation.downcase.to_sym
ppm = get_ppm_from_file(filename)
checkerr("bad input file: #{filename}") { ppm == nil }
ppm.name ||= motif_name
raise 'Unknown orientation' unless [:direct, :revcomp].include?(orientation)
ppm_oriented = (orientation == :direct) ? ppm : ppm.revcomp
{motif: ppm_oriented, shift: shift}
}
end
|
#make_logo_alignment(aligned_motifs, options) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/sequence_logo/exec/glue_logos.rb', line 23
def make_logo_alignment(aligned_motifs, options)
alignment = SequenceLogo::Alignment.new
aligned_motifs.map {|motif_infos|
ppm_logo = SequenceLogo::PPMLogo.new(motif_infos[:motif],
icd_mode: options[:icd_mode],
words_count: options[:words_count],
enable_threshold_lines: options[:threshold_lines])
alignment += SequenceLogo::Alignment::Item.new(ppm_logo, motif_infos[:shift])
}
alignment
end
|
#readlines_from_file_or_stdin(argv, options = {}) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/sequence_logo/exec/glue_logos.rb', line 35
def readlines_from_file_or_stdin(argv, options = {})
default_options = { source_not_given_msg: 'Specify input data',
both_sources_given_msg: 'Specify either file with data or data itself in stdin, not both'}
options = default_options.merge(options)
raise options[:both_sources_given_msg] if !argv.empty? && !$stdin.tty?
if !argv.empty?
lines = File.readlines(argv.first)
elsif !$stdin.tty?
lines = $stdin.readlines
else
raise ArgumentError, options[:source_not_given_msg]
end
lines
end
|
#report(message, program_name = nil) ⇒ Object
15
16
17
18
19
|
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 15
def report(message, program_name = nil)
$program_name = "[#{program_name}]" if program_name != nil
return if $NO_REPORT
puts "LLIB #{Ytilib.time} #{$program_name}\t#{message}" if !block_given? || yield
end
|
#reverse_output_filename(output_file) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/sequence_logo/exec/glue_logos.rb', line 57
def reverse_output_filename(output_file)
extname = File.extname(output_file)
basename = File.basename_wo_extname(output_file)
dirname = File.dirname(output_file)
File.join(dirname, "#{basename}_revcomp#{extname}")
end
|
#start(fullpath) ⇒ Object
9
10
11
12
13
|
# File 'lib/sequence_logo/ytilib/ytilib.rb', line 9
def start(fullpath)
report(fullpath + ARGV.inject("") { |out, v| out += " " + v})
return if $NO_REPORT
$program_name = "[#{File.name_wo_ext(fullpath)}]"
end
|