Source of file FilterMass.php

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

src/Utility/Filter/FilterMass.php

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
Covered by 7 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForValidConstructorArguments
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForInvalidConstructorArguments1
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForInvalidConstructorArguments2
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOnBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryArray
57
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForInvalidConstructorArguments1
58
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForInvalidConstructorArguments1
596061
Covered by 6 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForValidConstructorArguments
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForInvalidConstructorArguments2
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOnBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryArray
62
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForInvalidConstructorArguments2
63
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForInvalidConstructorArguments2
646566
Covered by 5 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForValidConstructorArguments
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOnBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryArray
67
Covered by 5 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForValidConstructorArguments
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOnBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryArray
68
Covered by 5 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testObjectCanBeConstructedForValidConstructorArguments
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOnBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryArray
69707172737475767778
Covered by 4 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOnBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryArray
79
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryArray
808182
Covered by 4 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOnBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryArray
83
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryArray
848586
Covered by 3 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOnBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryArray
878889909192939495969798
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
99100
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
101
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
102103104
Covered by 2 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
105
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryOutOfBounds
106107108
Covered by 1 test(s):
  • pgb_liv\php_ms\Test\Unit\FilterMassTest::testCanValidateEntryInBounds
109110111
<?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\Utility\Filter;

use pgb_liv\php_ms\Core\Peptide;
use pgb_liv\php_ms\Core\Spectra\IonInterface;

/**
 * Creates an instance of a filter than can be used with a list to
 * remove those which do not fit the criteria.
 *
 * @author Andrew Collins
 */
class FilterMass extends AbstractFilter
{

    /**
     * Minimum mass, inclusive
     *
     * @var float
     */
    private $minMass;

    /**
     * Maximum mass, inclusive
     *
     * @var float
     */
    private $maxMass;

    /**
     * Creates a new instance with the specified minimum and maximum mass values.
     * Specify null for minimum or maximum for no limit.
     *
     * @param float $minMass
     *            Minimum mass, inclusive
     * @param float $maxMass
     *            Maximum mass, inclusive
     */
    public function __construct($minMass, $maxMass)
    {
        if (! is_float($minMass) && ! is_int($minMass) && ! is_null($minMass)) {
            throw new \InvalidArgumentException(
                'Argument 1 must be of type float. Value is of type ' . gettype($minMass));
        }
        
        if (! is_float($maxMass) && ! is_int($maxMass) && ! is_null($maxMass)) {
            throw new \InvalidArgumentException(
                'Argument 2 must be of type float. Value is of type ' . gettype($maxMass));
        }
        
        $this->minMass = $minMass;
        $this->maxMass = $maxMass;
    }

    /**
     *
     * {@inheritdoc}
     *
     * @see \pgb_liv\php_ms\Utility\Filter\AbstractFilter::isValidSpectra()
     */
    public function isValidSpectra(IonInterface $spectra)
    {
        if (! is_null($this->minMass) && $spectra->getMass() < $this->minMass) {
            return false;
        }
        
        if (! is_null($this->maxMass) && $spectra->getMass() > $this->maxMass) {
            return false;
        }
        
        return true;
    }

    /**
     *
     * {@inheritdoc}
     *
     * @see \pgb_liv\php_ms\Utility\Filter\AbstractFilter::isValidPeptide()
     */
    public function isValidPeptide(Peptide $peptide)
    {
        // Mass is calculated at request so must be cached
        $mass = $peptide->getMonoisotopicMass();
        
        if (! is_null($this->minMass) && $mass < $this->minMass) {
            return false;
        }
        
        if (! is_null($this->maxMass) && $mass > $this->maxMass) {
            return false;
        }
        
        return true;
    }
}