mspire 0.6.7 → 0.6.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +5 -0
- data/VERSION +1 -1
- data/lib/cv/param.rb +25 -5
- data/lib/cv/referenceable_param_group_ref.rb +13 -0
- data/lib/cv.rb +3 -1
- data/lib/ms/cv/param.rb +19 -24
- data/lib/ms/cv/paramable.rb +42 -0
- data/lib/ms/mzml/activation.rb +33 -0
- data/lib/ms/mzml/chromatogram.rb +29 -0
- data/lib/ms/mzml/chromatogram_list.rb +26 -0
- data/lib/ms/mzml/component.rb +21 -0
- data/lib/ms/mzml/contact.rb +23 -0
- data/lib/ms/mzml/cv.rb +46 -0
- data/lib/ms/mzml/data_array.rb +65 -0
- data/lib/ms/mzml/data_array_container_like.rb +57 -0
- data/lib/ms/mzml/data_processing.rb +27 -0
- data/lib/ms/mzml/file_content.rb +21 -0
- data/lib/ms/mzml/file_description.rb +47 -0
- data/lib/ms/mzml/instrument_configuration.rb +37 -0
- data/lib/ms/mzml/isolation_window.rb +21 -0
- data/lib/ms/mzml/list.rb +23 -0
- data/lib/ms/mzml/precursor.rb +42 -0
- data/lib/ms/mzml/processing_method.rb +24 -0
- data/lib/ms/mzml/product.rb +22 -0
- data/lib/ms/mzml/referenceable_param_group.rb +40 -0
- data/lib/ms/mzml/run.rb +54 -0
- data/lib/ms/mzml/sample.rb +27 -0
- data/lib/ms/mzml/scan.rb +44 -0
- data/lib/ms/mzml/scan_list.rb +33 -0
- data/lib/ms/mzml/scan_settings.rb +28 -0
- data/lib/ms/mzml/selected_ion.rb +18 -0
- data/lib/ms/mzml/software.rb +28 -0
- data/lib/ms/mzml/source_file.rb +48 -0
- data/lib/ms/mzml/spectrum.rb +91 -0
- data/lib/ms/mzml/spectrum_list.rb +42 -0
- data/lib/ms/mzml.rb +173 -6
- data/lib/ms/quant/qspec/protein_group_comparison.rb +3 -3
- data/lib/ms/quant/qspec.rb +4 -4
- data/lib/ms/spectrum.rb +137 -260
- data/lib/ms/spectrum_like.rb +133 -0
- data/lib/ms/user_param.rb +43 -0
- data/lib/mspire.rb +6 -0
- data/obo/ms.obo +670 -121
- data/obo/unit.obo +23 -1
- data/spec/ms/cv/param_spec.rb +33 -0
- data/spec/ms/mzml/cv_spec.rb +17 -0
- data/spec/ms/mzml/file_content_spec.rb +25 -0
- data/spec/ms/mzml/file_description_spec.rb +34 -0
- data/spec/ms/mzml/referenceable_param_group_spec.rb +33 -0
- data/spec/ms/mzml_spec.rb +65 -4
- data/spec/ms/user_param_spec.rb +51 -0
- data/spec/mspire_spec.rb +9 -0
- data/spec/testfiles/ms/mzml/mspire_simulated.noidx.check.mzML +81 -0
- metadata +57 -21
- data/lib/cv/description.rb +0 -19
- data/lib/ms/cv/description.rb +0 -44
- data/lib/msplat.rb +0 -2
- data/spec/ms/cv/description_spec.rb +0 -60
- data/spec/msplat_spec.rb +0 -24
@@ -0,0 +1,133 @@
|
|
1
|
+
module MS
|
2
|
+
module SpectrumLike
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_accessor :products
|
6
|
+
attr_accessor :precursors
|
7
|
+
attr_accessor :scans
|
8
|
+
attr_accessor :ms_level
|
9
|
+
|
10
|
+
# boolean for if the spectrum represents centroided data or not
|
11
|
+
attr_accessor :centroided
|
12
|
+
|
13
|
+
# The underlying data store. methods are implemented so that data[0] is
|
14
|
+
# the m/z's and data[1] is intensities
|
15
|
+
attr_accessor :data
|
16
|
+
|
17
|
+
def centroided?() centroided end
|
18
|
+
|
19
|
+
# data takes an array: [mzs, intensities]
|
20
|
+
# @return [MS::Spectrum]
|
21
|
+
# @param [Array] data two element array of mzs and intensities
|
22
|
+
def initialize(data, centroided=true)
|
23
|
+
@data = data
|
24
|
+
@centroided = centroided
|
25
|
+
end
|
26
|
+
|
27
|
+
# found by querying the size of the data store. This should almost always
|
28
|
+
# be 2 (m/z and intensities)
|
29
|
+
def size
|
30
|
+
@data.size
|
31
|
+
end
|
32
|
+
|
33
|
+
def ==(other)
|
34
|
+
mzs == other.mzs && intensities == other.intensities
|
35
|
+
end
|
36
|
+
|
37
|
+
# An array of the mz data.
|
38
|
+
def mzs
|
39
|
+
@data[0]
|
40
|
+
end
|
41
|
+
|
42
|
+
# An array of the intensities data, corresponding to mzs.
|
43
|
+
def intensities
|
44
|
+
@data[1]
|
45
|
+
end
|
46
|
+
|
47
|
+
def mzs_and_intensities
|
48
|
+
[@data[0], @data[1]]
|
49
|
+
end
|
50
|
+
|
51
|
+
# retrieve an m/z and intensity doublet at that index
|
52
|
+
def [](array_index)
|
53
|
+
[@data[0][array_index], @data[1][array_index]]
|
54
|
+
end
|
55
|
+
|
56
|
+
# yields(mz, inten) across the spectrum, or array of doublets if no block
|
57
|
+
def points(&block)
|
58
|
+
@data[0].zip(@data[1], &block)
|
59
|
+
end
|
60
|
+
|
61
|
+
alias_method :each, :points
|
62
|
+
alias_method :each_point, :points
|
63
|
+
|
64
|
+
# if the mzs and intensities are the same then the spectra are considered
|
65
|
+
# equal
|
66
|
+
def ==(other)
|
67
|
+
mzs == other.mzs && intensities == other.intensities
|
68
|
+
end
|
69
|
+
|
70
|
+
# returns a new spectrum whose intensities have been normalized by the tic
|
71
|
+
# of another given value
|
72
|
+
def normalize(norm_by=:tic)
|
73
|
+
norm_by = tic if norm_by == :tic
|
74
|
+
MS::Spectrum.new([self.mzs, self.intensities.map {|v| v / norm_by }])
|
75
|
+
end
|
76
|
+
|
77
|
+
def tic
|
78
|
+
self.intensities.reduce(:+)
|
79
|
+
end
|
80
|
+
|
81
|
+
# ensures that the m/z values are monotonically ascending (some
|
82
|
+
# instruments are bad about this)
|
83
|
+
# returns self
|
84
|
+
def sort!
|
85
|
+
_points = points.to_a
|
86
|
+
_points.sort!
|
87
|
+
_points.each_with_index {|(mz,int), i| @data[0][i] = mz ; @data[1][i] = int }
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
91
|
+
# returns the m/z that is closest to the value, favoring the lower m/z in
|
92
|
+
# the case of a tie. Uses a binary search.
|
93
|
+
def find_nearest(val)
|
94
|
+
mzs[find_nearest_index(val)]
|
95
|
+
end
|
96
|
+
|
97
|
+
# same as find_nearest but returns the index of the point
|
98
|
+
def find_nearest_index(val)
|
99
|
+
find_all_nearest_index(val).first
|
100
|
+
end
|
101
|
+
|
102
|
+
def find_all_nearest_index(val)
|
103
|
+
_mzs = mzs
|
104
|
+
index = _mzs.bsearch_lower_boundary {|v| v <=> val }
|
105
|
+
if index == _mzs.size
|
106
|
+
[_mzs.size-1]
|
107
|
+
else
|
108
|
+
# if the previous m/z diff is smaller, use it
|
109
|
+
if index == 0
|
110
|
+
[index]
|
111
|
+
else
|
112
|
+
case (val - _mzs[index-1]).abs <=> (_mzs[index] - val).abs
|
113
|
+
when -1
|
114
|
+
[index-1]
|
115
|
+
when 0
|
116
|
+
[index-1, index]
|
117
|
+
when 1
|
118
|
+
[index]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def find_all_nearest(val)
|
125
|
+
find_all_nearest_index(val).map {|i| mzs[i] }
|
126
|
+
end
|
127
|
+
|
128
|
+
# uses MS::Spectrum.merge
|
129
|
+
def merge(other_spectra, opts={})
|
130
|
+
MS::Spectrum.merge([self, *other_spectra], opts)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
module MS
|
3
|
+
|
4
|
+
class UserParam
|
5
|
+
|
6
|
+
# (optional) a CV::Param object
|
7
|
+
attr_accessor :unit
|
8
|
+
|
9
|
+
# (required)
|
10
|
+
attr_accessor :name
|
11
|
+
|
12
|
+
# (optional)
|
13
|
+
attr_accessor :value
|
14
|
+
|
15
|
+
# (optional) e.g. 'xsd:float'
|
16
|
+
attr_accessor :type
|
17
|
+
|
18
|
+
# takes a few different incantations:
|
19
|
+
#
|
20
|
+
# name, unit_acc# or CV::Param object
|
21
|
+
# name, value, unit_acc# or CV::Param object
|
22
|
+
# name, value, type, unit_acc# or CV::Param object
|
23
|
+
def initialize(*args)
|
24
|
+
@unit =
|
25
|
+
if args.size > 1 && ((args.last.is_a?(::CV::Param) || args.last =~ /^[A-Za-z]+:\d+$/))
|
26
|
+
unit_arg = args.pop
|
27
|
+
unit_arg.is_a?(::CV::Param) ? unit_arg : MS::CV::Param[unit_arg]
|
28
|
+
end
|
29
|
+
@name, @value, @type = args
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# A UserParam
|
36
|
+
# (has no accession)
|
37
|
+
# (has no cvRef)
|
38
|
+
# name (required)
|
39
|
+
# type
|
40
|
+
# unitAccession
|
41
|
+
# unitCvRef
|
42
|
+
# unitName
|
43
|
+
# value
|