-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
301 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "pgscatalog.match" | ||
version = "0.3.2" | ||
version = "0.3.3" | ||
description = "Tools for matching variants in PGS scoring files and target variant information files" | ||
authors = ["Benjamin Wingfield <[email protected]>", "Samuel Lambert <[email protected]>", "Laurent Gil <[email protected]>"] | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
pgscatalog.match/src/pgscatalog/match/lib/normalisedscoringfile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import csv | ||
|
||
from xopen import xopen | ||
|
||
from pgscatalog.core.lib.models import ScoreVariant | ||
|
||
|
||
def _read_normalised_rows(path): | ||
with xopen(path) as f: | ||
reader = csv.DictReader(f, delimiter="\t") | ||
for row in reader: | ||
yield ScoreVariant(**row) | ||
|
||
|
||
class NormalisedScoringFile: | ||
"""This class represents a ScoringFile that's been normalised to have a consistent format | ||
Its main purpose is to provide a convenient way to iterate over variants | ||
# TODO: replace with a pydantic model in pgscatalog.core | ||
""" | ||
|
||
def __init__(self, path): | ||
try: | ||
with xopen(path): | ||
pass | ||
except TypeError: | ||
self.is_path = False | ||
self.path = str(path) | ||
else: | ||
self.is_path = True | ||
self.path = path | ||
finally: | ||
# either a ScoringFile or a path to a combined file | ||
self._scoringfile = path | ||
|
||
def __iter__(self): | ||
yield from self.variants | ||
|
||
@property | ||
def variants(self): | ||
if self.is_path: | ||
# get a fresh generator from the file | ||
self._variants = _read_normalised_rows(self._scoringfile) | ||
else: | ||
# get a fresh generator from the normalise() method | ||
self._variants = self._scoringfile.normalise() | ||
|
||
return self._variants | ||
|
||
def __repr__(self): | ||
if self.is_path: | ||
x = f"{repr(str(self._scoringfile))}" | ||
else: | ||
x = f"{repr(self._scoringfile)}" | ||
|
||
return f"{type(self).__name__}({x})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.