Class: Bioroebe::ElectronMicroscopy::ReadFileXMD

Inherits:
CommandlineApplication show all
Defined in:
lib/bioroebe/electron_microscopy/read_file_xmd.rb

Overview

Bioroebe::ElectronMicroscopy::ReadFileXMD

Constant Summary

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, #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, #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, #use_opn?, #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(this_xmd_file = nil, run_already = true) ⇒ ReadFileXMD

#

initialize

The first argument passed to this class here should be the .xmd file in question.

#


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 31

def initialize(
    this_xmd_file = nil,
    run_already   = true
  )
  reset # Set to default.
  set_this_xmd_file(this_xmd_file)
  case run_already
  when :dont_run_yet
    run_already = false
  end
  run if run_already
end

Class Method Details

.sanitize_header(i) ⇒ Object

#

ReadFileXMD.sanitize_header

Pass an array to us here.

#


262
263
264
265
266
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 262

def self.sanitize_header(i)
  _ = new(nil, :dont_run_yet)
  result = _.sanitize_header(i)
  return result
end

Instance Method Details

#_Object

#

_

#


69
70
71
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 69

def _
  @this_xmd_file
end

#bodyBoolean

#

body?

The body of the .xmd file.

#

body

Returns:

  • (Boolean)


148
149
150
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 148

def body?
  @body
end

#body?Boolean

#

body?

#

Returns:

  • (Boolean)


146
147
148
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 146

def body?
  @body
end

#file?Boolean

#

file?

This gives us colourized output.

#

Returns:

  • (Boolean)


128
129
130
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 128

def file?
  sfile(_)
end

#header?Boolean Also known as: header

#

header?

#

Returns:

  • (Boolean)


119
120
121
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 119

def header?
  @header
end

#reportObject

#

report (report tag)

#


236
237
238
239
240
241
242
243
244
245
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 236

def report
  opnerev 'The header subsection of this .xmd file is:'
  pp @header
  if @body
    opnerev 'The body subsection has '+@body.size.to_s+' entries.'
  else
    opnerev 'No body has been found. Has a .xmd file been '\
            'passed to this class?'
  end
end

#report_what_we_will_doObject

#

report_what_we_will_do

#


135
136
137
138
139
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 135

def report_what_we_will_do
  if be_verbose?
    opnerev "We will next read in the data from the file #{file?}"
  end
end

#resetObject

#

reset

#


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 47

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @header
  # ======================================================================= #
  @header = nil
  # ======================================================================= #
  # === @body
  # ======================================================================= #
  @body   = nil
  set_be_verbose
  # ======================================================================= #
  # === @dataset
  # ======================================================================= #
  @dataset = nil
  set_prepend_this_to_the_mrc_file_path
end

#runObject

#

run

#


250
251
252
253
254
255
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 250

def run
  report_what_we_will_do
  try_to_determine_the_header
  try_to_determine_the_body
  sanitize_body
end

#sanitize_bodyObject

#

sanitize_body

This method will do two things:

(1) It will chop off the trailing 1 (if it can be found)
(2) It will chop off the leading string that includes the
    @ character.
(3) It will eliminate an existing trailing newlines, and
    then .strip on the result.
(4) It will also replace the relative path to the .stk file
    with an absolute path. (This is experimental for now)
#


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
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 164

def sanitize_body
  # ======================================================================= #
  # @body is an Array.
  # ======================================================================= #
  @body.map! {|entry|
    entry = entry.dup if entry.frozen?
    entry.chomp!
    entry = entry[(entry.index('@')+1)..-1] if entry.include? '@'
    entry.strip!
    entry.chop! if entry.end_with? '1'
    # ===================================================================== #
    # Next, we modify the path to the .mrc file in question.
    # The line may look like so: "1_36kx_15.stk ./1_36kx_15.mrc"
    # ===================================================================== #
    if entry.include? '.mrc'
      entry.sub!(/\.\/(.+\.mrc)/,
        @prepend_this_to_the_mrc_file_path+'\\1')
    end
    # ===================================================================== #
    # if entry.include?('.stk') and ! entry.start_with?('/home')
    #   entry[0,0] = '/home/kumar/Robert/'
    # end
    # ===================================================================== #
    entry.strip!
    entry
  } if @body
end

#sanitize_header(i = @header) ⇒ Object

#

sanitize_header

Next we will sanitize the @header variable.

#


212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 212

def sanitize_header(i = @header)
  if i.is_a? String
    i = i.split(N)
  end
  i[3..-1] = '
_rlnImageName #1
_rlnMicrographName #2
_rlnCoordinateX #3
_rlnCoordinateY #4
'
  @header = i
  return i
end

#set_prepend_this_to_the_mrc_file_path(i = '') ⇒ Object Also known as: set_path_to_mrc_file

#

set_prepend_this_to_the_mrc_file_path

#


195
196
197
198
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 195

def set_prepend_this_to_the_mrc_file_path(i = '')
  i = i.to_s.dup
  @prepend_this_to_the_mrc_file_path = i
end

#set_this_xmd_file(i) ⇒ Object

#

set_this_xmd_file

#


76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 76

def set_this_xmd_file(i)
  i = i.first if i.is_a? Array
  i = i.to_s
  @this_xmd_file = i
  # Next, check if the file exists:
  if File.exist? @this_xmd_file
    @dataset = File.readlines(@this_xmd_file)
  else
    unless @this_xmd_file.empty?
      opnerev 'The file at '+sfile(_)+rev+' does not exist.'
    end
  end
end

#show_bodyObject

#

show_body

#


229
230
231
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 229

def show_body
  pp body?
end

#this_xmd_file?Boolean Also known as: this_xmd_file

#

this_xmd_file?

#

Returns:

  • (Boolean)


93
94
95
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 93

def this_xmd_file?
  @this_xmd_file
end

#try_to_determine_the_bodyObject

#

try_to_determine_the_body

#


110
111
112
113
114
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 110

def try_to_determine_the_body
  if @dataset
    @body = @dataset[9..-1] # Should be an Array.
  end
end

#try_to_determine_the_headerObject

#

try_to_determine_the_header

#


100
101
102
103
104
105
# File 'lib/bioroebe/electron_microscopy/read_file_xmd.rb', line 100

def try_to_determine_the_header
  if @dataset
    @header = @dataset[0,9]
    sanitize_header
  end
end