Class: Ms::DataExplorer::Convert::DatToAscii

Inherits:
Tap::Tasks::FileTask
  • Object
show all
Includes:
Ms::DataExplorer
Defined in:
lib/ms/data_explorer/convert/dat_to_ascii.rb

Overview

:startdoc::task converts .dat file to ascii text

Uses the Applied Biosystems DataExplorer software to extract an ASCII spectrum from a ‘.dat’ file. Each input file should be a dat file; ascii files will be placed in the output directory, with a ‘.txt’ extension (by default the output directory is the same directory as the input file).

DatToAscii is based on the getdeascii.pl script.

Instance Method Summary collapse

Methods included from Ms::DataExplorer

#close_data_explorer, #data_explorer, #data_explorer_version

Instance Method Details

#call(*args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ms/data_explorer/convert/dat_to_ascii.rb', line 25

def call(*args)
  @updated_files = []
  
  results = super
  close_data_explorer

  # Ensure de has time to close, then make sure all the output files are dated later than the inputs
  # This rigmarole is necessary because the output file is created while the input file is open in
  # DataExplorer, and apparently DataExplorer doesn't release the file until it completely exits.
  sleep 1 unless @updated_files.empty?
  @updated_files.each {|file| FileUtils.touch(file) }
  @updated_files = nil
  results
end

#process(*input_files) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ms/data_explorer/convert/dat_to_ascii.rb', line 40

def process(*input_files)
  input_files.collect do |input_file|
    app.check_terminate
    
    output_file = if output_dir
      File.join(output_dir, basename(input_file, ".txt"))
    else
      input_file.chomp(File.extname(input_file)) + ".txt"
    end
  
    if uptodate?(output_file, input_file)
      log_basename(:skip, input_file)
    else
      log_basename :ascii, input_file
      
      prepare output_file

      # This block of code raises an unexpected WIN32OLERuntimeError upon the 'close'
      # operation.  The error may be XP-related or DataExplorer 4.0-related as it is not raised on a 
      # Win2k computer using DataExplorer 4.9.  
      # 
      # I believe that the issue is with XP, however, due to articles I read online 
      # (see http://support.microsoft.com/kb/289737) as well as the fact that if you 
      # enact the open-close routine in irb multiple times, it will only raise the 0x80010105
      # error the first time for any given document.
      begin
        spectrum = data_explorer.documents.open(File.expand_path(input_file))
        spectrum.specview.exportasciispectrum(File.expand_path(output_file))
        spectrum.close
      rescue WIN32OLERuntimeError
        # TODO -- add debug logging for this...
      end

      updated_files << output_file
    end
  
    output_file
  end
end

#updated_filesObject



21
22
23
# File 'lib/ms/data_explorer/convert/dat_to_ascii.rb', line 21

def updated_files
  @updated_files ||= []
end