Class: Bioroebe::ParseFasta

Inherits:
CommandlineApplication show all
Defined in:
lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb

Overview

Bioroebe::ParseFasta

Constant Summary collapse

REGEX_NON_NUCLEOTIDES =
#

REGEX_NON_NUCLEOTIDES

All non-nucleotides will be handled here via this regex.

N is excluded because it may stand for “any” nucleotide too, at the least for a purine.

#
/BDEFHIJKLMOPQRSVWXYZ/
DEFAULT_FASTA =
#

DEFAULT_FASTA

This String can be used to quickly test code depending on FASTA entries.

#
'>Rosalind_6404
CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
TCCCACTAATAATTCTGAGG
>Rosalind_5959
CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
ATATCCATTTGTCAGCAGACACGC
>Rosalind_0808
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
TGGGAACCTGCGGGCAGTAGGTGGAAT'
DEFAULT_ROUND_TO =
#

DEFAULT_ROUND_TO

#
2

Constants inherited from CommandlineApplication

CommandlineApplication::OLD_VERBOSE_VALUE

Constants included from ColoursForBase

ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

Constants inherited from Base

Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

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, #opnerev, #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, #runmode?, #set_be_verbose, #set_runmode, #start_codon?, #stop_codons?, #strict_filter_away_invalid_aminoacids, #taxonomy_download_directory?, #three_to_one, #to_rna, #trailing_three_prime, #verbose_truth, #was_or_were, #without_extname, #write_what_into

Methods included from BaseModule

#absolute_path, #default_file_read, #file_readlines

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_will_we_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?, #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 InternalHashModule

#internal_hash?, #reset_the_internal_hash

Methods included from InferTheNamespaceModule

#infer_the_namespace, #namespace?

Constructor Details

#initialize(i = DEFAULT_FASTA, run_already = true, &block) ⇒ ParseFasta

#

initialize

#


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 67

def initialize(
    i           = DEFAULT_FASTA,
    run_already = true,
    &block
  )
  reset
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    # ===================================================================== #
    # First handle Symbols.
    # ===================================================================== #
    case yielded
    # ===================================================================== #
    # === :be_verbose
    # ===================================================================== #
    when :be_verbose,
         :verbose
      set_be_verbose_and_report_the_sequence
    # ===================================================================== #
    # === :be_quiet
    # ===================================================================== #
    when :be_quiet,
         :be_silent
      be_quiet
    # ===================================================================== #
    # === :sizeseq
    # ===================================================================== #
    when :sizeseq
      @sort_by_size = true
    end
    # ===================================================================== #
    # === Handle Hashes next
    # ===================================================================== #
    if yielded.is_a? Hash
      # =================================================================== #
      # === :be_verbose
      # =================================================================== #
      if yielded.has_key? :be_verbose
        set_be_verbose(yielded.delete(:be_verbose))
        @internal_hash[:report_the_sequence] = true
      end
      # =================================================================== #
      # === :use_colours
      # =================================================================== #
      if yielded.has_key? :use_colours
        set_use_colours(
          yielded.delete(:use_colours)
        )
      end
      # =================================================================== #
      # === :sizeseq
      # =================================================================== #
      if yielded.has_key? :sizeseq
        @sort_by_size = true
      end
    end
  end
  set_commandline_arguments(i)
  case run_already
  # ======================================================================= #
  # === :dont_run_yet
  # ======================================================================= #
  when :dont_run_yet,
       :do_not_run_yet
    run_already = false
  end
  run if run_already
end

Class Method Details

.[](i) ⇒ Object

#

Bioroebe::ParseFasta[]

#


1205
1206
1207
1208
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1205

def self.[](i)
  _ = new(i)
  _.sequences?
end

Instance Method Details

#[](i) ⇒ Object

#

[]

This is a simpler query-interface for obtaining the DNA/RNA sequence of the FASTA file (or aminoacid sequence, if we have a protein at hand here).

Using the method sequences? here, which in turn works on @hash, is ok because Hashes are kept in a sorted manner in ruby since some time.

#


1198
1199
1200
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1198

def [](i)
  sequences?[i]
end

#add_length_information_to_the_headerObject

#

add_length_information_to_the_header

#


1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1082

def add_length_information_to_the_header
  _ = header?.strip
  _ << ' length='+sequence_size?.to_s+';'
  # ======================================================================= #
  # Next, designate where to store this file.
  # ======================================================================= #
  into = 'new_fasta_file.fasta'
  if overwrite_the_original_file?
    into = @input_file
  end
  what = ''.dup
  what << "> "+_+"\n"
  what << raw_body?
  if what and into
    erev 'Storing into `'+sfile(into)+rev+'`.'
    write_what_into(what, into)
  end
end

#calculate_gc_contentObject

#

calculate_gc_content

Calculate the gc content through this method, which is called from within the method run().

#


705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 705

def calculate_gc_content
  _ = @hash.values.join.delete(N)
  if is_polynucleotide? _
    @hash.each_pair {|key, content|
      # =================================================================== #
      # Delegate towards the method Bioroebe.gc_content next, including
      # to round towards 5 positions:
      # =================================================================== #
      gc_content = ::Bioroebe.gc_content(content.upcase, round_to?)
      gc_content = gc_content.first if gc_content.is_a? Array
      gc_content = gc_content.to_s
      minimal_key = key.to_s
      if minimal_key.include? '|'
        minimal_key = minimal_key.split('|').last.strip
      end
      if be_verbose?
        _ = minimal_key.strip
        if _.size > 40 # Shorten the content a bit if it is too long.
          _ = _[0 .. 40]+' [...]'
        end
        erev 'GC content of "'+simp(_)+rev+'" is: '+
             "#{sfancy(gc_content)}#{rev} %"
      end
    }
  else
    erev '`'+simp(_)+rev+'` is not a polynucleotide.' if be_verbose?
  end
end

#condense_the_sequence_onto_a_single_line?Boolean

#

condense_the_sequence_onto_a_single_line?

#

Returns:

  • (Boolean)


871
872
873
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 871

def condense_the_sequence_onto_a_single_line?
  @internal_hash[:condense_the_sequence_onto_a_single_line]
end

#current_key?Boolean Also known as: id?, sequence_id?, title, title?

#

current_key?

#

Returns:

  • (Boolean)


671
672
673
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 671

def current_key?
  @current_key
end

#data?Boolean Also known as: input?, dataset?

#

data?

This will contain the full content of the (whole) .fasta file, including the header.

#

Returns:

  • (Boolean)


774
775
776
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 774

def data?
  @data
end

#do_process_the_commandline_arguments_that_are_files(these_files = commandline_arguments_that_are_files? ) ⇒ Object

#

do_process_the_commandline_arguments_that_are_files

#


413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 413

def do_process_the_commandline_arguments_that_are_files(
    these_files = commandline_arguments_that_are_files?
  )
  unless these_files.is_a? Array
    these_files = [these_files].flatten.compact
  end
  these_files.each {|this_file|
    set_input_file(this_file)
    set_data # This will use the default file.
    split_into_proper_sections
    report_the_FASTA_header if @show_the_header
    if @sort_by_size
      run_sizeseq_comparison
    else
      # =================================================================== #
      # === Handle cases where the input is a protein
      # =================================================================== #
      if is_the_sequence_a_polypeptide?
        if be_verbose?
          erev "This sequence is assumed to be a #{royalblue('protein')}#{rev}."
          report_how_many_elements_we_have_found
        end
      else # Must be a protein.
        # =================================================================== #
        # === Else it must be RNA or DNA
        # =================================================================== #
        if be_verbose?
          erev "This sequence is assumed to "\
               "be #{royalblue('DNA')}#{rev} or #{royalblue('RNA')}#{rev}."
        end
        calculate_gc_content # GC content makes only sense for nucleotides.
        report_how_many_elements_we_have_found if be_verbose?
      end
      if be_verbose?
        report_the_nucleotide_composition
        report_on_how_many_entries_we_did_work
        if report_the_sequence?
          do_report_the_sequence
        end
      end
    end
  }
end

#do_report_the_sequenceObject Also known as: display, report

#

do_report_the_sequence (report tag)

This method is used to display the main sequence at hand.

#


506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 506

def do_report_the_sequence
  _ = main_sequence?
  # ======================================================================= #
  # Honour the --limit commandline flag next.
  # ======================================================================= #
  if @internal_hash[:limit_the_display_to_n_nucleotides]
    _ = _[0 .. (@internal_hash[:limit_the_display_to_n_nucleotides] - 1)]
  end
  if @colourize_sequence
    if is_polynucleotide?
      # =================================================================== #
      # Else assume this is DNA/RNA input.
      # =================================================================== #
      _.gsub!(/A/, teal('A')+rev)
      _.gsub!(/C/, slateblue('C')+rev)
      _.gsub!(/G/, royalblue('G')+rev)
      _.gsub!(/T/, steelblue('T')+rev)
      _.gsub!(/U/, steelblue('U')+rev)
    #else
    end
  end
  if condense_the_sequence_onto_a_single_line?
    _ = _.delete("\n")
  end
  erev colourize_this_nucleotide_sequence(_)
  e if condense_the_sequence_onto_a_single_line?
  if show_the_translated_protein_sequence?
    # ===================================================================== #
    # Do show the translated protein sequence next:
    # ===================================================================== #
    translated_into_aa = Bioroebe.to_aa(_)
    translated_into_aa_and_colourized = translated_into_aa.dup
    if translated_into_aa.include? '*'
      translated_into_aa_and_colourized = translated_into_aa.gsub(/\*/,tomato('*'))
    end
    erev 'The translated aminoacid sequence of '+
         sfancy(translated_into_aa.size.to_s)+rev+
         ' aminoacids is:'
    e
    erev steelblue("  #{translated_into_aa_and_colourized}")
    e
  end
end

#do_sanitize_the_file_then_exitObject

#

do_sanitize_the_file_then_exit

#


1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1342

def do_sanitize_the_file_then_exit
  _ = non_hyphened_commandline_arguments?
  first = _.first
  if File.exist?(first)
    dataset = default_readlines(first)
    # ===================================================================== #
    # Next, iterate over the dataset.
    # ===================================================================== #
    dataset.map! {|entry|
      entry = entry.dup if entry.frozen?
      entry.delete!(' ') if entry.include?(' ')
      entry.upcase!
      entry
    }
    opne 'Saving the sanitized dataset into '\
         'the file '+sfile(first)+rev+'.'
    write_what_into(dataset.join, first)
  end
  exit
end

#do_show_the_headerObject

#

do_show_the_header

#


958
959
960
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 958

def do_show_the_header
  @show_the_header = true
end

#do_sort_by_sizeObject Also known as: run_sizeseq_comparison

#

do_sort_by_size

This method will sort the hash by size of the sequence. It has been inspired by the EMBOSS sizeq functionality.

The output that should be generated might look like this:

https://www.bioinformatics.nl/cgi-bin/emboss/help/sizeseq#input.1

Invocation example:

x = Bioroebe::ParseFasta.new('/Depot/j/globins.fasta'); x.do_sort_by_size
#


899
900
901
902
903
904
905
906
907
908
909
910
911
912
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 899

def do_sort_by_size
  # ======================================================================= #
  # Sort it here first, by the size of the "value", aka the sequence body.
  # ======================================================================= #
  @hash = return_size_sorted_hash(@hash)
  _ = ''.dup
  @hash.each_pair {|key, sequence|
    _ << '> ID '+sequence.size.to_s+' AA.; DE: '+key.to_s+
         ' SQ '+sequence.size.to_s+' AA'+N # ; unknown MW as of yet; '\
         #'unknown CRC64 as of yet'+N
    _ << sequence+N+N
  }
  e _
end

#entries?Boolean

#

entries?

#

Returns:

  • (Boolean)


483
484
485
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 483

def entries?
  @data
end

#first_key?Boolean

#

first_key?

Obtain the very first entry.

#

Returns:

  • (Boolean)


935
936
937
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 935

def first_key?
  headers?.first
end

#first_valueObject

#

first_value

This will return the first entry of the Fasta files.

#


739
740
741
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 739

def first_value
  sequences?.first
end

#gc_content?Boolean Also known as: gc_content

#

gc_content?

#

Returns:

  • (Boolean)


1279
1280
1281
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1279

def gc_content?
  return ::Bioroebe.gc_content(main_sequence?).to_f # Must be a float.
end

#hash?Boolean

#

hash?

#

Returns:

  • (Boolean)


782
783
784
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 782

def hash?
  @hash
end

#header?Boolean

#

header?

This variant will always return the first entry.

#

Returns:

  • (Boolean)


944
945
946
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 944

def header?
  headers?.first.to_s
end

#headers?Boolean

#

headers?

#

Returns:

  • (Boolean)


926
927
928
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 926

def headers?
  @hash.keys
end

#is_polynucleotide?(i = main_sequence?) ) ⇒ Boolean Also known as: is_a_nucleotide?

#

is_polynucleotide?

#

Returns:

  • (Boolean)


757
758
759
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 757

def is_polynucleotide?(i = main_sequence?)
  !is_protein?(i)
end

#is_the_sequence_a_polypeptide?(i = main_sequence? ) ⇒ Boolean Also known as: is_protein?, is_a_protein?

#

is_the_sequence_a_polypeptide?

This method can be used to determine whether a given input sequence is a polypeptide (aka a protein) or whether it is not.

If this sequence is a polypeptide then this method will return true. Otherwise false will be returned.

#

Returns:

  • (Boolean)


1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1232

def is_the_sequence_a_polypeptide?(
    i = main_sequence?
  )
  return_value = false # Set the default return value here.
  # ======================================================================= #
  # Look at the first 120 positions to determine whether this is a protein
  # or a nucleotide sequence.
  # ======================================================================= #
  subsequence = i[0 .. 119] # Must deduct 1 at the end since Arrays in ruby start at 0.
  # ======================================================================= #
  # Build a frequency of the characters there.
  # ======================================================================= #
  hash = {}
  hash.default = 0
  subsequence.chars.each {|character|
    hash[character] += 1
  }
  keys_to_check_for = %w(
    B D E F H I J K L M O P Q R S V W X Y Z
  )

  values = hash.select {|key, value|
    if keys_to_check_for.include? key
      true
    else
      false
    end
  }.values.sum
  if values > 0
    return_value = true
  end
  return return_value
end

#is_this_sequence_a_polynucleotide_sequence?Boolean

#

is_this_sequence_a_polynucleotide_sequence?

#

Returns:

  • (Boolean)


764
765
766
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 764

def is_this_sequence_a_polynucleotide_sequence?
  !is_protein?
end

#main_sequence?Boolean

#

main_sequence?

This will always return the first entry.

#

Returns:

  • (Boolean)


1272
1273
1274
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1272

def main_sequence?
  @hash.values.first
end
#

menu (menu tag)

#


263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 263

def menu(
    i = return_commandline_arguments_that_are_not_files
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === --sanitize-the-file
    #
    # This entry point allows the user to quickly sanitize a .fasta file.
    #
    # In this context, the default actions done will be to remove all
    # ' ' in a given line, and to upcase the content. Other than that
    # no modifications will be made.
    # ===================================================================== #
    when /^-?-?sanitize(-|_)?the(-|_)?file$/i
      @internal_hash[:sanitize_the_file] = true
    # ===================================================================== #
    # === --to-protein
    #
    # A few aliases exist to this, such as --convert and --translate.
    #
    # Invocation example:
    #
    #   pfasta *.fasta --toprotein
    #
    # ===================================================================== #
    when /^-?-?to(-|_)?protein$/i,
         /^-?-?convert$/i,
         /^-?-?translate$/i
      @internal_hash[:show_the_translated_protein_sequence] = true
    # ===================================================================== #
    # === --one-line
    #
    # Invocation example:
    #
    #   pfasta rpoS_NC_000913.3.fasta --one-line
    #
    # ===================================================================== #
    when /^-?-?one(-|_)?liner?/i
      @internal_hash[:condense_the_sequence_onto_a_single_line] = true
    # ===================================================================== #
    # === --limit=1000
    #
    # Invocation example:
    #
    #   pfasta --limit=1000
    #
    # ===================================================================== #
    when /^-?-?limit=(\d+)$/i
      @internal_hash[:limit_the_display_to_n_nucleotides] = $1.to_s.dup.to_i
    # ===================================================================== #
    # === --overwrite
    # ===================================================================== #
    when /^-?-?overwrite/i
      @internal_hash[:overwrite_the_original_file] = true
    # ===================================================================== #
    # === --help
    #
    # Usage example:
    #
    #   parse_fasta --help
    #
    # ===================================================================== #
    when /^-?-?help/i
      show_help
      exit
    # ===================================================================== #
    # === --save-file
    # ===================================================================== #
    when /^-?-?save(-|_)?file/i
      @internal_hash[:save_the_file] = true
    # ===================================================================== #
    # === --also-show-the-sequence
    #
    # To invoke this method try:
    #
    #   parsefasta /Depot/Bioroebe/NP_013521.3_289_aa.fasta --show
    #
    # ===================================================================== #
    when /^-?-?also(-|_)?show(-|_)?the(-|_)?sequence$/i,
         /^-?-?report$/i,
         /^-?-?show$/i
      @internal_hash[:report_the_sequence] = true
    # ===================================================================== #
    # === --header
    # ===================================================================== #
    when /^-?-?header/i
      do_show_the_header
    # ===================================================================== #
    # === --short
    #
    # This entry point can be used to show 300 nucleotides and not
    # more, by simply using the --short commandline flag.
    # ===================================================================== #
    when /^-?-?short/i
      @internal_hash[:limit_the_display_to_n_nucleotides] = 300
    # ===================================================================== #
    # === --size
    #
    # This will simply tell us how many nucleotides the given sequence 
    # has, then exit.
    #
    # To invoke this method try:
    #
    #   parsefasta /Depot/Bioroebe/NP_013521.3_289_aa.fasta --size
    #
    # ===================================================================== #
    when /^-?-?size$/i
      set_be_quiet
      do_process_the_commandline_arguments_that_are_files
      erev size? # Report the size here.
      exit
    end
  end
end

#n_nucleotides?Boolean Also known as: return_n_aminoacids, size?, sequence_size?

#

n_nucleotides?

#

Returns:

  • (Boolean)


917
918
919
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 917

def n_nucleotides?
  @hash.values.first.delete("\n").size
end

#nucleotides_or_aminoacids?Boolean

#

nucleotides_or_aminoacids?

#

Returns:

  • (Boolean)


746
747
748
749
750
751
752
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 746

def nucleotides_or_aminoacids?
  if is_polynucleotide?
    'nucleotides'
  else
    'aminoacids'
  end
end

#opnnObject

#

opnn

#


688
689
690
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 688

def opnn
  super(namespace?) if use_opn?
end

#output_resultsObject

#

output_results

#


497
498
499
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 497

def output_results
  pp @hash
end

#overwrite_the_original_file?Boolean

#

overwrite_the_original_file?

#

Returns:

  • (Boolean)


1016
1017
1018
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1016

def overwrite_the_original_file?
  @internal_hash[:overwrite_the_original_file]
end

#raw_body?Boolean

#

raw_body?

#

Returns:

  • (Boolean)


951
952
953
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 951

def raw_body?
  @hash.values.first
end

#report_how_many_elements_we_have_foundObject

#

report_how_many_elements_we_have_found

#


582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 582

def report_how_many_elements_we_have_found
  if @hash
    first = @hash.values.first.delete("\n")
    size = first.size.to_s
    if be_verbose?
      n_start_codons = first.count('ATG')
      # =================================================================== #
      # We upcase it since as of October 2021, as some FASTA files may
      # include the sequence in lowercased characters.
      # =================================================================== #
      n_start_codons += first.reverse.upcase.count('ATG')
      result = "This sequence contains #{simp(size.to_s)}#{rev}"\
               " #{nucleotides_or_aminoacids?}".dup
      if is_a_nucleotide?
        result << " and #{n_start_codons} "\
                  "ATG codons (on both strands) in total"
      end
      result << '.'
      if size.to_i > 1_000_000
        # ================================================================= #
        # Format the number with '_' characters.
        # ================================================================= #
        formatted = size.to_i.to_s.reverse.split(/(.{3})/).reject(&:empty?).join('_').reverse
        result = result.dup if result.frozen?
        result << ' ('+simp(formatted+' bp')+rev+')'
      end
      erev result
    end
  end
end

#report_on_how_many_entries_we_did_workObject

#

report_on_how_many_entries_we_did_work

#


616
617
618
619
620
621
622
623
624
625
626
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 616

def report_on_how_many_entries_we_did_work
  if be_verbose?
    entry_or_entries = 'entry'
    if @hash.keys.size > 1
      entry_or_entries = 'entries'
    end
    erev "We have identified a total of #{orange(@hash.keys.size)}"\
         "#{rev} #{entry_or_entries} in this fasta dataset."
    e
  end
end

#report_the_FASTA_headerObject

#

report_the_FASTA_header

#


631
632
633
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 631

def report_the_FASTA_header
  e "#{rev}The header is: #{steelblue(header?)}"
end

#report_the_nucleotide_compositionObject Also known as: report_the_protein_composition

#

report_the_nucleotide_composition

#


554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 554

def report_the_nucleotide_composition
  if is_this_sequence_a_polynucleotide_sequence?
    first = @hash.values.first.upcase
    total_size   = first.size
    n_adenines   = first.count('A')
    n_thymidines = first.count('T')
    n_cytodines  = first.count('C')
    n_guanines   = first.count('G')
    erev "The nucleotide composition is as follows:"
    e "  "\
      "#{steelblue(n_adenines)}#{rev}x A (#{(n_adenines * 100.0 / total_size).round(2)}%), "\
      "#{steelblue(n_thymidines)}#{rev}x T (#{(n_thymidines * 100.0 / total_size).round(2)}%), "\
      "#{steelblue(n_cytodines)}#{rev}x C (#{(n_cytodines * 100.0 / total_size).round(2)}%), "\
      "#{steelblue(n_guanines)}#{rev}x G (#{(n_guanines * 100.0 / total_size).round(2)}%)"
  elsif is_a_protein?
    # ===================================================================== #
    # Report the composition of the protein:
    # ===================================================================== #
    sequence = @hash.values.first.delete("\n")
    erev "The protein composition (aminoacids) is as follows:"
    # e colourize_this_aminoacid_sequence_for_the_commandline("  #{sequence}")
    e orchid("  #{sequence}")
  end
end

#report_the_sequence?Boolean

#

report_the_sequence?

#

Returns:

  • (Boolean)


638
639
640
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 638

def report_the_sequence?
  @internal_hash[:report_the_sequence]
end

#resetObject

#

reset (reset tag)

#


142
143
144
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
177
178
179
180
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 142

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @is_a_genbank_file
  # ======================================================================= #
  @is_a_genbank_file = false
  # ======================================================================= #
  # === @input_file
  #
  # This variable denotes which input file is used to read data from.
  #
  # It is nil initially because we may skip reading from an existing
  # file and e. g. only read from a String or some other non-file
  # entity.
  # ======================================================================= #
  @input_file = nil
  # ======================================================================= #
  # === @hash
  #
  # This is the main variable for the class. It will keep entries such
  # as this one here:
  #
  #   {
  #     "ENSMUSG00000020122|ENSMUST08" => "CCCTCC"
  #   }
  #
  # ======================================================================= #
  @hash = {}
  # ======================================================================= #
  # === @internal_hash
  #
  # This Hash exists for internal configuration of the class.
  # ======================================================================= #
  @internal_hash = {}
  # ======================================================================= #
  # === :report_the_sequence
  # ======================================================================= #
  @internal_hash[:report_the_sequence] = false
  # ======================================================================= #
  # === :overwrite_the_original_file
  # ======================================================================= #
  @internal_hash[:overwrite_the_original_file] = false
  # ======================================================================= #
  # === :save_the_file
  # ======================================================================= #
  @internal_hash[:save_the_file] = false
  # ======================================================================= #
  # === :remove_numbers_from_input
  # ======================================================================= #
  @internal_hash[:remove_numbers_from_input] = false
  # ======================================================================= #
  # === :sanitize_the_file
  #
  # If the following variable is true then the .fasta file at hand will
  # be modified. 
  # ======================================================================= #
  @internal_hash[:sanitize_the_file] = false
  # ======================================================================= #
  # === :show_the_translated_protein_sequence
  #
  # This setting is false initially. If set to true via the commandline
  # then report() will show the translated protein sequence as well.
  # ======================================================================= #
  @internal_hash[:show_the_translated_protein_sequence] = false
  # ======================================================================= #
  # === :condense_the_sequence_onto_a_single_line
  #
  # By default the output of this class will include newlines for the
  # sequence. If this is not wanted by the user then the following
  # variable keeps track of that behaviour. You can use the flag
  # called --one-line to enable a condensed output, with newlines
  # being removed.
  # ======================================================================= #
  @internal_hash[:condense_the_sequence_onto_a_single_line] = false
  # ======================================================================= #
  # === :limit_the_display_to_n_nucleotides
  #
  # If this variable is a number rather than nil, then it will be used
  # to display only a limited number of nucleotides, e. g. "1000" if
  # the user passes in 1000.
  # ======================================================================= #
  @internal_hash[:limit_the_display_to_n_nucleotides] = nil
  # ======================================================================= #
  # === @may_we_exit
  # ======================================================================= #
  @may_we_exit = false
  # ======================================================================= #
  # === @current_key
  # ======================================================================= #
  @current_key = nil
  # ======================================================================= #
  # === @use_opn
  # ======================================================================= #
  @use_opn = ::Bioroebe.use_opn?
  # ======================================================================= #
  # === @colourize_sequence
  # ======================================================================= #
  @colourize_sequence = false
  # ======================================================================= #
  # === @sort_by_size
  #
  # If the following variable is set to true, then this class will
  # run a sizeseq-comparison, that is, it will compare all sequences
  # and output them in a size-sorted manner, similar to the EMBOSS
  # sizeseq action.
  # ======================================================================= #
  @sort_by_size = false
  # ======================================================================= #
  # === @show_the_header
  #
  # If this variable is true then the header will be shown.
  # ======================================================================= #
  @show_the_header = false
  set_round_to :default
  set_be_verbose
end

#return_size_sorted_hash(i = @hash) ⇒ Object

#

return_size_sorted_hash

#


878
879
880
881
882
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 878

def return_size_sorted_hash(i = @hash)
  _ = i.sort_by {|key, value| value.size }
  i = Hash[_]
  return i
end

#round_to?Boolean

#

round_to?

#

Returns:

  • (Boolean)


681
682
683
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 681

def round_to?
  @internal_hash[:round_to]
end

#runObject

#

run (run tag)

#


1366
1367
1368
1369
1370
1371
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1366

def run
  menu
  do_sanitize_the_file_then_exit if sanitize_the_file?
  do_process_the_commandline_arguments_that_are_files
  do_save_the_file if save_the_file?
end

#sanitize_data(i) ⇒ Object

#

sanitize_data

#


645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 645

def sanitize_data(i)
  if i.is_a? Array
    i.flatten!
    i.reject! {|entry| entry.start_with? '#' }
    i.reject! {|entry| entry.strip.empty? }
    if i.first and i.first.include? "\r"
      # =================================================================== #
      # Some FASTA files include "\r" line endings. We will check first
      # for the first entry to contain a \r, and if so, we assume the
      # whole FASTA file may have \r, which then will be removed.
      # =================================================================== #
      i.map! {|entry| entry.delete("\r") }
    end
  end
  # ========================================================================= #
  # === Run through SanitizeNucleotideSequence
  # ========================================================================= #
  if @internal_hash[:remove_numbers_from_input]
    i = Bioroebe::SanitizeNucleotideSequence[i]
  end
  i
end

#sanitize_the_descriptionObject

#

sanitize_the_description

This method will iterate over the description entry and sanitize it. In this context sanitizing means to add the “length” entry, and the “type” entry, such as in:

" # length=231; type=dna"
#


467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 467

def sanitize_the_description
  @data.map! {|line|
    if line.start_with?('>') and !line.include?('length=')
      length = 0
      if @hash.has_key? line.delete('>')
        length = @hash[line.delete('>')].size
      end
      line << " # length=#{length}; type=dna" # Currently hardcoded to DNA.
    end
    line
  }
end

#sanitize_the_file?Boolean

#

sanitize_the_file?

#

Returns:

  • (Boolean)


1301
1302
1303
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1301

def sanitize_the_file?
  @internal_hash[:sanitize_the_file]
end

#saveObject

#

save

This method will save our FASTA file.

#


1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1174

def save
  if @input_file.nil?
    erev "The generic file #{sfile('foobar.fasta')}#{rev} "\
         "will be used."
    set_input_file('foobar.fasta')
  end
  into = @input_file
  what = @data.join("\n")
  erev 'Storing into '+sfile(into)+rev+'.'
  write_what_into(what, into)
  return into
end

#save_into_a_fasta_file(be_verbose = be_verbose? ) ⇒ Object Also known as: do_save_the_file

#

save_into_a_fasta_file

#


1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1061

def save_into_a_fasta_file(
    be_verbose = be_verbose?
  )
  case be_verbose
  when :be_verbose
    be_verbose = true
  end
  if @data
    what = @data.join("\n")
    into = 'standard.fasta'
    erev 'Saving into '+sfile(into)+rev+'.' if be_verbose
    write_what_into(what, into)
    return File.absolute_path(into) # And return the file we saved into.
  else
    opnerev 'No @data variable exists.'
  end
end

#save_the_file?Boolean

#

save_the_file?

#

Returns:

  • (Boolean)


1009
1010
1011
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1009

def save_the_file?
  @internal_hash[:save_the_file]
end

#sequenceObject Also known as: fasta_sequence, sequence?, body?, body, naseq, nucleotide_sequence, return_sequence, content?

#

sequence

This method will return the sequence, without any newlines. It is also called the “body” of a FASTA file.

#


1156
1157
1158
1159
1160
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1156

def sequence
  _ = @hash.values.first
  _.chomp! if _ and _.end_with?(N)
  return no_newlines(_)
end

#sequence_objectObject

#

sequence_object

This method will return a Sequence object.

Usage example:

x = Bioroebe.parse_fasta 'ls_orchid.fasta'
y = x.sequence_object # y is now an instance of Bioroebe::Sequence
#


1294
1295
1296
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1294

def sequence_object
  ::Bioroebe::Sequence.new(main_sequence?)
end

#sequences?Boolean Also known as: sequences, values

#

sequences?

This method will obtain all found sequences.

#

Returns:

  • (Boolean)


791
792
793
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 791

def sequences?
  @hash.values
end

#set_be_verbose_and_report_the_sequenceObject

#

set_be_verbose_and_report_the_sequence

#


863
864
865
866
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 863

def set_be_verbose_and_report_the_sequence
  set_be_verbose
  @internal_hash[:report_the_sequence] = true
end

#set_data(i = @input_file) ⇒ Object Also known as: set_sequence

#

set_data

This is the setter-method towards @data. It is no longer allowed to invoke set_input_file() since as of 12.06.2020. This means that you have to invoke that method prior to calling this method.

#


829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 829

def set_data(i = @input_file)
  # ======================================================================= #
  # The next line attempts to ensure that even an Array can be used
  # as input to that method.
  # ======================================================================= #
  i = [i].flatten.compact.first.to_s.dup
  if File.exist? i.to_s # First try to read in from a file.
    if be_verbose?
      opnerev "Will read from the file `#{sfile(i)}#{rev}`."
    end
    i = File.readlines(i)
    if @is_a_genbank_file
      selected = i.select {|line|
        line.start_with?('       ') and # such as: "       61 atggggcctg caatggggcc tgcaatgggg cctgca\n"
        (line.strip =~ /\d+/)
      }.map {|inner_line|
        inner_line.strip.delete(' 0123456789').strip.upcase
      }
      i = ["> genbank file"]+selected
    end
  end
  if i.nil? or i.empty?
    i = DEFAULT_FASTA
    opnerev 'No input was provided. Thus a default FASTA '\
            'sequence will be used instead.'
  end
  i = sanitize_data(i)
  i = i.split(N) if i.is_a? String
  @data = i
end

#set_input_file(i = nil) ⇒ Object Also known as: set_input_files

#

set_input_file

This method will be used to keep track of the input-file, from which we will read the dataset.

#


968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 968

def set_input_file(i = nil)
  if i.nil?
    # ===================================================================== #
    # First, we try to find a .fasta or .fa file in the current
    # directory. If we can find it, we will use that instead.
    # ===================================================================== #
    unless Dir['*.{fa,fasta}'].empty?
      file = Dir['*.{fa,fasta}'].first
      if be_verbose?
        result = 'A '
        if file.end_with? '.fasta'
          result < 'FASTA '
        end
        result << 'file was found in this directory ('+sfile(file)+').'
        opnerev result
        opnerev 'We will use it.'
      end
      i = file
    end
    unless Dir['*.{fa,fasta}'].empty?
      file = Dir['*.{fa,fasta}'].first
      if be_verbose?
        opnerev "We have found a file in this "\
                "directory (#{sfile(file)}#{rev})."
        opnerev 'We will use it.'
      end
      i = file
    end
  end
  if i and File.exist?(i)
    dataset = File.read(i)
    if dataset[0 .. ('LOCUS'.size - 1)] == 'LOCUS'
      @is_a_genbank_file = true
    end
  end
  @input_file = i
end

#set_round_to(i = :default) ⇒ Object

#

set_round_to

This will set to how many decimal numbers we will round to. This is mostly done for display-purposes, hence why the default is a fairly low value.

#


395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 395

def set_round_to(
    i = :default
  )
  case i
  # ======================================================================= #
  # === :default
  #
  # Since as of April 2021, the new default is 2, for rounding.
  # ======================================================================= #
  when :default
    i = DEFAULT_ROUND_TO
  end
  @internal_hash[:round_to] = i.to_i
end

#short_headers?Boolean

#

short_headers?

The short-headers are like the headers, but if a ‘ ’ token is found then the line will be truncated towards that first ‘ ’.

An example is:

sp|Q91FT8|234R_IIV6 Uncharacterized protein 234R OS=Invertebrate iridescent virus 6 OX=176652 GN=IIV6-234R PE=4 SV=1

This will be truncated towards

sp|Q91FT8|234R_IIV6

This could then be used to automatically rename FASTA files, for instance.

#

Returns:

  • (Boolean)


813
814
815
816
817
818
819
820
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 813

def short_headers?
  headers?.map {|entry|
    if entry.include? ' '
      entry = entry.split(' ').first
    end
    entry
  }
end

#show_helpObject

#

show_help (help tag)

This method will inform the user how this class may be used from the commandline.

Invocation example:

pfasta --help
#


1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1316

def show_help
  e
  eparse '  --size'
  eparse '  --also-show-the-sequence'
  eparse '  --header             # show the header as well (normally the '\
         'header is not shown)'
  eparse '  --limit=1000         # limit to show only the first 1000 '\
         'nucleotides; use'
  eparse '                       # any number that you need here'
  eparse '  --one-line           # show the sequence on one line only, '\
         'e. g. all newlines'
  eparse '                       # were removed'
  eparse '  --toprotein          # show the protein sequence as well '\
         '(assumes DNA or RNA'
  eparse '                       # .fasta file)'
  eparse '  --convert            # alias to the above ^^^'
  eparse '  --translate          # alias to the above ^^^'
  eparse '  --sanitize-the-file  # delete all " " characters '\
         'and upcase the content, of a'
  eparse '                       # .fasta file'
  e
end

#show_the_translated_protein_sequence?Boolean

#

show_the_translated_protein_sequence?

#

Returns:

  • (Boolean)


384
385
386
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 384

def show_the_translated_protein_sequence?
  @internal_hash[:show_the_translated_protein_sequence]
end

#simplify_headerObject

#

simplify_header

This method can be called to simplify the header. It will save into a .fasta file at once.

#


1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1107

def simplify_header
  _ = header?
  # ======================================================================= #
  # Next, simplify the header. We must start with checking for [] first,
  # because if there are any [] in the FASTA header then we can simplify
  # stuff at once.
  # ======================================================================= #
  if _.include?('[') and _.include?(']')
    _ = '> '+_.strip.scan(/\[.+\]/).flatten.first.delete('[]')+"\n"
  elsif _.include? ','
    _ = _[0 .. (_.index(',') - 1) ].strip
  end
  what = nil
  # ======================================================================= #
  # Next, designate where to store this file.
  # ======================================================================= #
  into = 'new_fasta_file.fasta'
  if overwrite_the_original_file?
    into = @input_file
  end
  if _.start_with? '>'
    what = _
  elsif _.include?('[') and _.include?(']') # For example: [Pan troglodytes]
    # ===================================================================== #
    # See rubular at:
    #
    #   https://rubular.com/r/aDjI0JwMOUlZzP
    #
    # ===================================================================== #
    what = "> "+_.scan(/\[(.+)\]/).flatten.first.to_s+"\n".dup 
  elsif _.include? 'Human'
    _scanned_result = _.scan(/(Human)/)
    what = "> "+$1.to_s.dup+"\n".dup
  else
    erev "Unsure what to do: #{steelblue(_)}"
  end
  if what and into
    what << raw_body?
    erev 'Storing into `'+sfile(into)+rev+'`.'
    write_what_into(what, into)
  end
end

#split_into_proper_sectionsObject

#

split_into_proper_sections

Split up into the fasta identifier, and the content.

#


1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1025

def split_into_proper_sections
  unless @data.to_s.include? '>'
    erev 'No ">" character was found in this dataset.'
    erev 'It is recommended to always have a > identifier '\
         'for the'
    erev 'FASTA format (such as in a .fasta or a .fa file).'
  end if be_verbose? # Ok, the input data includes >. We can proceed.
  @data.each { |line|
    # ===================================================================== #
    # === Handle the leading > FASTA identifier first
    # ===================================================================== #
    if line.start_with? '>' # leading identifier.
      @current_key = line[1..-1].chomp # Select all but the first character.
      @hash[@current_key] = ''.dup
    else
      line.delete!('_')
      unless @current_key
        @current_key = 'standard'
        @hash[@current_key] = ''.dup
      end
      # =================================================================== #
      # === Retain the newlines
      #
      # Here we may decide to get rid of newlines, but it is better to
      # NOT remove the newlines - that way we can simply save the
      # dataset again.
      # @hash[@current_key] << no_newlines(line)
      # =================================================================== #
      @hash[@current_key] << line
    end
  }
end

#type?Boolean

#

type?

#

Returns:

  • (Boolean)


1213
1214
1215
1216
1217
1218
1219
1220
1221
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 1213

def type?
  if is_the_sequence_a_polypeptide?
    :protein
  elsif is_this_sequence_a_polynucleotide_sequence?
    :dna_or_rna
  else
    :unknown
  end
end

#use_opn?Boolean

#

use_opn?

#

Returns:

  • (Boolean)


695
696
697
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 695

def use_opn?
  @use_opn
end

#we_may_exitObject

#

we_may_exit

#


490
491
492
# File 'lib/bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb', line 490

def we_may_exit
  @may_we_exit = true
end