Source of file MgfReader.php

Size: 6,292 Bytes - Last Modified: 2019-05-10T12:24:09+01:00

src/Reader/MgfReader.php

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
Covered by 5 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testObjectCanBeConstructedForValidConstructorArguments
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteShortEntry
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteLongEntry
48
Covered by 5 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testObjectCanBeConstructedForValidConstructorArguments
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteShortEntry
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteLongEntry
495051525354555657
Covered by 4 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteShortEntry
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteLongEntry
58596061626364656667
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
686970717273747576
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
77
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
78
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
79
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
80
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
818283848586878889
Covered by 4 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteShortEntry
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteLongEntry
90
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
91
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
9293
Covered by 4 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteShortEntry
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteLongEntry
94
Covered by 4 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteShortEntry
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteLongEntry
95
Covered by 4 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteShortEntry
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteLongEntry
96
Covered by 4 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteShortEntry
  • pgb_liv\php_ms\Test\Unit\MgfWriterTest::testCanWriteLongEntry
979899100101102103104105
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
106
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
107108109
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
110111112113114115116117118119
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
120
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
121122123
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
124
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
125126
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
127128129130131132133134135136
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
137
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
138
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
139140
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
141142143144145
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
146147148
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
149
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
150
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
151
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
152
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
153154155
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
156
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
157158159
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
160
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
161162163
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
164
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
165166167
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
168
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
169
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
170171172
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
173
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
174175176
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
177
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
178
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
179180181182183
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
184
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
185
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
186187188
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
189
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
190191
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
192193
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
194195196197198199200201202203204
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
205
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
206207
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
208
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
209
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
210
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
211212
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
213
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
214
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
215
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
216
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
217218219220
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
221
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
222
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
223
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
224
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
225
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
226
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
227
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
228
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
229
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
230231232
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
233
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
234235236237238239240241242243
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
244245
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
246247248249
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
250251
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
252
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
253
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
254255
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
256
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
257
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
258259
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
260
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
261
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
262263
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
264265
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
266
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRetrieveEntry
  • pgb_liv\php_ms\Test\Unit\MgfReaderTest::testCanRewind
267268
<?php
/**
 * Copyright 2018 University of Liverpool
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
namespace pgb_liv\php_ms\Reader;

use pgb_liv\php_ms\Core\Spectra\PrecursorIon;
use pgb_liv\php_ms\Core\Spectra\FragmentIon;

/**
 * An MGF reader that creates a new iterable object that will return a raw
 * entry on each iteration.
 *
 * @author Andrew Collins
 */
class MgfReader implements \Iterator
{

    private $filePath;

    private $fileHandle;

    private $filePeek;

    private $current;

    private $key = 0;

    private $massCharge;

    private $charge;

    public function __construct($filePath)
    {
        $this->filePath = $filePath;
    }

    /**
     *
     * {@inheritdoc}
     * @return PrecursorIon
     */
    public function current()
    {
        return $this->current;
    }

    /**
     *
     * {@inheritdoc}
     * @return int
     */
    public function key()
    {
        return $this->key;
    }

    /**
     *
     * {@inheritdoc}
     */
    public function next()
    {
        $this->current = null;
        if (! feof($this->fileHandle)) {
            $this->current = $this->parseEntry();
        }
    }

    /**
     *
     * {@inheritdoc}
     */
    public function rewind()
    {
        // Reset file parsing to start
        if ($this->fileHandle != null) {
            fclose($this->fileHandle);
        }

        $this->fileHandle = fopen($this->filePath, 'r');
        $this->key = 0;
        $this->current = $this->parseEntry();
    }

    /**
     *
     * {@inheritdoc}
     * @return bool
     */
    public function valid()
    {
        if ($this->current instanceof PrecursorIon) {
            return true;
        }

        return false;
    }

    /**
     * Gets the next line and increments the file iterator
     *
     * @return string The next line in the file
     */
    private function getLine()
    {
        if ($this->filePeek == null) {
            return fgets($this->fileHandle);
        }

        $ret = $this->filePeek;
        $this->filePeek = null;

        return $ret;
    }

    /**
     * Gets the next line, though does not move the file iterator
     *
     * @return string The next line in the file
     */
    private function peekLine()
    {
        if ($this->filePeek == null) {
            $this->filePeek = fgets($this->fileHandle);
        }

        return $this->filePeek;
    }

    private function parseEntry()
    {
        $entry = new PrecursorIon();

        // Scan to BEGIN IONS
        $isFound = false;
        while ($line = $this->getLine()) {
            $line = trim($line);
            if (strpos($line, 'BEGIN IONS') !== 0) {
                continue;
            }

            $isFound = true;
            break;
        }

        if (! $isFound) {
            return null;
        }

        $this->massCharge = null;
        $this->charge = 1;

        // Scan for key=value pairs
        while ($line = $this->peekLine()) {
            if (strpos($line, '=') === false) {
                break;
            }

            $this->parseMeta($entry);
        }

        // TODO: Better support required for charge-less data
        if (! is_null($this->massCharge)) {
            $entry->setMonoisotopicMassCharge($this->massCharge, $this->charge);
        } else {
            $entry->setCharge($this->charge);
        }

        // Scan for [m/z] [intensity] [charge]
        while ($line = $this->peekLine()) {
            if (strpos($line, 'END IONS') !== false) {
                break;
            }

            $this->parseFragments($entry);
        }

        $this->key ++;

        return $entry;
    }

    /**
     * Parses the meta information from the scan and writes it to the precursor entry
     *
     * @param PrecursorIon $precursor
     *            The precursor to append to
     */
    private function parseMeta(PrecursorIon $precursor)
    {
        $line = trim($this->getLine());
        $pair = explode('=', $line, 2);

        $value = $pair[1];
        if (is_numeric($value)) {
            $value += 0;
        }

        if ($pair[0] == 'TITLE') {
            $precursor->setTitle($pair[1]);
        } elseif ($pair[0] == 'PEPMASS') {
            $chunks = explode(' ', $pair[1]);
            if (count($chunks) > 1) {
                $precursor->setIntensity((float) $chunks[1] + 0);
            }

            $this->massCharge = (float) $chunks[0] + 0;
        } elseif ($pair[0] == 'CHARGE') {
            $this->charge = (int) $pair[1];
        } elseif ($pair[0] == 'SCANS') {
            $precursor->setScan((int) $pair[1] + 0);
        } elseif ($pair[0] == 'RTINSECONDS') {
            $window = explode(',', $pair[1]);
            if (count($window) == 1) {
                $precursor->setRetentionTime((float) $window[0] + 0);
            } else {
                $precursor->setRetentionTimeWindow((float) $window[0] + 0, (float) $window[1] + 0);
            }
        }
    }

    /**
     * Parses the fragment information from the scan and writes it to the precursor entry
     *
     * @param PrecursorIon $precursor
     *            The precursor to append to
     */
    private function parseFragments(PrecursorIon $precursor)
    {
        $line = trim($this->getLine());

        if (strlen($line) == 0) {
            return;
        }

        $pair = preg_split('/\\s/', $line, 3);

        $ion = new FragmentIon();
        $fragmentMz = (float) $pair[0];
        $fragmentCharge = 1;

        if (count($pair) > 1) {
            $ion->setIntensity((float) $pair[1]);
        }

        if (count($pair) > 2) {
            $fragmentCharge = (int) $pair[2];
        }

        $ion->setMonoisotopicMassCharge($fragmentMz, $fragmentCharge);

        $precursor->addFragmentIon($ion);
    }
}