Skip to content

Commit

Permalink
Merge pull request #15 from counsyl/rename-hgvs-pyhgvs
Browse files Browse the repository at this point in the history
Rename hgvs module to pyhgvs
  • Loading branch information
mdrasmus committed Dec 12, 2014
2 parents 4572247 + 3a93eba commit 8827d98
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 31 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# HGVS library change log

## 0.9.2 (2014-12-11)
- Rename package to pyhgvs to avoid naming conflict with other libraries.

## 0.9.1 (2014-03-10)
- Normalize variants by default when generating names.

## 0.9 (2014-01-16)
- Improved testing.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ and transcripts are read from a RefSeqGenes flat-file using methods
provided by `hgvs`.

```python
import hgvs
import hgvs.utils
import pyhgvs as hgvs
import hgvs.utils as hgvs_utils
from pygr.seqdb import SequenceFileDB

# Read genome sequence using pygr.
genome = SequenceFileDB('hg19.fa')

# Read RefSeq transcripts into a python dict.
with open('hgvs/data/genes.refGene') as infile:
transcripts = hgvs.utils.read_transcripts(infile)
transcripts = hgvs_utils.read_transcripts(infile)

# Provide a callback for fetching a transcript by its name.
def get_transcript(name):
Expand All @@ -127,7 +127,7 @@ The `hgvs` library can also perform just the parsing step and provide
a parse tree of the HGVS name.

```python
import hgvs
import pyhgvs as hgvs

hgvs_name = hgvs.HGVSName('NM_000352.3:c.215-10A>G')

Expand Down
33 changes: 18 additions & 15 deletions bin/hgvs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python

import argparse
import logging
import optparse
import sys

import hgvs
from hgvs.variants import normalize_variant
from hgvs.utils import read_transcripts
from hgvs import parse_hgvs_name
import pyhgvs
from pyhgvs import parse_hgvs_name
from pyhgvs.variants import normalize_variant
from pyhgvs.utils import read_transcripts

import pygr.logger
from pygr.seqdb import SequenceFileDB
Expand All @@ -24,9 +24,10 @@ handler.setFormatter(formatter)
logger.addHandler(handler)

# Command line options.
options = optparse.OptionParser()
options.add_option('-f', '--fasta')
options.add_option('-t', '--trans')
options = argparse.ArgumentParser()
options.add_argument('-f', '--fasta', required=True)
options.add_argument('-t', '--trans', required=True)
options.add_argument('hgvs_name', nargs='*')


#=============================================================================
Expand Down Expand Up @@ -61,7 +62,7 @@ def determine_allele(genome, hgvs_name):
chrom, start, ref, alt = parse_hgvs_name(
hgvs_name, genome, get_transcript=get_transcript)
except (NotImplementedError, AssertionError, KeyError, ValueError,
hgvs.InvalidHGVSName) as error:
pyhgvs.InvalidHGVSName) as error:
messages.append(str(error))
return None, messages

Expand All @@ -86,23 +87,25 @@ def determine_allele(genome, hgvs_name):
# Main.

if __name__ == '__main__':
conf, args = options.parse_args()
args = options.parse_args()

# Read genome and transcripts.
genome = SequenceFileDB(conf.fasta)
with open(conf.trans) as infile:
genome = SequenceFileDB(args.fasta)
with open(args.trans) as infile:
transcripts = read_transcripts(infile)

gene2transcript = {transcript.gene.name: transcript
for transcript in transcripts.itervalues()}

if len(args) == 0:
args = (line.rstrip() for line in sys.stdin)
if args.hgvs_name:
hgvs_names = args.hgvs_name
else:
hgvs_names = (line.rstrip() for line in sys.stdin)

headers = ['name', 'chrom', 'start', 'ref', 'alt', 'messages']
print '\t'.join(map(str, headers))

for allele_name in args:
for allele_name in hgvs_names:
allele, messages = determine_allele(genome, allele_name)
message = '|'.join(messages)
if allele:
Expand Down
6 changes: 3 additions & 3 deletions examples/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
"""

import hgvs
import hgvs.utils
import pyhgvs as hgvs
import hgvs.utils as hgvs_utils
from pygr.seqdb import SequenceFileDB

# Read genome sequence using pygr.
genome = SequenceFileDB('hg19.fa')

# Read RefSeq transcripts into a python dict.
with open('hgvs/data/genes.refGene') as infile:
transcripts = hgvs.utils.read_transcripts(infile)
transcripts = hgvs_utils.read_transcripts(infile)


# Provide a callback for fetching a transcript by its name.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_name_to_variant():
"""
genome = MockGenomeTestFile(
db_filename='hg19.fa',
filename='hgvs/tests/data/test_name_to_variant.genome',
filename='pyhgvs/tests/data/test_name_to_variant.genome',
create_data=False)

for hgvs_name, variant, name_canonical, var_canonical in _name_variants:
Expand All @@ -115,7 +115,7 @@ def test_variant_to_name():
"""
genome = MockGenomeTestFile(
db_filename='hg19.fa',
filename='hgvs/tests/data/test_variant_to_name.genome',
filename='pyhgvs/tests/data/test_variant_to_name.genome',
create_data=False)

for (expected_hgvs_name, variant,
Expand All @@ -139,7 +139,7 @@ def test_variant_to_name_counsyl():
"""
genome = MockGenomeTestFile(
db_filename='hg19.fa',
filename='hgvs/tests/data/test_variant_to_name.genome',
filename='pyhgvs/tests/data/test_variant_to_name.genome',
create_data=False)

for (expected_hgvs_name, variant,
Expand All @@ -164,7 +164,7 @@ def test_name_to_variant_refseqs():
if not SequenceFileDB:
print 'skip test_name_to_variant_refseqs'
return
genome = SequenceFileDB('hgvs/tests/data/test_refseqs.fa')
genome = SequenceFileDB('pyhgvs/tests/data/test_refseqs.fa')

for hgvs_name, variant, name_canonical, var_canonical in _name_variants:
if not var_canonical or 'NM_' not in hgvs_name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def test_name_to_variant_long():
"""
genome = MockGenomeTestFile(
db_filename='hg19.fa',
filename='hgvs/tests/data/test_hgvs.genome',
filename='pyhgvs/tests/data/test_hgvs.genome',
create_data=False)

# Read transcripts.
with open('hgvs/data/genes.refGene', 'r') as infile:
with open('pyhgvs/data/genes.refGene', 'r') as infile:
transcripts = read_transcripts(infile)

class NoTranscriptError(Exception):
Expand All @@ -40,7 +40,7 @@ def get_transcript_long(name):
return transcript

errors = []
with open('hgvs/tests/data/test_hgvs.txt', 'r') as infile:
with open('pyhgvs/tests/data/test_hgvs.txt', 'r') as infile:
for i, line in enumerate(infile):
row = line.rstrip().split('\t')
chrom, offset, ref, alt, hgvs_name = row[:5]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def main():

setup(
name='pyhgvs',
version='0.9.1',
version='0.9.2',
description='HGVS name parsing and formatting',
long_description=description,
author='Matt Rasmussen',
author_email='[email protected]',
packages=['hgvs', 'hgvs.tests'],
packages=['pyhgvs', 'pyhgvs.tests'],
include_package_data=True,
package_data={
'': ['requirements-dev.txt'],
Expand Down

0 comments on commit 8827d98

Please sign in to comment.