Skip to content

Commit

Permalink
Add sdk.utils.compare_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
sbslee committed Nov 27, 2021
1 parent a32ce10 commit 8ece6ed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Changelog
* Add new method :meth:`sdk.utils.Archive.check_metadata`.
* Add new error ``sdk.utils.IncorrectMetadataError``.
* Update :command:`run-ngs-pipeline` command to check input files more vigorously.
* Add new method :meth:`sdk.utils.compare_metadata`.

0.8.0 (2021-11-20)
------------------
Expand Down
4 changes: 2 additions & 2 deletions pypgx/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,6 @@ def train_cnv_caller(copy_number, cnv_calls, confusion_matrix=None):

cnv_calls.check_type('SampleTable[CNVCalls]')

copy_number = _process_copy_number(copy_number)

gene1 = copy_number.metadata['Gene']
gene2 = cnv_calls.metadata['Gene']

Expand All @@ -1177,6 +1175,8 @@ def train_cnv_caller(copy_number, cnv_calls, confusion_matrix=None):
raise ValueError("Different genes detected, CovFrame[CopyNumber] "
f"has '{assembly1}' and SampleTable[CNVCalls] has '{assembly2}'")

copy_number = _process_copy_number(copy_number)

cnv_table = core.load_cnv_table()
cnv_table = cnv_table[cnv_table.Gene == copy_number.metadata['Gene']]
name2code = dict(zip(cnv_table.Name, cnv_table.Code))
Expand Down
4 changes: 2 additions & 2 deletions pypgx/sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .utils import (Archive, parse_input_bams)
from .utils import (Archive, parse_input_bams, compare_metadata)

__all__ = ['Archive', 'parse_input_bams']
__all__ = ['Archive', 'parse_input_bams', 'compare_metadata']
14 changes: 14 additions & 0 deletions pypgx/sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ def check_metadata(self, key, value):
f"Expected '{key}={value}' but found '{key}={actual_value}' "
f"for semantic type '{semantic_type}'")

def compare_metadata(a, b, key):
"""
Raise IncorrectMetadataError if two archives have different values for
specified metadata key.
"""
type1 = a.metadata['SemanticType']
type2 = a.metadata['SemanticType']
value1 = a.metadata[key]
value2 = b.metadata[key]
if value1 != value2:
raise IncorrectMetadataError(
f"First archive '{type1}' has '{key}={value1}' and second "
f"archive '{type2}' has '{key}={value2}'")

def zipdir(dir, output):
"""
Create a ZIP archive of a directory.
Expand Down

0 comments on commit 8ece6ed

Please sign in to comment.