ms-sequest 0.0.2

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.
@@ -0,0 +1,169 @@
1
+
2
+ require 'ms/sequest'
3
+ require 'ms/sequest/srf'
4
+ require 'ms/sequest/sqt'
5
+
6
+ module Ms
7
+ module Sequest
8
+ class Srf
9
+
10
+ # the out_filename will be the base_name + .sqt unless 'out_filename' is
11
+ # defined
12
+ # :round => round floating point numbers
13
+ # etc...
14
+ def to_sqt(out_filename=nil, opts={})
15
+ # default rounding precision (Decimal Places)
16
+ tic_dp = 2
17
+ mh_dp = 7
18
+ xcorr_dp = 5
19
+ sp_dp = 2
20
+ dcn_dp = 5
21
+
22
+ defaults = {:db_info=>false, :new_db_path=>nil, :update_db_path=>false, :round=>false}
23
+ opt = defaults.merge(opts)
24
+
25
+ outfile =
26
+ if out_filename
27
+ out_filename
28
+ else
29
+ base_name + '.sqt'
30
+ end
31
+ invariant_ordering = %w(SQTGenerator SQTGeneratorVersion Database FragmentMasses PrecursorMasses StartTime) # just for readability and consistency
32
+ fmt =
33
+ if params.fragment_mass_type == 'average' ; 'AVG'
34
+ else ; 'MONO'
35
+ end
36
+ pmt =
37
+ if params.precursor_mass_type == 'average' ; 'AVG'
38
+ else ; 'MONO'
39
+ end
40
+
41
+ mass_index = params.mass_index
42
+ static_mods = params.static_mods.map do |k,v|
43
+ key = k.split(/_/)[1]
44
+ if key.size == 1
45
+ key + '=' + (mass_index[key.to_sym] + v.to_f).to_s
46
+ else
47
+ key + '=' + v
48
+ end
49
+ end
50
+
51
+ dynamic_mods = []
52
+ header.modifications.scan(/\((.*?)\)/) do |match|
53
+ dynamic_mods << match.first.sub(/ /,'=')
54
+ end
55
+ plural = {
56
+ 'StaticMod' => static_mods,
57
+ 'DynamicMod' => dynamic_mods, # example as diff mod
58
+ 'Comment' => ['Created from Bioworks .srf file']
59
+ }
60
+
61
+
62
+ db_filename = header.db_filename
63
+ db_filename_in_sqt = db_filename
64
+ if opt[:new_db_path]
65
+ db_filename = File.join(opt[:new_db_path], File.basename(db_filename.gsub('\\', '/')))
66
+ if opt[:update_db_path]
67
+ db_filename_in_sqt = File.expand_path(db_filename)
68
+ warn "writing Database #{db_filename} to sqt, but it does not exist on this file system" unless File.exist?(db_filename)
69
+ end
70
+ end
71
+
72
+ apmu =
73
+ case params.peptide_mass_units
74
+ when '0' : 'amu'
75
+ when '1' : 'mmu'
76
+ when '2' : 'ppm'
77
+ end
78
+
79
+ hh = {
80
+ 'SQTGenerator' => "mspire: ms-sequest",
81
+ 'SQTGeneratorVersion' => Ms::Sequest::VERSION,
82
+ 'Database' => db_filename_in_sqt,
83
+ 'FragmentMasses' => fmt,
84
+ 'PrecursorMasses' => pmt,
85
+ 'StartTime' => '', # Bioworks 3.2 also leaves this blank...
86
+ 'Alg-PreMassTol' => params.peptide_mass_tolerance,
87
+ 'Alg-FragMassTol' => params.fragment_ion_tolerance,
88
+ 'Alg-PreMassUnits' => apmu, ## mine
89
+ 'Alg-IonSeries' => header.ion_series.split(':').last.lstrip,
90
+ 'Alg-Enzyme' => header.enzyme.split(':').last,
91
+ 'Alg-MSModel' => header.model,
92
+ }
93
+
94
+ if opt[:db_info]
95
+ if File.exist?(db_filename)
96
+ reply = Ms::Sequest::Sqt.get_db_info(db_filename)
97
+ %w(DBSeqLength DBLocusCount DBMD5Sum).zip(reply) do |label,val|
98
+ hh[label] = val
99
+ end
100
+ else
101
+ warn "file #{db_filename} does not exist, no extra db info in header!"
102
+ end
103
+ end
104
+
105
+ has_hits = (self.out_files.size > 0)
106
+ if has_hits
107
+ # somewhat redundant with above, but we can get this without a db present!
108
+ hh['DBLocusCount'] = self.out_files.first.db_locus_count
109
+ end
110
+
111
+ File.open(outfile, 'w') do |out|
112
+ # print the header:
113
+ invariant_ordering.each do |iv|
114
+ out.puts ['H', iv, hh.delete(iv)].join("\t")
115
+ end
116
+ hh.each do |k,v|
117
+ out.puts ['H', k, v].join("\t")
118
+ end
119
+ plural.each do |k,vals|
120
+ vals.each do |val|
121
+ out.puts ['H', k, val].join("\t")
122
+ end
123
+ end
124
+
125
+ ##### SPECTRA
126
+ time_to_process = '0.0'
127
+ #########################################
128
+ # NEED TO FIGURE OUT: (in spectra guy)
129
+ # * Lowest Sp value for top 500 spectra
130
+ # * Number of sequences matching this precursor ion
131
+ #########################################
132
+
133
+ manual_validation_status = 'U'
134
+ self.out_files.zip(dta_files) do |out_file, dta_file|
135
+ # don't have the time to process (using 0.0 like bioworks 3.2)
136
+ dta_file_mh = dta_file.mh
137
+ out_file_total_inten = out_file.total_inten
138
+ out_file_lowest_sp = out_file.lowest_sp
139
+ if opt[:round]
140
+ dta_file_mh = round(dta_file_mh, mh_dp)
141
+ out_file_total_inten = round(out_file_total_inten, tic_dp)
142
+ out_file_lowest_sp = round(out_file_lowest_sp, sp_dp)
143
+ end
144
+
145
+ out.puts ['S', out_file.first_scan, out_file.last_scan, out_file.charge, time_to_process, out_file.computer, dta_file_mh, out_file_total_inten, out_file_lowest_sp, out_file.num_matched_peptides].join("\t")
146
+ out_file.hits.each_with_index do |hit,index|
147
+ hit_mh = hit.mh
148
+ hit_deltacn_orig_updated = hit.deltacn_orig_updated
149
+ hit_xcorr = hit.xcorr
150
+ hit_sp = hit.sp
151
+ if opt[:round]
152
+ hit_mh = round(hit_mh, mh_dp)
153
+ hit_deltacn_orig_updated = round(hit_deltacn_orig_updated, dcn_dp)
154
+ hit_xcorr = round(hit_xcorr, xcorr_dp)
155
+ hit_sp = round(hit_sp, sp_dp)
156
+ end
157
+ # note that the rank is determined by the order..
158
+ out.puts ['M', index+1, hit.rsp, hit_mh, hit_deltacn_orig_updated, hit_xcorr, hit_sp, hit.ions_matched, hit.ions_total, hit.sequence, manual_validation_status].join("\t")
159
+ hit.prots.each do |prot|
160
+ out.puts ['L', prot.first_entry].join("\t")
161
+ end
162
+ end
163
+ end
164
+ end # close the filehandle
165
+ end # method
166
+
167
+ end # Srf
168
+ end # Sequest
169
+ end # Ms
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ms-sequest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - John Prince
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-14 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: arrayclass
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: ms-core
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.1
34
+ version:
35
+ description:
36
+ email: jtprince@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ - MIT-LICENSE
44
+ - History
45
+ files:
46
+ - lib/ms/sequest/params.rb
47
+ - lib/ms/sequest/srf/sqt.rb
48
+ - lib/ms/sequest/srf.rb
49
+ - lib/ms/sequest/sqt.rb
50
+ - lib/ms/sequest.rb
51
+ - README
52
+ - MIT-LICENSE
53
+ - History
54
+ has_rdoc: true
55
+ homepage: http://mspire.rubyforge.org/projects/ms-sequest/
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --main
61
+ - README
62
+ - -S
63
+ - -N
64
+ - --title
65
+ - Ms-Sequest
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project: mspire
83
+ rubygems_version: 1.3.2
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: An mspire library supporting SEQUEST, Bioworks, SQT, etc
87
+ test_files: []
88
+