Skip to content

Commit

Permalink
Allow "Source" and "Version" in INFO header (#106)
Browse files Browse the repository at this point in the history
* Allow source and version in INFO header

* Bump version

---------

Co-authored-by: Daniel Nilsson <[email protected]>
  • Loading branch information
maehler and dnil authored Oct 24, 2024
1 parent 9b69d59 commit fca33bd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Please add a new candidate release at the top after changing the latest one. Fee

Try to use the following format:

## [unreleased]
### Fixed
- The optional fields Source and Version are allowed in the VCF header([#106](https://github.com/Clinical-Genomics/genmod/pull/106))


## [3.9]
- Fixed wrong models when chromosome X was named `chrX` and not `X` ([#135](https://github.com/Clinical-Genomics/genmod/pull/135))
- Added GitHub Actions workflows for automatic publishing to PyPI on release, and keep a changelog reminder ([#136](https://github.com/Clinical-Genomics/genmod/pull/136))
Expand Down
5 changes: 4 additions & 1 deletion genmod/vcf_tools/header_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def __init__(self):
Number=(?P<number>-?\d+|\.|[AGR]),
Type=(?P<type>Integer|Float|Flag|Character|String),
Description="(?P<desc>[^"]*)"
(?:,Source="(?P<source>[^"]+)")?
(?:,Version="(?P<version>[^"]+)")?
>''', re.VERBOSE)
self.filter_pattern = re.compile(r'''\#\#FILTER=<
ID=(?P<id>[^,]+),
Expand Down Expand Up @@ -99,7 +101,8 @@ def parse_meta_data(self, line):

matches = [
match.group('id'), match.group('number'),
match.group('type'), match.group('desc')
match.group('type'), match.group('desc'),
match.group('source'), match.group('version')
]

# extra_info is a dictionary to check the metadata about the INFO values:
Expand Down
35 changes: 35 additions & 0 deletions tests/vcf_tools/test_header_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,41 @@ def test_parse_info():
## THEN assert it is added to the parser
assert 'MQ' in head.info_dict

def test_parse_info_with_source():
## GIVEN a header object
head = HeaderParser()
assert 'MQ' not in head.info_dict
info_line = '##INFO=<ID=MQ,Number=1,Type=Float,Description="RMS Mapping Quality",Source="bwa">'

## WHEN parsing a correct info line
head.parse_meta_data(info_line)

## THEN assert it is added to the parser
assert 'MQ' in head.info_dict

def test_parse_info_with_version():
## GIVEN a header object
head = HeaderParser()
assert 'MQ' not in head.info_dict
info_line = '##INFO=<ID=MQ,Number=1,Type=Float,Description="RMS Mapping Quality",Version="1.0.0">'

## WHEN parsing a correct info line
head.parse_meta_data(info_line)

## THEN assert it is added to the parser
assert 'MQ' in head.info_dict

def test_parse_info_with_source_and_version():
## GIVEN a header object
head = HeaderParser()
assert 'MQ' not in head.info_dict
info_line = '##INFO=<ID=MQ,Number=1,Type=Float,Description="RMS Mapping Quality",Source="bwa",Version="1.0.0">'

## WHEN parsing a correct info line
head.parse_meta_data(info_line)

## THEN assert it is added to the parser
assert 'MQ' in head.info_dict

def test_parse_contig():
## GIVEN a header object
Expand Down

0 comments on commit fca33bd

Please sign in to comment.