/** * Write single sequence to FastA file * * @param VIB\Bundle\BioBundle\Entity\DNA\Abstracts\Sequence $sequence * @return integer Position of the sequence in the file */ protected function writeSequence(AbstractSequence $sequence, $saveMode = false) { $file = $saveMode ? $this->getFile() : $this->getWorkingFile(); if ($file == null) { throw new IOException("Cannot open file for writing."); } if ($sequence == null || strlen($sequence->getSequence()) == 0) { throw new FileFormatException("Sequence is empty."); } if (strlen($sequence->getName()) == 0) { throw new FileFormatException("Sequence name is empty."); } $position = $file->ftell(); $file->fwrite(">"); $file->fwrite(rawurlencode($sequence->getName())); if (strlen($sequence->getDescription()) > 0) { $file->fwrite(' ' . $sequence->getDescription()); } $file->fwrite("\n"); $file->fwrite(wordwrap($sequence->getSequence(), 75, "\n", true)); $file->fwrite("\n"); return $position; }