Class: Bioroebe::SanitizeNucleotideSequence

Inherits:
Base
  • Object
show all
Defined in:
lib/bioroebe/nucleotides/sanitize_nucleotide_sequence.rb

Overview

Bioroebe::SanitizeNucleotideSequence

Constant Summary

Constants inherited from Base

Base::NAMESPACE

Constants included from ColoursForBase

ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#append_what_into, #can_base_pair?, #convert_global_env, #delete_file, #directory_to_the_codon_tables?, #is_on_roebe?, #is_palindrome?, #main_encoding?, #mkdir, #move_file, #mv, #no_file_exists_at, #no_newlines, #project_yaml_directory?, #rds, #register_sigint, #return_pwd, #return_the_first_line_of_this_file, #word_wrap, #write_what_into

Methods included from BaseModule

#absolute_path, #default_file_read, #file_readlines

Methods included from InternalHashModule

#internal_hash?, #reset_the_internal_hash

Methods included from ColoursForBase

#colourize_this_aminoacid_sequence_for_the_commandline, #colourize_this_nucleotide_sequence, #disable_colours, #ecomment, #efancy, #egold, #enable_colours, #eorange, #eparse, #erev, #red, #remove_trailing_escape_part, #return_colour_for_nucleotides, #rev, #sdir, #set_will_we_use_colours, #sfancy, #sfile, #simp, #swarn, #use_colours?, #use_colours_within_the_bioroebe_namespace?

Methods included from InferTheNamespaceModule

#infer_the_namespace, #namespace?

Constructor Details

#initialize(i = nil, run_already = true, &block) ⇒ SanitizeNucleotideSequence

#

initialize

#


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bioroebe/nucleotides/sanitize_nucleotide_sequence.rb', line 34

def initialize(
    i           = nil,
    run_already = true,
    &block
  )
  reset
  set_input(i)
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :do_not_remove_newlines
    # ===================================================================== #
    when /do(_|-)?not(_|-)?remove(_|-)?newlines$/,
         :do_not_remove_newlines
      @shall_we_remove_newlines = false
    end
  end
  run if run_already
end

Class Method Details

.[](i = "1 ATCCG\n30 TTA", &block) ⇒ Object

#

Bioroebe::SanitizeNucleotideSequence[]

This method will yield a consecutive nucleotide String by default.

#


148
149
150
151
152
153
# File 'lib/bioroebe/nucleotides/sanitize_nucleotide_sequence.rb', line 148

def self.[](
    i = "1 ATCCG\n30 TTA",
    &block
  )
  new(i, &block).result?
end

Instance Method Details

#input?Boolean Also known as: result?

#

input?

#

Returns:

  • (Boolean)


123
124
125
# File 'lib/bioroebe/nucleotides/sanitize_nucleotide_sequence.rb', line 123

def input?
  @input
end

#report_resultObject Also known as: report

#

report_result

This will report the result, but it has to be invoked manually.

#


132
133
134
# File 'lib/bioroebe/nucleotides/sanitize_nucleotide_sequence.rb', line 132

def report_result
  e result?
end

#resetObject

#

reset (reset tag)

#


61
62
63
64
65
66
67
68
69
# File 'lib/bioroebe/nucleotides/sanitize_nucleotide_sequence.rb', line 61

def reset
  super()
  # ======================================================================= #
  # === @shall_we_remove_newlines
  #
  # By default newlines will be removed.
  # ======================================================================= #
  @shall_we_remove_newlines = true
end

#runObject

#

run (run tag)

#


139
140
141
# File 'lib/bioroebe/nucleotides/sanitize_nucleotide_sequence.rb', line 139

def run
  sanitize_the_input
end

#sanitize_the_inputObject Also known as: sanitize_input

#

sanitize_the_input

#


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/bioroebe/nucleotides/sanitize_nucleotide_sequence.rb', line 98

def sanitize_the_input
  @input.reject! {|entry| entry.empty? }
  if shall_we_remove_newlines?
    @input.map! {|entry|
      entry = entry.delete("\n")
      entry = entry.delete("\\\\n")
    }
  end
  # ======================================================================= #
  # Next remove all numbers.
  # ======================================================================= #
  @input.map! {|entry|
    chars = entry.chars
    chars.reject! {|inner_entry| inner_entry =~ /\d+/ } # Reject numbers.
    if entry.include? '/'
      entry.delete('/')
    end
    entry
  }
  @input = @input.join
end

#set_input(i = '') ⇒ Object

#

set_input

#


81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/bioroebe/nucleotides/sanitize_nucleotide_sequence.rb', line 81

def set_input(
    i = ''
  )
  if i.is_a? Array
    if i.first.start_with?('>') and i.first.include?(N) # Assume gi number, which we will chop off.
      i[0] = i[0][i[0].index(N) .. -1] # Get all from the start, to the first newline.
    end 
    # i = i.join(' ') # .strip
  end
  # i = i.to_s.dup
  i = [i] unless i.is_a?(Array)
  @input = i
end

#shall_we_remove_newlines?Boolean

#

shall_we_remove_newlines?

#

Returns:

  • (Boolean)


74
75
76
# File 'lib/bioroebe/nucleotides/sanitize_nucleotide_sequence.rb', line 74

def shall_we_remove_newlines?
  @shall_we_remove_newlines
end