lib/ms/in_silico/spectrum.rb in ms-in_silico-0.1.0 vs lib/ms/in_silico/spectrum.rb in ms-in_silico-0.2.0
- old
+ new
@@ -110,10 +110,13 @@
# Scans the sequence to produce a ladder of masses and a
# hash of (residue, locations) pairs which indicate the
# indicies at which the residue occurs in sequence. The
# ladder corresponds to the M values described above.
+ # Characters in the sequence that do not add mass, such
+ # as whitespace, are skipped and do not add an entry to
+ # the ladder.
#
# Returns [ladder, {residue => locations}].
#
# ==== Inputs
# sequence:: a string
@@ -130,13 +133,17 @@
residues_to_locate.each_byte {|byte| locations[byte] = []}
mass = 0
ladder = []
sequence.each_byte do |byte|
- mass += masses_by_byte[byte]
- location = locations[byte]
-
- location << ladder.length if location
+ # check a mass is added... if not (as for whitespace)
+ # then skip to the next byte
+ next if (mass == (mass += masses_by_byte[byte]))
+
+ if location = locations[byte]
+ location << ladder.length
+ end
+
ladder << mass
end
hash = {}
0.upto(residues_to_locate.length-1) do |index|
\ No newline at end of file