Skip to content

Commit

Permalink
Merge pull request #1915 from 4dn-dcic/ajs_241025_upd_trtmt_title
Browse files Browse the repository at this point in the history
Update treatment item display title
  • Loading branch information
aschroed authored Nov 5, 2024
2 parents 85a392a + d72b6de commit 40adc80
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 5 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ fourfront
Change Log
----------


8.4.3
=====

`Update treatment item display title <https://github.com/4dn-dcic/fourfront/pull/1915>`_

* Add 'override_treatment_title' property to Treatment items
* Tweak the display_title calcprop to:
- use the override_treatment_title prop if present
- for biological treatments with constructs but no biological agent use construct names in treatment display_title
* added tests


8.4.2
=====

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
# Note: Various modules refer to this system as "encoded", not "fourfront".
name = "encoded"
version = "8.4.2"
version = "8.4.3"
description = "4DN-DCIC Fourfront"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down
5 changes: 5 additions & 0 deletions src/encoded/schemas/treatment.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"type": "string",
"lookup": 1000,
"format": "uri"
},
"override_treatment_title": {
"title": "Override display title",
"type": "string",
"lookup": 1000
}
},
"facets": {
Expand Down
28 changes: 28 additions & 0 deletions src/encoded/tests/data/inserts/treatment_agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,33 @@
"submitted_by": "[email protected]",
"temperature": 20,
"status": "in review by lab"
},
{
"uuid": "05501f04-360a-438a-87d7-443311fc6831",
"aliases": ["dcic:ba-treatment-1"],
"description": "Biological treatment with agent",
"treatment_type": "Biological",
"biological_agent": "Green Virus",
"duration": 24,
"duration_units": "hour",
"award": "1U01CA200059-01",
"lab": "4dn-dcic-lab",
"submitted_by": "[email protected]",
"temperature": 37,
"status": "in review by lab"
},
{
"uuid": "dee3576a-5e03-4390-88c2-1b4f73cc294e",
"aliases": ["dcic:biol_w_constructs"],
"description": "Biological treatment with construct",
"treatment_type": "Biological",
"constructs": ["131106bc-8535-4448-903e-854af460b211"],
"duration": 24,
"duration_units": "hour",
"award": "1U01CA200059-01",
"lab": "4dn-dcic-lab",
"submitted_by": "[email protected]",
"temperature": 37,
"status": "in review by lab"
}
]
51 changes: 51 additions & 0 deletions src/encoded/tests/test_types_treatment.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ def viral_treatment(testapp, lab, award):
return testapp.post_json('/treatment_agent', item).json['@graph'][0]


@pytest.fixture
def construct_based_treatment(testapp, lab, award, construct):
item = {
'award': award['@id'],
'lab': lab['@id'],
'treatment_type': 'Biological',
'constructs': [construct],
'duration': 3.5,
'duration_units': 'hour'
}
return testapp.post_json('/treatment_agent', item).json['@graph'][0]


@pytest.fixture
def heatshock_treatment(testapp, lab, award):
item = {
Expand Down Expand Up @@ -88,3 +101,41 @@ def test_calculated_rnai_treatment_display_title(testapp, rnai, gene_bio_feature
assert rnai['display_title'] == 'shRNA treatment'
res = testapp.patch_json(rnai['@id'], {'target': [gene_bio_feature['@id']]})
assert res.json['@graph'][0]['display_title'] == 'shRNA of RAD21 gene'


def test_calculated_treatment_agent_w_override_display_title(testapp, drug_treatment):
assert drug_treatment['display_title'] == 'Drug treatment'
res = testapp.patch_json(drug_treatment['@id'], {'override_treatment_title': 'New drug treatment'})
assert res.json['@graph'][0]['display_title'] == 'New drug treatment'


def test_calculated_rnai_treatment_w_override_display_title(testapp, rnai):
assert rnai['display_title'] == 'shRNA treatment'
res = testapp.patch_json(rnai['@id'], {'override_treatment_title': 'New RNAi treatment'})
assert res.json['@graph'][0]['display_title'] == 'New RNAi treatment'


def test_calculated_biological_treatment_w_construct_display_title(
construct_based_treatment, construct):
assert construct.get('display_title') in construct_based_treatment.get('display_title')


def test_calculated_biological_treatment_w_multiple_constructs_display_title(
testapp, construct_based_treatment, lab, award):
c_name = 'super_construct_'
c_type = 'expression construct'
constructs = []
for i in range(1, 5):
cmeta = {
'name': c_name + str(i),
'construct_type': c_type,
'lab': lab['@id'],
'award': award['@id']
}
constructs.append(testapp.post_json('/construct', cmeta).json['@graph'][0])
# test display_title with 2 constructs
res = testapp.patch_json(construct_based_treatment['@id'], {'constructs': [c['@id'] for c in constructs[:2]]})
assert res.json['@graph'][0]['display_title'] == 'super_construct_1, super_construct_2 treatment (3.5h)'
# test with 4 constructs
res = testapp.patch_json(construct_based_treatment['@id'], {'constructs': [c['@id'] for c in constructs]})
assert res.json['@graph'][0]['display_title'] == 'super_construct_1, super_construct_2, super_construct_3 and 1 more treatment (3.5h)'
29 changes: 25 additions & 4 deletions src/encoded/types/treatment.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ class TreatmentAgent(Treatment):
def display_title(self, request, treatment_type=None, chemical=None,
biological_agent=None, constructs=None, duration=None,
duration_units=None, concentration=None,
concentration_units=None, temperature=None):
concentration_units=None, temperature=None,
override_treatment_title=None):
conditions = ""
if override_treatment_title:
return override_treatment_title
if concentration and concentration_units:
conditions += str(concentration) + " " + concentration_units
if duration and duration_units:
Expand All @@ -91,8 +94,24 @@ def display_title(self, request, treatment_type=None, chemical=None,
[get_item_or_none(request, construct).get('name') for construct in constructs]
)
disp_title = "Transient transfection of " + plasmids + conditions
elif treatment_type == "Biological" and biological_agent:
disp_title = biological_agent + " treatment" + conditions
elif treatment_type == "Biological":
disp_title = ''
if biological_agent or constructs:
if biological_agent:
disp_title = biological_agent + " treatment" + conditions
else:
const_str = ''
suffix = ''
if len(constructs) > 3:
suffix = ' and {} more'.format(len(constructs) - 3)
constructs = constructs[0:3]
const_str = ", ".join(
[get_item_or_none(request, construct).get('display_title') for construct in constructs]
)
const_str = const_str.rstrip(", ")
disp_title = const_str + suffix + " treatment" + conditions
else:
pass
else:
disp_title = treatment_type + conditions
return disp_title
Expand Down Expand Up @@ -128,7 +147,9 @@ class TreatmentRnai(Treatment):
"description": "A calculated title for every object in 4DN",
"type": "string"
})
def display_title(self, request, rnai_type=None, target=None):
def display_title(self, request, rnai_type=None, target=None, override_treatment_title=None):
if override_treatment_title:
return override_treatment_title
if rnai_type and target:
tstring = ''
for t in target:
Expand Down

0 comments on commit 40adc80

Please sign in to comment.