Skip to content

Commit 27d9d5d

Browse files
committed
Created custom parser for PMIDB
Since one file has headers while the others don't
1 parent dd72c24 commit 27d9d5d

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

‎pypath/inputs_v2/pmidb.py‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Dataset,
1717
ontology_entity_mapper,
1818
)
19-
from pypath.inputs_v2.parsers import brenda as _parsers
19+
from pypath.inputs_v2.parsers.base import iter_tsv, _first_handle
2020
from pypath.internals.tabular_builder import (
2121
AssociationBuilder,
2222
AssociationsBuilder,
@@ -46,7 +46,7 @@
4646
license=LicenseCV.UNSPECIFIED,
4747
update_category=UpdateCategoryCV.IRREGULAR,
4848
pubmed='33554247',
49-
primary_category='intercell',
49+
primary_category='interactions',
5050
description=(
5151
'PMIDB provides both interactions and non-interactions between protein '
5252
'and metabolite, which not only reduces the experimental cost for '
@@ -67,7 +67,27 @@
6767
for f in files
6868
}
6969

70-
#def parser(opener, skiprows):
70+
def parser(opener, header=None, sep='\t'):
71+
72+
if header is not None and iter(header):
73+
74+
entries = [line.strip().split(sep) for line in _first_handle(opener)]
75+
76+
if x := len(entries[0]) - len(header):
77+
78+
raise KeyError(
79+
'Length of header is %s than the number of entries'
80+
% ('smaller' if x > 0 else 'larger')
81+
)
82+
83+
yield from [
84+
{k: v for k, v in zip(header, line)}
85+
for line in entries
86+
]
87+
88+
else:
89+
90+
return iter_tsv(opener)
7191

7292
# =================================== SCHEMA ===================================
7393

0 commit comments

Comments
 (0)