bahuvrihi-ms-data_explorer 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2006-2008, Regents of the University of Colorado.
2
+ Developer:: Simon Chiang, Biomolecular Structure Program, Hansen Lab
3
+ Support:: CU Denver School of Medicine Deans Academic Enrichment Fund
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
+ software and associated documentation files (the "Software"), to deal in the Software
7
+ without restriction, including without limitation the rights to use, copy, modify, merge,
8
+ publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9
+ to whom the Software is furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or
12
+ substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,76 @@
1
+ require 'ms/data_explorer'
2
+
3
+ module Ms
4
+ module DataExplorer
5
+ module Convert
6
+
7
+ # :startdoc::manifest converts .dat file to ascii text
8
+ #
9
+ # Uses the Applied Biosystems DataExplorer software to extract an ASCII spectrum
10
+ # from a '.dat' file. Each input file should be a dat file; ascii files will be placed in
11
+ # the output directory, with a '.txt' extension (by default the output directory is
12
+ # the same directory as the input file).
13
+ #
14
+ # DatToAscii is based on the getdeascii.pl script.
15
+ class DatToAscii < Tap::FileTask
16
+ include DataExplorer
17
+
18
+ config :output_dir, nil, &c.string_or_nil # the output dir
19
+
20
+ def process(*input_files)
21
+ @updated_files = []
22
+ input_files.collect do |input_file|
23
+ check_terminate
24
+
25
+ output_file = if output_dir
26
+ File.join(output_dir, basename(input_file, ".txt"))
27
+ else
28
+ input_file.chomp(File.extname(input_file)) + ".txt"
29
+ end
30
+
31
+ if uptodate?(output_file, input_file)
32
+ log_basename(:skip, input_file)
33
+ else
34
+ log_basename :ascii, input_file
35
+
36
+ prepare output_file
37
+
38
+ # This block of code raises an unexpected WIN32OLERuntimeError upon the 'close'
39
+ # operation. The error may be XP-related or DataExplorer 4.0-related as it is not raised on a
40
+ # Win2k computer using DataExplorer 4.9.
41
+ #
42
+ # I believe that the issue is with XP, however, due to articles I read online
43
+ # (see http://support.microsoft.com/kb/289737) as well as the fact that if you
44
+ # enact the open-close routine in irb multiple times, it will only raise the 0x80010105
45
+ # error the first time for any given document.
46
+ begin
47
+ spectrum = data_explorer.documents.open(File.expand_path(input_file))
48
+ spectrum.specview.exportasciispectrum(File.expand_path(output_file))
49
+ spectrum.close
50
+ rescue WIN32OLERuntimeError
51
+ # TODO -- add debug logging for this...
52
+ end
53
+
54
+ @updated_files << output_file
55
+ end
56
+
57
+ output_file
58
+ end
59
+ end
60
+
61
+ protected
62
+
63
+ def after_execute
64
+ close_data_explorer
65
+
66
+ # Ensure de has time to close, then make sure all the output files are dated later than the inputs
67
+ # This rigmarole is necessary because the output file is created while the input file is open in
68
+ # DataExplorer, and apparently DataExplorer doesn't release the file until it completely exits.
69
+ sleep 1 unless @updated_files.empty?
70
+ @updated_files.each {|file| FileUtils.touch(file) }
71
+ @updated_files = nil
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,34 @@
1
+ require 'ms/data'
2
+ require 'ms/spectrum'
3
+
4
+ module Ms
5
+ module DataExplorer
6
+
7
+ # ::format (.dat)
8
+ #
9
+ module Format
10
+ class Ascii < Spectrum
11
+ class << self
12
+ def parse(str)
13
+ headers = {}
14
+ data = []
15
+
16
+ str.split(/\r?\n/).each do |line|
17
+ line = line.strip
18
+ next if line.empty?
19
+
20
+ key, value = line.split(/\s+/, 2)
21
+ if key =~ /^\d/
22
+ data << [key.to_f, value.to_f]
23
+ else
24
+ headers[key] = value
25
+ end
26
+ end
27
+
28
+ new(Data.new(data, :transposed), headers)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,54 @@
1
+ require 'win32ole'
2
+ require 'Win32API'
3
+
4
+ module Ms
5
+ module DataExplorer
6
+ @@data_explorer_instance = nil
7
+
8
+ def data_explorer
9
+ @@data_explorer_instance = WIN32OLE.new('DataExplorer.Application') unless @@data_explorer_instance
10
+ @@data_explorer_instance
11
+ end
12
+
13
+ def close_data_explorer
14
+ if @@data_explorer_instance
15
+ data_explorer.quit
16
+ data_explorer.ole_free
17
+ @@data_explorer_instance = nil
18
+ end
19
+ end
20
+
21
+ def data_explorer_version
22
+ # Gets the version information for a windows executable
23
+ # trivially modified from: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/161140
24
+ #fname = 'D:\ruby\bin\ruby.exe'
25
+ fname = data_explorer.fullname
26
+ get_file_version_info_size = Win32API.new('Version', 'GetFileVersionInfoSize', 'PP', 'L')
27
+ get_file_version_info = Win32API.new('Version', 'GetFileVersionInfo', 'PLLP', 'L')
28
+ ver_query_value = Win32API.new('Version', 'VerQueryValue', 'PPPP', 'I')
29
+ memcpy = Win32API.new('msvcrt', 'memcpy', 'PLL', 'L')
30
+
31
+ addr = "\0"*4
32
+
33
+ v_info_sz = get_file_version_info_size.call(fname, addr)
34
+
35
+ raise 'GFVIS failed' if v_info_sz == 0
36
+ v_info = "\0"*v_info_sz
37
+ get_file_version_info.call(fname, 0, v_info_sz, v_info)
38
+
39
+ v_val_sz = "\0"*4
40
+ ver_query_value.call(v_info, '\\', addr, v_val_sz)
41
+ v_bufsz = v_val_sz.unpack('L')[0]
42
+ v_buf = "\0" * v_bufsz
43
+ v_src = addr.unpack('L')[0]
44
+ ret = memcpy.call(v_buf, v_src, v_bufsz)
45
+ raise 'memcpy failed' if ret == 0
46
+
47
+ raise 'Oops' unless v_buf[0, 4].unpack('L')[0] == 0xFEEF04BD
48
+ #p v_buf[0x08, 8].unpack('S*').values_at(1,0,3,2) #-> [1, 8, 2, 0]
49
+ #p v_buf[0x10, 8].unpack('S*').values_at(1,0,3,2) #-> [1, 8, 2, 0]
50
+ v_buf[0x08, 8].unpack('S*').values_at(1,0,3,2).join('.')
51
+ end
52
+
53
+ end
54
+ end
data/tap.yml ADDED
File without changes
@@ -0,0 +1,5 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
2
+
3
+ # runs all subsets (see Tap::Test::SubsetMethods)
4
+ ENV["ALL"] = "true"
5
+ Dir.glob("./**/*_test.rb").each {|test| require test}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bahuvrihi-ms-data_explorer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Chiang
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-13 00:00:00 -07:00
12
+ date: 2008-10-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,16 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 0.10.0
22
+ version: "0.11"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: mspire
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: "0.5"
23
32
  version:
24
33
  description:
25
34
  email: simon.a.chiang@gmail.com
@@ -32,6 +41,7 @@ extra_rdoc_files:
32
41
  files:
33
42
  - lib/ms/data_explorer.rb
34
43
  - lib/ms/data_explorer/convert/dat_to_ascii.rb
44
+ - lib/ms/data_explorer/format/ascii.rb
35
45
  - tap.yml
36
46
  - MIT-LICENSE
37
47
  has_rdoc: true