ms-mascot 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,94 +0,0 @@
1
- require 'ms/in_silico/digest'
2
- require 'ms/mascot/fragment'
3
- require 'ms/mascot/mgf/archive'
4
-
5
- module Ms
6
- module Mascot
7
-
8
- # Ms::Mascot::Predict::manifest predicts the spectra for a protein sequence
9
- #
10
- # Fragments a protein sequence and calculates the fragment spectra for
11
- # each peptide. The peptide spectra are formatted as mgf and dumped to
12
- # the target.
13
- #
14
- # % rap predict MAEELVLERCDLELETNGRDHHTADLCREKLVVRRGQPFWLTLHFEGRNYEASVDSLTFS
15
- # I[16:30:19] digest MAEELVLERCD... to 15 peptides
16
- # I[16:30:19] fragment MAEELVLER
17
- # I[16:30:19] fragment MAEELVLERCDLELETNGR
18
- # I[16:30:19] fragment CDLELETNGR
19
- # I[16:30:19] fragment CDLELETNGRDHHTADLCR
20
- # I[16:30:19] fragment DHHTADLCR
21
- # I[16:30:19] fragment DHHTADLCREK
22
- # I[16:30:19] fragment EKLVVR
23
- # I[16:30:19] fragment LVVR
24
- # I[16:30:19] fragment LVVRR
25
- # I[16:30:19] fragment RGQPFWLTLHFEGR
26
- # I[16:30:19] fragment GQPFWLTLHFEGR
27
- # I[16:30:19] fragment GQPFWLTLHFEGRNYEASVDSLTFS
28
- # I[16:30:19] fragment NYEASVDSLTFS
29
- #
30
- class Predict < Tap::FileTask
31
- define :digest, InSilico::Digest, {:max_misses => 1}
32
- define :fragment, Mascot::Fragment, {:intensity => 1, :unmask => true, :sort => true}
33
-
34
- config :headers, nil, &c.hash_or_nil # a hash of headers to include
35
- config :min_length, 3, &c.integer_or_nil # the minimum peptide length
36
- config :mz_precision, 6, &c.integer # the precision of mzs
37
- config :intensity_precision, 0, &c.integer # the precision of intensities
38
- config :pepmass_precision, 6, &c.integer # the precision of peptide mass
39
-
40
- # Sequences digest and fragment. When fragment completes, it will add
41
- # a new mgf entry to the internal entries collection.
42
- def workflow
43
- digest.on_complete do |_results|
44
- _results._iterate.each do |_result|
45
- next if min_length && _result._current.length < min_length
46
- fragment._execute(_result)
47
- end
48
- end
49
-
50
- fragment.on_complete do |_result|
51
- parent_ion_mass, data = _result._current
52
- next if data.empty?
53
-
54
- peptide = _result._values[-2]
55
- headers = {
56
- 'TITLE' => "#{peptide} (#{fragment.series.join(', ')})",
57
- 'CHARGE' => fragment.charge,
58
- 'PEPMASS' => parent_ion_mass}
59
-
60
- @entries << Mgf::Entry.new(headers, data)
61
- end
62
- end
63
-
64
- # Infers a default path for the output mgf file from the sequence; the
65
- # path is the sequence if the sequence is less than 10 characters,
66
- # otherwise it's like: "<first five>_<last five>.mgf"
67
- #
68
- def default_path(sequence)
69
- sequence = "#{sequence[0,5]}_#{sequence[-5,5]}" if sequence.length > 10
70
- "#{sequence}.mgf"
71
- end
72
-
73
- def process(sequence, target=nil)
74
- sequence = sequence.gsub(/\s/, "")
75
-
76
- @entries = []
77
- digest.execute(sequence)
78
-
79
- # prepare and dump the predicted spectra
80
- # to the target path.
81
- target = default_path(sequence) if target == nil
82
- prepare(target)
83
- File.open(target, "wb") do |file|
84
- @entries.each do |entry|
85
- entry.dump(file, config)
86
- file.puts
87
- end
88
- end
89
-
90
- target
91
- end
92
- end
93
- end
94
- end