ms-core 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .DS_Store
2
+ pkg/
3
+ rdoc/
4
+ backup/
5
+ config/
6
+ data/
7
+ doc/
8
+ *.swp
9
+ *.gemspec
data/History CHANGED
@@ -1,3 +1,11 @@
1
+ == version 0.0.3
2
+
3
+ * switched specs to spec/more
4
+ * added ability to decompress mzxml data
5
+
6
+ == version 0.0.2
7
+
8
+ * round function in Ms::Calc
1
9
 
2
10
  == version 0.0.1
3
11
 
data/MIT-LICENSE CHANGED
@@ -1,13 +1,23 @@
1
- Copyright (c) 2006, The University of Texas at Austin("U.T. Austin"). All rights reserved.
1
+ The MIT License
2
2
 
3
- Software by John T. Prince under the direction of Edward M. Marcotte.
3
+ Copyright (c) 2006-2010 University of Texas at Austin, Howard Hughes Medical Institute, Reagents of the University of Colorado, and Brigham Young University
4
4
 
5
- By using this software the USER indicates that he or she has read, understood and will comply with the following:
5
+ Authored by John T. Prince and Simon Chiang.
6
6
 
7
- U. T. Austin hereby grants USER permission to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of this software and its documentation for any purpose and without fee, provided that a full copy of this notice is included with the software and its documentation.
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
8
13
 
9
- Title to copyright this software and its associated documentation shall at all times remain with U. T. Austin. No right is granted to use in advertising, publicity or otherwise any trademark, service mark, or the name of U. T. Austin.
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
10
16
 
11
- This software and any associated documentation are provided "as is," and U. T. AUSTIN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESSED OR IMPLIED, INCLUDING THOSE OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, OR THAT USE OF THE SOFTWARE, MODIFICATIONS, OR ASSOCIATED DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER INTELLECTUAL PROPERTY RIGHTS OF A THIRD PARTY. U. T. Austin, The University of Texas System, its Regents, officers, and employees shall not be liable under any circumstances for any direct, indirect, special, incidental, or consequential damages with respect to any claim by USER or any third party on account of or arising from the use, or inability to use, this software or its associated documentation, even if U. T. Austin has been advised of the possibility of those damages.
12
-
13
- Submit software operation questions to: Edward M. Marcotte, Department of Chemistry and Biochemistry, U. T. Austin, Austin, Texas 78712.
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
data/README.rdoc CHANGED
@@ -1,27 +1,21 @@
1
- = {ms-core}[http://mspire.rubyforge.org/projects/ms-core]
1
+ = ms-core
2
2
 
3
- The core mspire[http://mspire.rubyforge.org] library for working with mass spectrometry proteomics data.
4
- Generally, This will be used as a dependency and won't be all that useful on
5
- its own.
3
+ The core mspire[http://jtprince.github.com/mspire] library for working with
4
+ mass spectrometry proteomics data. Generally, This will be used as a
5
+ dependency and won't be all that useful on its own.
6
6
 
7
7
  == Description
8
8
 
9
9
  * Github[http://github.com/jtprince/ms-core/tree/master]
10
- * Lighthouse[http://bahuvrihi.lighthouseapp.com/projects/16692-mspire/tickets]
11
10
  * {Google Group}[http://groups.google.com/group/mspire-forum]
12
11
 
13
12
  == Installation
14
13
 
15
- Available as a gem on RubyForge[http://rubyforge.org/projects/mspire]. Use:
16
-
17
- % gem install ms-mascot
14
+ % gem install ms-core
18
15
 
19
16
  Typically, it will be included as a dependency so it will be installed with
20
17
  another gem
21
18
 
22
- == Info
19
+ == Copyright
23
20
 
24
- Copyright (c) 2006-2008, Regents of the University of Colorado and HHMI
25
- Developers:: {Simon Chiang}[http://bahuvrihi.wordpress.com], {Biomolecular Structure Program}[http://biomol.uchsc.edu/], {Hansen Lab}[http://hsc-proteomics.uchsc.edu/hansenlab/], John Prince, {Edward Marcotte Lab}[http://polaris.icmb.utexas.edu/home.html], {Natalie Ahn Lab}[http://www.colorado.edu/chem/people/ahnn.html], {Howard Hughes Medical Institute}[http://www.hhmi.org/], {BYU Dept. of Chemistry and Biochemistry}[http://www.chem.byu.edu/]
26
- Support:: CU Denver School of Medicine Deans Academic Enrichment Fund, HHMI
27
- License:: {MIT-Style}[link:files/MIT-LICENSE.html]
21
+ MIT-LICENSE
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'jeweler'
4
+ require 'rcov/rcovtask'
5
+ require 'rake/rdoctask'
6
+ require 'rake/testtask'
7
+
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "ms-core"
10
+ gem.summary = "basic, shared functionality for mspire libraries"
11
+ gem.description = "basic, shared functionality for mspire libraries"
12
+ gem.email = "jtprince@gmail.com"
13
+ gem.homepage = "http://github.com/jtprince/ms-core/rdoc"
14
+ gem.authors = ["Simon Chiang", "John Prince"]
15
+ # dependencies:
16
+ gem.add_dependency("molecules", ">= 0.2.0")
17
+
18
+ # dev dependencies:
19
+ gem.add_development_dependency "spec-more", ">= 0"
20
+ end
21
+
22
+ Rake::TestTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.pattern = 'spec/**/*_spec.rb'
25
+ spec.verbose = true
26
+ end
27
+
28
+ Rcov::RcovTask.new do |spec|
29
+ spec.libs << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.verbose = true
32
+ end
33
+
34
+ task :default => :spec
35
+
36
+ Rake::RDocTask.new do |rdoc|
37
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
38
+
39
+ rdoc.rdoc_dir = 'rdoc'
40
+ rdoc.title = "ms-core #{version}"
41
+ rdoc.rdoc_files.include('README*')
42
+ rdoc.rdoc_files.include('lib/**/*.rb')
43
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.4
@@ -9,51 +9,51 @@ module Ms
9
9
  Interleaved.new(unresolved_data, n=2)
10
10
  end
11
11
 
12
- # An Interleaved data array lazily evaluates it's unresolved data as
13
- # an interleaved array of n members. The unresolved data is evaluated
12
+ # An Interleaved data array lazily evaluates it's unresolved data as
13
+ # an interleaved array of n members. The unresolved data is evaluated
14
14
  # into an array using to_a.
15
15
  #
16
16
  # i = Ms::Data::Interleaved.new([1,4,2,5,3,6])
17
- # i.unresolved_data # => [1,4,2,5,3,6]
17
+ # i.unresolved_data # => [1,4,2,5,3,6]
18
18
  # i.data # => []
19
19
  # i[0] # => [1,2,3]
20
- # i[1] # => [4,5,6]
20
+ # i[1] # => [4,5,6]
21
21
  # i.data # => [[1,2,3], [4,5,6]]
22
22
  #
23
- class Interleaved < Simple
24
- attr_reader :n
25
-
26
- def initialize(unresolved_data, n=2)
27
- @n = 2
28
- super(unresolved_data)
29
- end
30
-
31
- def [](index)
32
- resolve.data[index]
33
- end
34
-
35
- def resolved?
36
- !@data.empty?
37
- end
23
+ class Interleaved < Simple
24
+ attr_reader :n
25
+
26
+ def initialize(unresolved_data, n=2)
27
+ @n = 2
28
+ super(unresolved_data)
29
+ end
30
+
31
+ def [](index)
32
+ resolve.data[index]
33
+ end
34
+
35
+ def resolved?
36
+ !@data.empty?
37
+ end
38
38
 
39
- def resolve
40
- return(self) if resolved?
39
+ def resolve
40
+ return(self) if resolved?
41
41
 
42
42
  unresolved_data = @unresolved_data.to_a
43
43
 
44
44
  unless unresolved_data.length % n == 0
45
45
  raise ArgumentError, "interleaved data must have a number of elements evenly divisible by n (#{n})"
46
46
  end
47
-
47
+
48
48
  n.times { @data << [] }
49
49
  map = @data * (unresolved_data.length/n)
50
50
 
51
51
  unresolved_data.each_with_index do |item, i|
52
52
  map[i] << item
53
53
  end
54
-
54
+
55
55
  self
56
- end
56
+ end
57
57
 
58
58
  end
59
59
  end
@@ -1,3 +1,5 @@
1
+ require 'zlib'
2
+
1
3
  module Ms
2
4
  module Data
3
5
 
@@ -40,12 +42,16 @@ module Ms
40
42
  # Indicates a decoding format, may be false to unpack string
41
43
  # without decoding.
42
44
  attr_reader :decode_format
45
+
46
+ # boolean: whether the peaks string is zlib compressed
47
+ attr_reader :compressed
43
48
 
44
- def initialize(io, start_index=io.pos, num_bytes=nil, unpack_format=NETWORK_FLOAT, decode_format=BASE_64)
49
+ def initialize(io, start_index=io.pos, num_bytes=nil, unpack_format=NETWORK_FLOAT, compressed=false, decode_format=BASE_64)
45
50
  @io = io
46
51
  @start_index = start_index
47
52
  @num_bytes = num_bytes
48
53
  @unpack_format = unpack_format
54
+ @compressed = compressed
49
55
  @decode_format = decode_format
50
56
  end
51
57
 
@@ -61,13 +67,15 @@ module Ms
61
67
  def reset
62
68
  @array = nil
63
69
  end
64
-
70
+
65
71
  # Reads string and unpacks using decode_format and unpack_code. The
66
72
  # array is cached internally; to re-read the array, use reset.
67
73
  def to_a
68
- @array ||= (decode_format ? string.unpack(decode_format)[0] : string).unpack(unpack_format)
74
+ return @array if @array
75
+ decoded = decode_format ? string.unpack(decode_format)[0] : string
76
+ uncompressed = @compressed ? Zlib::Inflate.inflate(decoded) : decoded
77
+ uncompressed.unpack(unpack_format)
69
78
  end
70
-
71
79
  end
72
80
  end
73
81
  end
@@ -7,9 +7,9 @@ module Ms
7
7
  # LazyString is a LazyIO initialized from a string, which is converted into
8
8
  # a StringIO.
9
9
  class LazyString < LazyIO
10
- def initialize(string, unpack_format=NETWORK_FLOAT, decode_format=BASE_64)
11
- super(StringIO.new(string), 0, string.length, unpack_format, decode_format)
10
+ def initialize(string, unpack_format=NETWORK_FLOAT, compression=false, decode_format=BASE_64)
11
+ super(StringIO.new(string), 0, string.length, unpack_format, compression, decode_format)
12
12
  end
13
13
  end
14
14
  end
15
- end
15
+ end
data/lib/ms/spectrum.rb CHANGED
@@ -5,12 +5,11 @@ module Ms
5
5
  # The underlying data store.
6
6
  attr_reader :data
7
7
 
8
- # Associated headers
9
- attr_reader :headers
10
-
11
- def initialize(data, headers={})
8
+ # data takes an array: [mzs, intensities]
9
+ # @return [Ms::Spectrum]
10
+ # @param [Array] data two element array of mzs and intensities
11
+ def initialize(data)
12
12
  @data = data
13
- @headers = headers
14
13
  end
15
14
 
16
15
  def self.from_peaks(ar_of_doublets)
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper.rb"
2
+ require 'ms/calc'
3
+
4
+ describe 'Ms::Calc - calculating ppm tolerances' do
5
+ extend Ms::Calc
6
+
7
+ it "returns the ppm tolerance at the specified mass, ppm" do
8
+ ppm_tol_at(100, 100).is 0.01
9
+ ppm_tol_at(1000, 100).is 0.1
10
+ ppm_tol_at(1000, 10).is 0.01
11
+ end
12
+
13
+ it "works for any numeric inputs" do
14
+ ppm_tol_at(100, 100).is 0.01
15
+ ppm_tol_at(100.0, 100.0).is 0.01
16
+ ppm_tol_at(1e2, 1e2).is 0.01
17
+ end
18
+
19
+ it "should return a span of ppm_tol_at centered on the specified mass" do
20
+ ppm_span_at(100, 100).is [99.99, 100.01]
21
+ ppm_span_at(1000, 100).is [999.9, 1000.1]
22
+ ppm_span_at(1000, 10).is [999.99, 1000.01]
23
+ end
24
+
25
+ it "should work for any numeric inputs" do
26
+ ppm_span_at(100, 100).is [99.99, 100.01]
27
+ ppm_span_at(100.0, 100.0).is [99.99, 100.01]
28
+ ppm_span_at(1e2, 1e2).is [99.99, 100.01]
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper.rb"
2
+ require 'ms/data'
3
+
4
+ describe "Data.new" do
5
+ it "satisfies documentation" do
6
+ s = Ms::Data.new([[1,2,3], [4,5,6]], :simple)
7
+ s.resolve.data.is [[1,2,3], [4,5,6]]
8
+
9
+ t = Ms::Data.new([[1,4],[2,5],[3,6]], :transposed)
10
+ t.resolve.data.is [[1,2,3], [4,5,6]]
11
+
12
+ i = Ms::Data.new([1,4,2,5,3,6], :interleaved)
13
+ i.resolve.data.is [[1,2,3], [4,5,6]]
14
+
15
+ str = [[1,4,2,5,3,6].pack("g*")].pack("m")
16
+ unresolved_data = Ms::Data::LazyString.new(str)
17
+
18
+ i = Ms::Data.new(unresolved_data, :interleaved)
19
+ i.resolve.data.is [[1,2,3], [4,5,6]]
20
+ end
21
+
22
+ it "should return a new data of the specified type" do
23
+ data = Ms::Data.new([[1,2,3], [4,5,6]])
24
+ data.class.is Ms::Data::Simple
25
+
26
+ data = Ms::Data.new([[1,2,3], [4,5,6]], :simple)
27
+ data.class.is Ms::Data::Simple
28
+
29
+ data = Ms::Data.new([1,4,2,5,3,6], :interleaved)
30
+ data.class.is Ms::Data::Interleaved
31
+
32
+ data = Ms::Data.new([[1,4],[2,5],[3,6]], :transposed)
33
+ data.class.is Ms::Data::Transposed
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper.rb"
2
+ require 'ms/support/binary_search'
3
+
4
+ describe 'binary searching' do
5
+ extend Ms::Support::BinarySearch
6
+
7
+ it "satisfies documentation" do
8
+ search_first(%w(a b c c c d e f)) {|x| x <=> "c"}.is 2
9
+ search_last(%w(a b c c c d e f)) {|x| x <=> "c"}.is 4
10
+ search_first(%w(a b c e f)) {|x| x <=> "c"}.is 2
11
+ search_first(%w(a b e f)) {|x| x <=> "c"}.is nil
12
+ search_last(%w(a b e f)) {|x| x <=> "c"}.is nil
13
+ search_lower_boundary(%w(a b e f)) {|x| x <=> "c"}.is 2
14
+ search_upper_boundary(%w(a b e f)) {|x| x <=> "c"}.is 2
15
+ search_range(%w(a b c c c d e f)) {|x| x <=> "c"}.is(2...5)
16
+ search_range(%w(a b c d e f)) {|x| x <=> "c"}.is(2...3)
17
+ search_range(%w(a b d e f)) {|x| x <=> "c"}.is(2...2)
18
+ end
19
+
20
+ it "is fast" do
21
+ start = Time.now
22
+ if ENV['BENCHMARK']
23
+ Benchmark.bm(25) do |x|
24
+ array = (0..100000).to_a
25
+
26
+ x.report("100k/1kx search_range") do
27
+ 1000.times do
28
+ search_range(array) {|x| x <=> 88 }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ true.is true
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'spec/more'
3
+ require 'benchmark'
4
+
5
+ Bacon.summary_on_exit
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ms-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 4
9
+ version: 0.0.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - Simon Chiang
@@ -10,54 +15,50 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2009-09-08 00:00:00 -06:00
18
+ date: 2010-07-08 00:00:00 -06:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: molecules
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 2
31
+ - 0
24
32
  version: 0.2.0
25
- version:
33
+ type: :runtime
34
+ version_requirements: *id001
26
35
  - !ruby/object:Gem::Dependency
27
- name: tap
28
- type: :development
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
36
+ name: spec-more
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
31
39
  requirements:
32
40
  - - ">="
33
41
  - !ruby/object:Gem::Version
34
- version: 0.11.2
35
- version:
36
- - !ruby/object:Gem::Dependency
37
- name: minitest
42
+ segments:
43
+ - 0
44
+ version: "0"
38
45
  type: :development
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: 1.3.0
45
- version:
46
- description:
47
- email:
48
- - jtprince@gmail.com
46
+ version_requirements: *id002
47
+ description: basic, shared functionality for mspire libraries
48
+ email: jtprince@gmail.com
49
49
  executables: []
50
50
 
51
51
  extensions: []
52
52
 
53
53
  extra_rdoc_files:
54
54
  - README.rdoc
55
- - MIT-LICENSE
56
- - History
57
55
  files:
56
+ - .gitignore
57
+ - History
58
58
  - MIT-LICENSE
59
59
  - README.rdoc
60
- - History
60
+ - Rakefile
61
+ - VERSION
61
62
  - lib/ms.rb
62
63
  - lib/ms/calc.rb
63
64
  - lib/ms/data.rb
@@ -74,33 +75,42 @@ files:
74
75
  - lib/ms/mass/aa.rb
75
76
  - lib/ms/spectrum.rb
76
77
  - lib/ms/support/binary_search.rb
78
+ - spec/ms/calc_spec.rb
79
+ - spec/ms/data_spec.rb
80
+ - spec/ms/support/binary_search_spec.rb
81
+ - spec/spec_helper.rb
77
82
  has_rdoc: true
78
- homepage: http://mspire.rubyforge.org/ms-core/
83
+ homepage: http://github.com/jtprince/ms-core/rdoc
79
84
  licenses: []
80
85
 
81
86
  post_install_message:
82
- rdoc_options: []
83
-
87
+ rdoc_options:
88
+ - --charset=UTF-8
84
89
  require_paths:
85
90
  - lib
86
91
  required_ruby_version: !ruby/object:Gem::Requirement
87
92
  requirements:
88
93
  - - ">="
89
94
  - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
90
97
  version: "0"
91
- version:
92
98
  required_rubygems_version: !ruby/object:Gem::Requirement
93
99
  requirements:
94
100
  - - ">="
95
101
  - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
96
104
  version: "0"
97
- version:
98
105
  requirements: []
99
106
 
100
- rubyforge_project: mspire
101
- rubygems_version: 1.3.2
107
+ rubyforge_project:
108
+ rubygems_version: 1.3.6
102
109
  signing_key:
103
110
  specification_version: 3
104
111
  summary: basic, shared functionality for mspire libraries
105
- test_files: []
106
-
112
+ test_files:
113
+ - spec/ms/support/binary_search_spec.rb
114
+ - spec/ms/calc_spec.rb
115
+ - spec/ms/data_spec.rb
116
+ - spec/spec_helper.rb