Skip to content

Commit

Permalink
Delint
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed May 1, 2023
1 parent 51c48bc commit a245367
Show file tree
Hide file tree
Showing 64 changed files with 565 additions and 908 deletions.
2 changes: 1 addition & 1 deletion docker/rest-blaze.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def getTTLFiles():


class NIDMRest(Resource):
def get(self, all):
def get(self, all): # noqa: A002
query_bits = []
for a in request.args.keys():
query_bits.append("{}={}".format(a, request.args.get(a)))
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

# General information about the project.
project = "PyNIDM"
copyright = "2018, [email protected], [email protected], [email protected], [email protected]"
copyright = "2018, [email protected], [email protected], [email protected], [email protected]" # noqa: A001
author = "[email protected], [email protected], [email protected], [email protected]"

# The version info for the project you're documenting, acts as replacement for
Expand Down
3 changes: 0 additions & 3 deletions nidm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import, division, print_function
import __main__

__version__ = "3.9.7"

try:
Expand Down
4 changes: 2 additions & 2 deletions nidm/core/BIDS_Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
# JSON file keys
json_keys = {
##Image terms
# Image terms
"run": Constants.NIDM_ACQUISITION_ENTITY,
"ImageType": Constants.DICOM["ImageType"],
"ManufacturerModelName": Constants.DICOM["ManufacturerModelName"],
Expand Down Expand Up @@ -108,7 +108,7 @@
"NumberDiscardedVolumesByUser": Constants.NIDM["NumberDiscardedVolumesByUser"],
"DelayTime": Constants.NIDM["DelayTime"],
"PulseSequenceType": Constants.DICOM["PulseSequenceName"],
###Task Stuff
# Task Stuff
"TaskName": Constants.NIDM_MRI_FUNCTION_TASK
# "CogAtlasID" :
# "CogPOID" :
Expand Down
4 changes: 2 additions & 2 deletions nidm/core/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Added Python provtoolbox support
10/3/17 Modified Namespace to be QualifiedName for provtoolbox support...left most of the NIDM-Results Namespaces the same
@author: Sanu Ann Abraham <[email protected]>
05/04/2018 Added python ProvONE support
05/04/2018 Added python ProvONE support
"""
from collections import namedtuple
from prov.constants import PROV_ATTRIBUTE_LITERALS, PROV_ATTRIBUTE_QNAMES, PROV_N_MAP
Expand Down Expand Up @@ -604,7 +604,7 @@ def __init__(self, namespaces=None):
)


####ADDED BY DBK to make searching NIDM-Experiment Terms easier...temporary, should be done in the OWL file#####
# ADDED BY DBK to make searching NIDM-Experiment Terms easier...temporary, should be done in the OWL file #
nidm_experiment_terms = [
NIDM_PROJECT,
NIDM_PROJECT_IDENTIFIER,
Expand Down
28 changes: 24 additions & 4 deletions nidm/core/dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from cgi import escape

from datetime import datetime
from prov.dot import DOT_PROV_STYLE
from prov.model import (
PROV_ACTIVITY,
PROV_AGENT,
Expand Down Expand Up @@ -47,7 +46,28 @@
)
import pydot
import six
from .Constants import *
from .Constants import (
PROVONE_ATTRIBUTE_QNAMES,
PROVONE_CLTODESTP,
PROVONE_DATA,
PROVONE_DATALINK,
PROVONE_DATAONLINK,
PROVONE_DLTOINPORT,
PROVONE_DLTOOUTPORT,
PROVONE_HASINPORT,
PROVONE_HASOUTPORT,
PROVONE_HASSUBPROCESS,
PROVONE_INPORTTODL,
PROVONE_INPUTPORT,
PROVONE_ISPARTOF,
PROVONE_OUTPORTTODL,
PROVONE_OUTPUTPORT,
PROVONE_PROCESS,
PROVONE_PROCESSEXEC,
PROVONE_SEQCTRLLINK,
PROVONE_SOURCEPTOCL,
PROVONE_USER,
)

__author__ = "Sanu Ann Abraham"
__email__ = "[email protected]"
Expand Down Expand Up @@ -381,8 +401,8 @@ def _get_node(qname):
relations.append(rec)

if not bundle.is_bundle():
for bundle in bundle.bundles:
_add_bundle(bundle)
for b in bundle.bundles:
_add_bundle(b)

for rec in relations:
args = rec.args
Expand Down
4 changes: 1 addition & 3 deletions nidm/core/provone.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
PROVONE_ATTR_PLAN,
PROVONE_ATTR_PROCESS,
PROVONE_ATTR_PROCESSEXEC,
PROVONE_ATTR_RELATED_PREXEC,
PROVONE_ATTR_SEQCTRLLINK,
PROVONE_ATTR_USED_DATA,
PROVONE_ATTR_USED_PREXEC,
Expand All @@ -76,7 +75,6 @@
PROVONE_INPORTTODL,
PROVONE_INPUTPORT,
PROVONE_ISPARTOF,
PROVONE_MEMBERSHIP,
PROVONE_N_MAP,
PROVONE_OUTPORTTODL,
PROVONE_OUTPUTPORT,
Expand Down Expand Up @@ -882,7 +880,7 @@ def parameterization(
other_attributes,
)

def serialize(self, destination=None, format="json", **args):
def serialize(self, destination=None, format="json", **args): # noqa: A002
"""
Serialize the :py:class:`ProvDocument` to the destination.
Expand Down
107 changes: 53 additions & 54 deletions nidm/core/serializers/provonerdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
PROV_DERIVATION,
PROV_END,
PROV_GENERATION,
PROV_ID_ATTRIBUTES_MAP,
PROV_INVALIDATION,
PROV_LOCATION,
PROV_MENTION,
Expand Down Expand Up @@ -258,7 +257,7 @@ def encode_container(self, bundle, container=None, identifier=None):
record.attributes
)
formal_qualifiers = False
for attrid, (attr, value) in enumerate(list(record.formal_attributes)):
for attrid, (_, value) in enumerate(list(record.formal_attributes)):
if (identifier is not None and value is not None) or (
identifier is None and value is not None and attrid > 1
):
Expand All @@ -284,10 +283,7 @@ def encode_container(self, bundle, container=None, identifier=None):
if identifier is None and subj is not None:
try:
obj_val = record.formal_attributes[1][1]
obj_attr = URIRef(
record.formal_attributes[1][0].uri
)
# TODO: Why is obj_attr above not used anywhere?
URIRef(record.formal_attributes[1][0].uri)
except IndexError:
obj_val = None
if obj_val and (
Expand Down Expand Up @@ -478,7 +474,7 @@ def decode_container(self, graph, bundle):
PROV_CLS_MAP = {}
formal_attributes = {}
unique_sets = {}
for key, val in PROV_BASE_CLS.items():
for key, _ in PROV_BASE_CLS.items():
PROV_CLS_MAP[key.uri] = PROV_BASE_CLS[key]
relation_mapper = {
URIRef(PROV["alternateOf"].uri): "alternate",
Expand Down Expand Up @@ -511,11 +507,14 @@ def decode_container(self, graph, bundle):
}
other_attributes = {}
for stmt in graph.triples((None, RDF.type, None)):
id = six.text_type(stmt[0])
id_ = six.text_type(stmt[0])
obj = six.text_type(stmt[2])
if obj in PROV_CLS_MAP:
if not isinstance(stmt[0], BNode) and self.valid_identifier(id) is None:
prefix, iri, _ = graph.namespace_manager.compute_qname(id)
if (
not isinstance(stmt[0], BNode)
and self.valid_identifier(id_) is None
):
prefix, iri, _ = graph.namespace_manager.compute_qname(id_)
self.document.add_namespace(prefix, iri)
try:
prov_obj = PROV_CLS_MAP[obj]
Expand All @@ -528,53 +527,53 @@ def decode_container(self, graph, bundle):
or pm.PROV["PrimarySource"].uri in stmt[2]
)
if (
id not in ids
id_ not in ids
and prov_obj
and (
prov_obj.uri == obj
or isderivation
or isinstance(stmt[0], BNode)
)
):
ids[id] = prov_obj
ids[id_] = prov_obj
klass = pm.PROV_REC_CLS[prov_obj]
formal_attributes[id] = OrderedDict(
formal_attributes[id_] = OrderedDict(
[(key, None) for key in klass.FORMAL_ATTRIBUTES]
)
unique_sets[id] = OrderedDict(
unique_sets[id_] = OrderedDict(
[(key, []) for key in klass.FORMAL_ATTRIBUTES]
)
add_attr = False or (
(isinstance(stmt[0], BNode) or isderivation)
and prov_obj.uri != obj
)
if add_attr:
if id not in other_attributes:
other_attributes[id] = []
if id_ not in other_attributes:
other_attributes[id_] = []
obj_formatted = self.decode_rdf_representation(stmt[2], graph)
other_attributes[id].append((pm.PROV["type"], obj_formatted))
other_attributes[id_].append((pm.PROV["type"], obj_formatted))
else:
if id not in other_attributes:
other_attributes[id] = []
if id_ not in other_attributes:
other_attributes[id_] = []
obj = self.decode_rdf_representation(stmt[2], graph)
other_attributes[id].append((pm.PROV["type"], obj))
for id, pred, obj in graph:
id = six.text_type(id)
if id not in other_attributes:
other_attributes[id] = []
other_attributes[id_].append((pm.PROV["type"], obj))
for id_, pred, obj in graph:
id_ = six.text_type(id_)
if id_ not in other_attributes:
other_attributes[id_] = []
if pred == RDF.type:
continue
if pred in relation_mapper:
if "alternateOf" in pred:
getattr(bundle, relation_mapper[pred])(obj, id)
getattr(bundle, relation_mapper[pred])(obj, id_)
elif "mentionOf" in pred:
mentionBundle = None
for stmt in graph.triples(
(URIRef(id), URIRef(pm.PROV["asInBundle"].uri), None)
(URIRef(id_), URIRef(pm.PROV["asInBundle"].uri), None)
):
mentionBundle = stmt[2]
getattr(bundle, relation_mapper[pred])(
id, six.text_type(obj), mentionBundle
id_, six.text_type(obj), mentionBundle
)
elif "actedOnBehalfOf" in pred or "wasAssociatedWith" in pred:
qualifier = (
Expand All @@ -584,83 +583,83 @@ def decode_container(self, graph, bundle):
)
qualifier_bnode = None
for stmt in graph.triples(
(URIRef(id), URIRef(pm.PROV[qualifier].uri), None)
(URIRef(id_), URIRef(pm.PROV[qualifier].uri), None)
):
qualifier_bnode = stmt[2]
if qualifier_bnode is None:
getattr(bundle, relation_mapper[pred])(id, six.text_type(obj))
getattr(bundle, relation_mapper[pred])(id_, six.text_type(obj))
else:
fakeys = list(
formal_attributes[six.text_type(qualifier_bnode)].keys()
)
formal_attributes[six.text_type(qualifier_bnode)][
fakeys[0]
] = id
] = id_
formal_attributes[six.text_type(qualifier_bnode)][
fakeys[1]
] = six.text_type(obj)
else:
getattr(bundle, relation_mapper[pred])(id, six.text_type(obj))
elif id in ids:
getattr(bundle, relation_mapper[pred])(id_, six.text_type(obj))
elif id_ in ids:
obj1 = self.decode_rdf_representation(obj, graph)
if obj is not None and obj1 is None:
raise ValueError(("Error transforming", obj))
pred_new = pred
if pred in predicate_mapper:
pred_new = predicate_mapper[pred]
if ids[id] == PROV_COMMUNICATION and "activity" in six.text_type(
if ids[id_] == PROV_COMMUNICATION and "activity" in six.text_type(
pred_new
):
pred_new = PROV_ATTR_INFORMANT
if ids[id] == PROV_DELEGATION and "agent" in six.text_type(pred_new):
if ids[id_] == PROV_DELEGATION and "agent" in six.text_type(pred_new):
pred_new = PROV_ATTR_RESPONSIBLE
if ids[id] in [PROV_END, PROV_START] and "entity" in six.text_type(
if ids[id_] in [PROV_END, PROV_START] and "entity" in six.text_type(
pred_new
):
pred_new = PROV_ATTR_TRIGGER
if ids[id] in [PROV_END] and "activity" in six.text_type(pred_new):
if ids[id_] in [PROV_END] and "activity" in six.text_type(pred_new):
pred_new = PROV_ATTR_ENDER
if ids[id] in [PROV_START] and "activity" in six.text_type(pred_new):
if ids[id_] in [PROV_START] and "activity" in six.text_type(pred_new):
pred_new = PROV_ATTR_STARTER
if ids[id] == PROV_DERIVATION and "entity" in six.text_type(pred_new):
if ids[id_] == PROV_DERIVATION and "entity" in six.text_type(pred_new):
pred_new = PROV_ATTR_USED_ENTITY
if six.text_type(pred_new) in [
val.uri for val in formal_attributes[id]
val.uri for val in formal_attributes[id_]
]:
qname_key = self.valid_identifier(pred_new)
formal_attributes[id][qname_key] = obj1
unique_sets[id][qname_key].append(obj1)
if len(unique_sets[id][qname_key]) > 1:
formal_attributes[id][qname_key] = None
formal_attributes[id_][qname_key] = obj1
unique_sets[id_][qname_key].append(obj1)
if len(unique_sets[id_][qname_key]) > 1:
formal_attributes[id_][qname_key] = None
else:
if "qualified" not in six.text_type(
pred_new
) and "asInBundle" not in six.text_type(pred_new):
other_attributes[id].append((six.text_type(pred_new), obj1))
other_attributes[id_].append((six.text_type(pred_new), obj1))
local_key = six.text_type(obj)
if local_key in ids:
if "qualified" in pred:
formal_attributes[local_key][
list(formal_attributes[local_key].keys())[0]
] = id
for id in ids:
] = id_
for id_ in ids:
attrs = None
if id in other_attributes:
attrs = other_attributes[id]
if id_ in other_attributes:
attrs = other_attributes[id_]
items_to_walk = []
for qname, values in unique_sets[id].items():
for qname, values in unique_sets[id_].items():
if values and len(values) > 1:
items_to_walk.append((qname, values))
if items_to_walk:
for subset in list(walk(items_to_walk)):
for key, value in subset.items():
formal_attributes[id][key] = value
bundle.new_record(ids[id], id, formal_attributes[id], attrs)
formal_attributes[id_][key] = value
bundle.new_record(ids[id_], id_, formal_attributes[id_], attrs)
else:
bundle.new_record(ids[id], id, formal_attributes[id], attrs)
ids[id] = None
bundle.new_record(ids[id_], id_, formal_attributes[id_], attrs)
ids[id_] = None
if attrs is not None:
other_attributes[id] = []
other_attributes[id_] = []
for key, val in other_attributes.items():
if val:
ids[key].add_attributes(val)
Expand Down
3 changes: 2 additions & 1 deletion nidm/core/tests/test_provone.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# from nidm.core.provone import ProvONEDocument
from nidm.core import Constants
from nidm.core.dot import provone_to_dot
import pytest

Expand All @@ -11,6 +10,8 @@
@pytest.fixture(scope="module")
def doc():
# Create new provone document with namespaces
from nidm.core.provone import ProvONEDocument

d1 = ProvONEDocument()
d1.add_namespace("dcterms", "http://purl.org/dc/terms/")
d1.add_namespace("wfms", "http://www.wfms.org/registry/")
Expand Down
5 changes: 0 additions & 5 deletions nidm/experiment/Acquisition.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import os
import sys
import prov.model as pm
import rdflib as rdf

# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from ..core import Constants
from ..experiment import Core
from ..experiment.Core import getUUID
Expand Down
Loading

0 comments on commit a245367

Please sign in to comment.