Skip to content

Commit

Permalink
Merge pull request #18 from ChrisBeaumont/parse
Browse files Browse the repository at this point in the history
Catch invalid coordinates in HGVS names
  • Loading branch information
pkaleta committed Mar 11, 2015
2 parents 3361459 + cffd9c0 commit aebe5bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pyhgvs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
BASES = BASE+
"""

import re

from .variants import justify_indel
Expand Down Expand Up @@ -746,6 +745,7 @@ def parse(self, name):
# Parse prefix and allele.
self.parse_allele(allele)
self.parse_prefix(prefix, self.kind)
self._validate()

def parse_prefix(self, prefix, kind):
"""
Expand Down Expand Up @@ -970,6 +970,13 @@ def parse_genome(self, details):

raise InvalidHGVSName(details, 'genomic allele')

def _validate(self):
"""
Check for internal inconsistencies in representation
"""
if self.start > self.end:
raise InvalidHGVSName(reason="Coordinates are nonincreasing")

def __repr__(self):
try:
return "HGVSName('%s')" % self.format()
Expand Down
14 changes: 14 additions & 0 deletions pyhgvs/tests/test_hgvs_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .. import CDNACoord
from .. import CDNA_STOP_CODON
from .. import HGVSName
from .. import InvalidHGVSName
from .. import cdna_to_genomic_coord
from .. import format_hgvs_name
from .. import genomic_to_cdna_coord
Expand Down Expand Up @@ -177,6 +178,19 @@ def test_name_to_variant_refseqs():
repr([hgvs_name, variant, hgvs_variant]))


@nose.tools.raises(InvalidHGVSName)
def test_invalid_coordinates():
"""
Regression test for 17
"""
if not SequenceFileDB:
raise nose.SkipTest

genome = SequenceFileDB('pyhgvs/tests/data/test_refseqs.fa')
hgvs_name = 'NC_000005.10:g.177421339_177421327delACTCGAGTGCTCC'
parse_hgvs_name(hgvs_name, genome, get_transcript=get_transcript)


# Test examples of cDNA coordinates.
_parse_cdna_coords = [
('1001', CDNACoord(1001)),
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from setuptools import setup
from pip.req import parse_requirements
from pip.download import PipSession
import sys

description = ("This library provides a simple to use Python API for parsing, "
Expand All @@ -19,7 +20,7 @@ def main():

setup(
name='pyhgvs',
version='0.9.3',
version='0.9.4',
description='HGVS name parsing and formatting',
long_description=description,
author='Matt Rasmussen',
Expand All @@ -32,7 +33,8 @@ def main():
scripts=[],
install_requires=['pip>=1.2'],
tests_require=[str(line.req) for line in
parse_requirements('requirements-dev.txt')],
parse_requirements('requirements-dev.txt',
session=PipSession())],
)

if __name__ == '__main__':
Expand Down

0 comments on commit aebe5bd

Please sign in to comment.