Skip to content

Commit

Permalink
fix factor IDs for result sets
Browse files Browse the repository at this point in the history
  • Loading branch information
oganm committed Aug 8, 2024
1 parent fe15d45 commit a5068c0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
29 changes: 24 additions & 5 deletions gemmapy/_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def process_dea(d):
d[i].result_sets[j].experimental_factors = [d[i].result_sets[j].experimental_factors[k] for k in order]
exp_factors = d[i].result_sets[j].experimental_factors


if len(exp_factors) == 1:
contrast_id = [x.id for x in exp_factors[0].values]
baseline_id = d[i].result_sets[j].baseline_group.id
Expand All @@ -128,6 +129,18 @@ def process_dea(d):
size = len(contrast_id)

experimental_factors = [sub.process_FactorValueValueObject(x) for x in non_control_factors]

factor_ID = d[i].result_sets[j].experimental_factors[0].id
factor_category = d[i].result_sets[j].experimental_factors[0].category
factor_category_URI = d[i].result_sets[j].experimental_factors[0].category_uri

def add_missing(x):
x.factor_ID = factor_ID
x.factor_category = factor_category
x.factor_category_URI = factor_category_URI
return x

experimental_factors = [add_missing(x) for x in experimental_factors]
baseline_factors = sub.process_FactorValueBasicValueObject(d[i].result_sets[j].baseline_group)

else:
Expand All @@ -144,11 +157,17 @@ def process_dea(d):

relevant_ids = [x for x in ids if not any(sub.list_in_list(x, baseline_ids))]

fac_vals = [sub.access_field(y,'values') for y in exp_factors]
all_factors = pd.concat(
[sub.process_FactorValueValueObject_list(y) for y in fac_vals],
ignore_index = True
)
def get_factor_vals(x):
vals = sub.access_field(x,'values')
out = sub.process_FactorValueValueObject_list(vals)
out.factor_ID = x.id
out.factor_category = x.category
out.factor_category_URI = x.category_uri
return out

all_factors = pd.concat([get_factor_vals(x) for x in exp_factors])



baseline_factors = all_factors.loc[all_factors.ID.isin(baseline_ids)]
experimental_factors = [
Expand Down
2 changes: 1 addition & 1 deletion gemmapy/_subprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def process_FactorValueBasicValueObject(d):
"factor_category":[],
"factor_category_URI":[]
})
elif not d.measurement is None:
elif d.is_measurement:
return pd.DataFrame({
'category': [access_field(d,"category")],
"category_URI": [access_field(d,"category_uri")],
Expand Down
28 changes: 27 additions & 1 deletion gemmapy/sdk/models/factor_value_basic_value_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class FactorValueBasicValueObject(object):
and the value is json key in definition.
"""
swagger_types = {
'measurement': 'MeasurementValueObject',
'id': 'int',
'ontology_id': 'str',
'experimental_factor_id': 'int',
Expand All @@ -40,6 +41,7 @@ class FactorValueBasicValueObject(object):
}

attribute_map = {
'measurement': 'measurement',
'id': 'id',
'ontology_id': 'ontologyId',
'experimental_factor_id': 'experimentalFactorId',
Expand All @@ -51,8 +53,9 @@ class FactorValueBasicValueObject(object):
'is_measurement': 'isMeasurement'
}

def __init__(self, id=None, ontology_id=None, experimental_factor_id=None, experimental_factor_category=None, characteristics=None, statements=None, summary=None, value=None, is_measurement=None): # noqa: E501
def __init__(self, measurement=None, id=None, ontology_id=None, experimental_factor_id=None, experimental_factor_category=None, characteristics=None, statements=None, summary=None, value=None, is_measurement=None): # noqa: E501
"""FactorValueBasicValueObject - a model defined in Swagger""" # noqa: E501
self._measurement = None
self._id = None
self._ontology_id = None
self._experimental_factor_id = None
Expand All @@ -63,6 +66,8 @@ def __init__(self, id=None, ontology_id=None, experimental_factor_id=None, exper
self._value = None
self._is_measurement = None
self.discriminator = None
if measurement is not None:
self.measurement = measurement
if id is not None:
self.id = id
if ontology_id is not None:
Expand All @@ -82,6 +87,27 @@ def __init__(self, id=None, ontology_id=None, experimental_factor_id=None, exper
if is_measurement is not None:
self.is_measurement = is_measurement

@property
def measurement(self):
"""Gets the measurement of this FactorValueBasicValueObject. # noqa: E501
:return: The measurement of this FactorValueBasicValueObject. # noqa: E501
:rtype: MeasurementValueObject
"""
return self._measurement

@measurement.setter
def measurement(self, measurement):
"""Sets the measurement of this FactorValueBasicValueObject.
:param measurement: The measurement of this FactorValueBasicValueObject. # noqa: E501
:type: MeasurementValueObject
"""

self._measurement = measurement

@property
def id(self):
"""Gets the id of this FactorValueBasicValueObject. # noqa: E501
Expand Down
2 changes: 2 additions & 0 deletions sdk-gen/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3441,6 +3441,8 @@ components:
FactorValueBasicValueObject:
type: object
properties:
measurement:
$ref: '#/components/schemas/MeasurementValueObject'
id:
type: integer
format: int64
Expand Down

0 comments on commit a5068c0

Please sign in to comment.