Skip to content

Commit

Permalink
Raise an exception if unable to parse ProteinMetadata from Uniprot …
Browse files Browse the repository at this point in the history
…JSON.
  • Loading branch information
ielis committed Nov 13, 2024
1 parent ede82e5 commit 9b6a6b1
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/gpsea/model/_protein.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,19 +368,16 @@ def from_uniprot_json(

regions = list()
for feature in data["features"]:
try:
region_name = feature["description"]
locus = feature["location"]
region_start = int(locus["start"]["value"]) - 1 # convert to 0-based coordinates
region_end = int(locus["end"]["value"])
feature_type = FeatureType.from_string(feature["type"])
finfo = FeatureInfo(
name=region_name, region=Region(start=region_start, end=region_end)
)
pfeature = ProteinFeature.create(info=finfo, feature_type=feature_type)
regions.append(pfeature)
except Exception as feature_exception:
print(f"Could not parse feature: {str(feature_exception)} (skipping)")
region_name = feature["description"]
locus = feature["location"]
region_start = int(locus["start"]["value"]) - 1 # convert to 0-based coordinates
region_end = int(locus["end"]["value"])
feature_type = FeatureType.from_string(feature["type"])
finfo = FeatureInfo(
name=region_name, region=Region(start=region_start, end=region_end)
)
pfeature = ProteinFeature.create(info=finfo, feature_type=feature_type)
regions.append(pfeature)

return ProteinMetadata(
protein_id=protein_id,
Expand Down

0 comments on commit 9b6a6b1

Please sign in to comment.