Source of file Modification.php

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

src/Core/Modification.php

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidLocation
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidLocation
72
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidLocation
73
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidLocation
747576
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidLocation
77
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidLocation
787980818283848586
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidLocation
878889909192939495969798
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidMonoMass
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidMonoMass
99
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidMonoMass
100
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidMonoMass
101102103
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidMonoMass
104
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidMonoMass
105106107108109110111112113
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidMonoMass
114115116117118
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidAvgMass
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidAvgMass
119
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidAvgMass
120
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidAvgMass
121122123
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidAvgMass
124
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidAvgMass
125126127128
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidAvgMass
129130131132133
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetName
134
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetName
135136137138139140141142143
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetName
144145146147148149150151152153154155
Covered by 4 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidResidues
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidResidues1
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidResidues2
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidResidues3
156
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidResidues3
157158159
Covered by 3 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidResidues
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidResidues1
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidResidues2
160
Covered by 3 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidResidues
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidResidues1
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidResidues2
161
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidResidues1
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanSetInvalidResidues2
162163
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidResidues
164165166
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidResidues
167168169
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidResidues
170
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidResidues
171172173174175176177178179
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidResidues
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetEmptyResidues
180
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetEmptyResidues
181182183
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetValidResidues
184185186187188
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetTypeFixed
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetTypeVariable
189
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetTypeFixed
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetTypeVariable
190191192193
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetTypeFixed
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetTypeVariable
194195196197198
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetTypeFixed
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetTypeVariable
199200201202203
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetTypeFixed
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetTypeVariable
204205206207208209210211212213214215216217
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionValid
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionInvalid
218
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionValid
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionInvalid
219
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionValid
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionInvalid
220
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionValid
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionInvalid
221
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionValid
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionInvalid
222
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionValid
223224
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionValid
225
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionInvalid
226
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionInvalid
227
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionInvalid
228
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionValid
229230231232
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetPositionValid
233234235236237238239240241242243244
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetAccession
245
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetAccession
246247248249250251252253254
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\ModificationTest::testObjectCanGetSetAccession
255256257
<?php
/**
 * Copyright 2016 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\Core;

/**
 * A modification object which may be applied to a peptide or protein
 *
 * @author Andrew Collins
 */
class Modification
{

    const TYPE_FIXED = 0;

    const TYPE_VARIABLE = 1;

    const POSITION_ANY = 'any';

    const POSITION_NTERM = 'N-term';

    const POSITION_CTERM = 'C-term';

    const POSITION_PROTEIN_NTERM = 'Prot-N-term';

    const POSITION_PROTEIN_CTERM = 'Prot-C-term';

    private $location;

    private $monoisotopicMass;

    private $averageMass;

    private $name;

    private $residues;

    private $type = Modification::TYPE_VARIABLE;

    private $position = Modification::POSITION_ANY;

    /**
     * Accession (HUPO-PSI format) for this modification
     *
     * @var string
     */
    private $accession;

    /**
     * Sets the location for this modification
     *
     * @param int $location
     *            The location to set this modification at
     * @throws \InvalidArgumentException If argument 1 is not of type int
     */
    public function setLocation($location)
    {
        if (! is_int($location)) {
            throw new \InvalidArgumentException(
                'Argument 1 must be an int value. Valued passed is of type ' . gettype($location));
        }
        
        $this->location = $location;
    }

    /**
     * Gets the location of this modification
     *
     * @return int
     */
    public function getLocation()
    {
        return $this->location;
    }

    /**
     * Sets the monoisotopic mass for this modification
     *
     * @param float $mass
     *            The monoisotopic mass to set
     * @throws \InvalidArgumentException If argument 1 is not of type float
     */
    public function setMonoisotopicMass($mass)
    {
        if (! is_float($mass) && ! is_int($mass)) {
            throw new \InvalidArgumentException(
                'Argument 1 must be a float or integer value. Valued passed is of type ' . gettype($mass));
        }
        
        $this->monoisotopicMass = $mass;
    }

    /**
     * Gets the monoisotopic mass
     *
     * @return float
     */
    public function getMonoisotopicMass()
    {
        return $this->monoisotopicMass;
    }

    public function setAverageMass($mass)
    {
        if (! is_float($mass) && ! is_int($mass)) {
            throw new \InvalidArgumentException(
                'Argument 1 must be a float or integer value. Valued passed is of type ' . gettype($mass));
        }
        
        $this->averageMass = $mass;
    }

    public function getAverageMass()
    {
        return $this->averageMass;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * Gets this name of this instance
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set residues for this modification
     *
     * @param array $residues
     *            Array of residues this modification may occur on
     * @throws \InvalidArgumentException If argument 1 is not of type float
     */
    public function setResidues(array $residues)
    {
        if (empty($residues)) {
            throw new \InvalidArgumentException('Argument 1 must not be empty.');
        }
        
        foreach ($residues as $residue) {
            if (!preg_match('/^[A-Z]$/', $residue)) {
                throw new \InvalidArgumentException('Argument 1 must be an array of single char values (A-Z). Value passed is ' . $residue);
            }
        }
        
        // Force sort order
        sort($residues);
        
        // Force unique residue positions
        $this->residues = array_combine($residues, $residues);
    }

    /**
     * Gets the residues the modification is assosciated with
     *
     * @return array
     */
    public function getResidues()
    {
        if (is_null($this->residues)) {
            return array();
        }
        
        return array_values($this->residues);
    }

    public function setType($type)
    {
        $this->type = $type;
    }

    public function getType()
    {
        return $this->type;
    }

    public function isFixed()
    {
        return $this->type == Modification::TYPE_FIXED;
    }

    public function isVariable()
    {
        return $this->type == Modification::TYPE_VARIABLE;
    }

    /**
     * Sets the position this modification can occur on within the peptide or protein.
     * Default is 'Any'.
     *
     * @param int $position
     *            Position the modification can occur, see POSITION_ for list of options.
     * @throws \InvalidArgumentException If unknown position specified
     */
    public function setPosition($position)
    {
        switch ($position) {
            case Modification::POSITION_ANY:
            case Modification::POSITION_NTERM:
            case Modification::POSITION_CTERM:
            case Modification::POSITION_PROTEIN_NTERM:
            case Modification::POSITION_PROTEIN_CTERM:
                $this->position = $position;
                
                break;
            default:
                throw new \InvalidArgumentException('Postion must be any or terminus (see POSITION_XXXX)');
        }
    }

    public function getPosition()
    {
        return $this->position;
    }

    /**
     * Sets the accession for this modification.
     * Recommended for use when interacting with HUPO-PSI formats.
     *
     * @param string $accession
     *            The accession value to set
     */
    public function setAccession($accession)
    {
        $this->accession = $accession;
    }

    /**
     * Gets the accession for this modification if present
     *
     * @return string
     */
    public function getAccession()
    {
        return $this->accession;
    }
}