Top Level Namespace

Defined Under Namespace

Modules: Bioinform, Magick, SequenceLogo Classes: File, Float, Integer

Instance Method Summary collapse

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

#direct_output_filename(output_file) ⇒ Object



49
50
51
52
53
54
# File 'lib/sequence_logo/exec/glue_logos.rb', line 49

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

#icd2of4(words_count, floor: false) ⇒ Object



26
27
28
29
30
# File 'lib/sequence_logo/ppm_support.rb', line 26

def icd2of4(words_count, floor: false)
  i2o4 = words_count / 2.0
  i2o4 = i2o4.floor if floor
  position_infocod([i2o4, i2o4, 0, 0]) # 0 is equal to words_count % 2, because 0! = 1!
end

#icd3of4(words_count, floor: false) ⇒ Object



32
33
34
35
36
37
# File 'lib/sequence_logo/ppm_support.rb', line 32

def icd3of4(words_count, floor: false)
  i3o4 = words_count / 3.0
  i3o4 = i3o4.floor if floor
  addon = floor ? words_count % 3 : 0
  position_infocod([i3o4, i3o4, i3o4, addon])
end

#icd4of4(words_count, floor: false) ⇒ Object



20
21
22
23
24
# File 'lib/sequence_logo/ppm_support.rb', line 20

def icd4of4(words_count, floor: false)
  i4o4 = words_count / 4.0
  i4o4 = i4o4.floor  if floor
  position_infocod([i4o4, i4o4, i4o4, i4o4])
end

#icdThc(words_count, floor: false) ⇒ Object



39
40
41
# File 'lib/sequence_logo/ppm_support.rb', line 39

def icdThc(words_count, floor: false)
  icd3of4(words_count, floor: floor)
end

#icdTlc(words_count, floor: false) ⇒ Object



43
44
45
46
47
# File 'lib/sequence_logo/ppm_support.rb', line 43

def icdTlc(words_count, floor: false)
  io = words_count / 6.0
  io = io.floor  if floor
  position_infocod([2*io, 2*io, io, io])
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
# 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 = Bioinform::MotifModel::PCM.from_file(filename, validator: Bioinform::MotifModel::PCM::DIFFERENT_COUNTS_VALIDATOR)
    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



22
23
24
25
26
27
28
29
30
31
# File 'lib/sequence_logo/exec/glue_logos.rb', line 22

def make_logo_alignment(aligned_motifs, options)
  alignment = SequenceLogo::Alignment.new
  aligned_motifs.map {|motif_infos|
     = SequenceLogo::PPMLogo.new(motif_infos[:motif],
                                        icd_mode: options[:icd_mode],
                                        enable_threshold_lines: options[:threshold_lines])
    alignment += SequenceLogo::Alignment::Item.new(, motif_infos[:shift])
  }
  alignment
end

#position_infocod(pos) ⇒ Object



15
16
17
18
# File 'lib/sequence_logo/ppm_support.rb', line 15

def position_infocod(pos)
  words_count = pos.inject(0.0, &:+)
  ( pos.map(&:log_fact).inject(0.0, &:+) - words_count.log_fact ) / words_count
end

#readlines_from_file_or_stdin(argv, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sequence_logo/exec/glue_logos.rb', line 33

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)
  ## This check fails when glue_logos is run via unicorn. It looks that unicorn daemon redefines isatty of child process
  # 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

#reverse_output_filename(output_file) ⇒ Object



56
57
58
59
60
61
# File 'lib/sequence_logo/exec/glue_logos.rb', line 56

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

#scale(value, relative_to:) ⇒ Object



49
50
51
# File 'lib/sequence_logo/ppm_support.rb', line 49

def scale(value, relative_to:)
  ( (value - relative_to) / relative_to ).abs
end