Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "Source" and "Version" in INFO header #106

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>[^"]+)")?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 💯

>''', 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():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏅

## 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
Loading