Class: Bioroebe::FastaParser

Inherits:
Base
  • Object
show all
Defined in:
lib/bioroebe/fasta_and_fastq/fasta_parser.rb

Overview

Bioroebe::FastaParser

Constant Summary collapse

MAIN_URL =
#

MAIN_URL

#
'https://www.ncbi.nlm.nih.gov/'
BASE_URL =
#

BASE_URL

#
MAIN_URL+'protein/'
APPEND_THIS =
#

APPEND_THIS

#
'?report=fasta'
DEFAULT_URL =
#

DEFAULT_URL

#
340622821
DISPLAY_HTML_RESULT =
#

DISPLAY_HTML_RESULT

#
true
SAVE_HTML_FILE_HERE =
#

SAVE_HTML_FILE_HERE

#
::Bioroebe.log_dir?+
'SavedFasta.html'

Constants inherited from Base

Base::NAMESPACE

Constants included from ColoursForBase

ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

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(url = DEFAULT_URL, run_already = true) ⇒ FastaParser

#

initialize

#


58
59
60
61
62
63
64
65
# File 'lib/bioroebe/fasta_and_fastq/fasta_parser.rb', line 58

def initialize(
    url         = DEFAULT_URL,
    run_already = true
  )
  reset
  set_full_url(url)
  run if run_already
end

Instance Method Details

#feedback_help_then_exitObject

#

feedback_help_then_exit

#


107
108
109
110
111
112
113
# File 'lib/bioroebe/fasta_and_fastq/fasta_parser.rb', line 107

def feedback_help_then_exit
  e 'The URL is:'
  e
  e "  #{simp(MAIN_URL)}"
  e
  exit(0)
end

#read_remote_urlObject

#

read_remote_url

#


118
119
120
121
122
# File 'lib/bioroebe/fasta_and_fastq/fasta_parser.rb', line 118

def read_remote_url
  @result = open(@url).read
  sanitize_result
  e @result if DISPLAY_HTML_RESULT
end

#report_url_usedObject

#

report_url_used

#


134
135
136
137
# File 'lib/bioroebe/fasta_and_fastq/fasta_parser.rb', line 134

def report_url_used
  e 'We used this URL:'
  e "  #{simp(@url)}"
end

#resetObject

#

reset

#


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bioroebe/fasta_and_fastq/fasta_parser.rb', line 70

def reset
  super()
  # ======================================================================= #
  # === @result
  # ======================================================================= #
  @result = nil
  # ======================================================================= #
  # === @url
  # ======================================================================= #
  @url = nil
  # ======================================================================= #
  # === @save_html_file_here
  # ======================================================================= #
  @save_html_file_here = SAVE_HTML_FILE_HERE
end

#runObject

#

run (run tag)

#


157
158
159
160
161
# File 'lib/bioroebe/fasta_and_fastq/fasta_parser.rb', line 157

def run
  read_remote_url
  report_url_used
  save_html_file
end

#sanitize_resultObject

#

sanitize_result

#


127
128
129
# File 'lib/bioroebe/fasta_and_fastq/fasta_parser.rb', line 127

def sanitize_result # make @result look better.
  @result.squeeze!(' ')
end

#save_html_fileObject

#

save_html_file

#


142
143
144
145
146
147
148
149
150
151
152
# File 'lib/bioroebe/fasta_and_fastq/fasta_parser.rb', line 142

def save_html_file
  if @result # Save the HTML data.
    unless Dir.exist?(File.basename(@save_html_file_here))
      @save_html_file_here = File.expand_path('~')+'/'+
        File.basename(SAVE_HTML_FILE_HERE)
    end
    e 'We will save the HTML file here:'
    e "  #{simp(@save_html_file_here)}"
    save_file(@result, @save_html_file_here,'w+')
  end
end

#set_full_url(i = DEFAULT_URL, be_verbose = true) ⇒ Object

#

set_full_url

#


89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/bioroebe/fasta_and_fastq/fasta_parser.rb', line 89

def set_full_url(
    i          = DEFAULT_URL,
    be_verbose = true
  )
  case i # case tag
  when nil
    i = DEFAULT_URL
  when 'help','help?'
    feedback_help_then_exit
  end
  i = BASE_URL+i.to_s+APPEND_THIS
  @url = i
  e 'Setting to use this URL: '+sfancy(@url) if be_verbose
end