Class: Bioroebe::BlosumParser
- Inherits:
-
CommandlineApplication
- Object
- Base
- CommandlineApplication
- Bioroebe::BlosumParser
- Defined in:
- lib/bioroebe/parsers/blosum_parser.rb
Overview
Bioroebe::BlosumParser
Constant Summary collapse
- NAMESPACE =
#
NAMESPACE
#
inspect
- N =
#
N
#
"\n"
- VERTICAL_LINE =
#
VERTICAL_LINE
#
"|"
Constants inherited from CommandlineApplication
CommandlineApplication::OLD_VERBOSE_VALUE
Constants included from ColoursForBase
ColoursForBase::ARRAY_HTML_COLOURS_IN_USE
Class Method Summary collapse
-
.return_as_2D_table(i = :blosum62) ⇒ Object
# === Bioroebe::BlosumParser.return_as_2D_table ========================================================================= #.
-
.show_as_2D_table(i = :blosum62) ⇒ Object
# === Bioroebe::BlosumParser.show_as_2D_table ========================================================================= #.
Instance Method Summary collapse
-
#check_if_the_file_exists ⇒ Object
# === check_if_the_file_exists ========================================================================= #.
-
#dataset? ⇒ Boolean
(also: #data?, #hash, #hash?)
# === dataset? ========================================================================= #.
-
#initialize(i = '', run_already = true) ⇒ BlosumParser
constructor
# === initialize.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#run ⇒ Object
# === run ========================================================================= #.
-
#save_into_a_yaml_file ⇒ Object
# === save_into_a_yaml_file.
-
#set_blosum_file_to_use(i) ⇒ Object
# === set_blosum_file_to_use.
Methods inherited from CommandlineApplication
#all_aminoacids?, #append_what_into, #at_home?, #be_silent, #be_verbose?, #cat, #ccliner, #change_directory, #cliner, #codon_table_dataset?, #codon_to_aminoacid, #codons_for?, #colourize_this_dna_sequence, #complement, #cp, #disable_warnings, #download_dir?, #editor?, #enable_warnings, #ensure_that_the_base_directories_exist, #esystem, #extract, #is_this_a_start_codon?, #is_this_a_stop_codon?, #leading_five_prime, #load_bioroebe_yaml_file, #log_directory?, #one_letter_to_long_name, #one_to_three, #only_numbers?, #open_in_browser, #opne, #opnn, #pad_with_double_quotes, #pad_with_single_quotes, #partner_nucleotide, #remove_numbers, #remove_trailing_ansii_escape_code, #return_all_possible_start_codons, #return_array_of_one_letter_aminoacids, #return_cheerful_person, #return_chunked_display, #return_ubiquitin_sequence, #set_be_verbose, #start_codon?, #stop_codons?, #strict_filter_away_invalid_aminoacids, #taxonomy_download_directory?, #three_to_one, #to_rna, #trailing_three_prime, #use_opn?, #verbose_truth, #was_or_were, #without_extname, #write_what_into
Methods included from CommandlineArguments
#commandline_arguments?, #commandline_arguments_that_are_files?, #e, #first?, #first_non_hyphen_argument?, #remove_hyphens_from_the_commandline_arguments, #return_commandline_arguments_as_string, #return_commandline_arguments_that_are_not_files, #return_entries_without_two_leading_hyphens, #select_commandline_arguments, #select_entries_starting_with_two_hyphens, #set_commandline_arguments
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_use_colours, #sfancy, #sfile, #simp, #swarn, #use_colours?, #use_colours_within_the_bioroebe_namespace?
Methods inherited from Base
#append_what_into, #can_base_pair?, #convert_global_env, #delete_file, #directory_to_the_codon_tables?, #file_readlines, #infer_the_namespace, #is_on_roebe?, #is_palindrome?, #main_encoding?, #mkdir, #move_file, #mv, #namespace?, #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
Constructor Details
#initialize(i = '', run_already = true) ⇒ BlosumParser
#
initialize
The first argument should be the blosum file that we wish to use.
#
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bioroebe/parsers/blosum_parser.rb', line 43 def initialize( i = '', run_already = true ) reset set_blosum_file_to_use(i) if block_given? case yield # ===================================================================== # # === :be_quiet # ===================================================================== # when :be_quiet @be_verbose = false end end run if run_already end |
Class Method Details
.return_as_2D_table(i = :blosum62) ⇒ Object
#
Bioroebe::BlosumParser.return_as_2D_table
#
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/bioroebe/parsers/blosum_parser.rb', line 145 def self.return_as_2D_table(i = :blosum62) @result = ''.dup if i.is_a? Array i = i.first # Only support the first element of an Array. end _ = Bioroebe::BlosumParser.new(i) { :be_quiet } hash = _.hash? @result << i.to_s.capitalize+N @result << N array = %w( A R N D C Q E G H I L K M F P S T W Y V B J Z X * ) @result << ' ' array.each {|entry| @result << "#{entry.to_s.rjust(3, ' ')}" } @result << N @result << '―'* 80 @result << N array.each_with_index {|entry, index| @result << "#{entry} #{VERTICAL_LINE}" array.each_with_index {|inner_entry, inner_index| key_to_use = entry+inner_entry if hash.has_key? key_to_use match = hash[key_to_use] @result << "#{match.to_s.rjust(3, ' ')}" else @result << "No key found for #{key_to_use}." end } @result << N } @result << '―'* 80 @result << N return @result end |
.show_as_2D_table(i = :blosum62) ⇒ Object
#
Bioroebe::BlosumParser.show_as_2D_table
#
138 139 140 |
# File 'lib/bioroebe/parsers/blosum_parser.rb', line 138 def self.show_as_2D_table(i = :blosum62) print Bioroebe::BlosumParser.return_as_2D_table(i) end |
Instance Method Details
#check_if_the_file_exists ⇒ Object
#
check_if_the_file_exists
#
105 106 107 108 109 110 111 112 |
# File 'lib/bioroebe/parsers/blosum_parser.rb', line 105 def check_if_the_file_exists _ = @blosum_file_to_use.to_s if File.exist? _ # Pass through - all is fine. else erev "The file at `#{sfile(_)}#{rev}` does not exist." end end |
#dataset? ⇒ Boolean Also known as: data?, hash, hash?
#
dataset?
#
117 118 119 |
# File 'lib/bioroebe/parsers/blosum_parser.rb', line 117 def dataset? @hash end |
#reset ⇒ Object
#
reset
#
64 65 66 67 68 69 70 |
# File 'lib/bioroebe/parsers/blosum_parser.rb', line 64 def reset super() # ======================================================================= # # === @hash # ======================================================================= # @hash = {} # Initialize our main Hash here. end |
#run ⇒ Object
#
run
#
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/bioroebe/parsers/blosum_parser.rb', line 181 def run check_if_the_file_exists if File.exist? @blosum_file_to_use dataset = File.readlines(@blosum_file_to_use).map {|entry| entry.strip } # ======================================================================= # # === Eliminate comments from the file # # Next, we get rid of all rows that start with '#' character, as # we assume these to be comments. # ======================================================================= # dataset.reject! {|line| line.start_with?('#') or line.empty? } # ======================================================================= # # First, we obtain the headers in the proper order. # ======================================================================= # headers = dataset.shift.split(' ') # ======================================================================= # # Next we can iterate over the remaining dataset - the first entry will # be one part of the key in the hash. # ======================================================================= # dataset.each {|line| splitted = line.split(' ') which_aminoacid = splitted.shift # Get the first entry. splitted.each_with_index {|the_score, index| key = which_aminoacid + headers[index] @hash[key] = the_score.to_i } } end end |
#save_into_a_yaml_file ⇒ Object
#
save_into_a_yaml_file
This method can be used to store the main @hash into a yaml file.
#
128 129 130 131 132 133 |
# File 'lib/bioroebe/parsers/blosum_parser.rb', line 128 def save_into_a_yaml_file what = YAML.dump(@hash) into = log_dir?+File.basename(@blosum_file_to_use) erev "Storing into the file `#{sfile(into)}`." write_what_into(what, into) end |
#set_blosum_file_to_use(i) ⇒ Object
#
set_blosum_file_to_use
This method is used to determine the main BLOSUM-file to use, which is typically a .yaml file.
#
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/bioroebe/parsers/blosum_parser.rb', line 78 def set_blosum_file_to_use(i) i = i.first if i.is_a? Array if i.is_a? Symbol i = i.to_s end if i.include? '-' i.delete!('-') end if i.is_a?(String) i = i.dup # i.downcase! # This has been eliminated at 17.08.2021, because it # may contain the full path. On Linux paths are # case sensitive. unless i.end_with?('.yml') # =================================================================== # # In this case we have to modify the input a little bit. # =================================================================== # i = ::Bioroebe.blosum_directory?+ i.to_s.dup+'.yml' end end @blosum_file_to_use = i end |