public function write(PrecursorIon $precursor)
    {
        if (is_null($this->fileHandle)) {
            throw new \BadMethodCallException('The file handle is closed. Cannot write after close() has been called.');
        }
        
        // TODO: Validate mandatory/optional fields
        fwrite($this->fileHandle, 'BEGIN IONS' . PHP_EOL);
        fwrite($this->fileHandle, 'TITLE=' . $precursor->getTitle() . PHP_EOL);
        fwrite($this->fileHandle, 'PEPMASS=' . $precursor->getMonoisotopicMassCharge());
        if (! is_null($precursor->getIntensity())) {
            fwrite($this->fileHandle, ' ' . $precursor->getIntensity());
        }
        
        fwrite($this->fileHandle, PHP_EOL);
        fwrite($this->fileHandle, 'CHARGE=' . $precursor->getCharge() . '+' . PHP_EOL);
        
        if (! is_null($precursor->getScan())) {
            fwrite($this->fileHandle, 'SCANS=' . $precursor->getScan() . PHP_EOL);
        }
        
        if (! is_null($precursor->getRetentionTime())) {
            if ($precursor->hasRetentionTimeWindow()) {
                fwrite($this->fileHandle, 'RTINSECONDS=' . implode(',', $precursor->getRetentionTimeWindow()) . PHP_EOL);
            } else {
                fwrite($this->fileHandle, 'RTINSECONDS=' . $precursor->getRetentionTime() . PHP_EOL);
            }
        }
        
        foreach ($precursor->getFragmentIons() as $ion) {
            fwrite($this->fileHandle, $ion->getMonoisotopicMassCharge() . ' ');
            fwrite($this->fileHandle, $ion->getIntensity());
            
            if (! is_null($ion->getCharge()) && $ion->getCharge() != 1) {
                fwrite($this->fileHandle, ' ' . $ion->getCharge());
            }
            
            fwrite($this->fileHandle, PHP_EOL);
        }
        
        fwrite($this->fileHandle, 'END IONS' . PHP_EOL);
    }