Skip to content

Commit 136efdb

Browse files
committed
Merge pull request #349 from ENCODE-DCC/fix-search
Fix for data change from elasticsearch; caused missing data in searches.
2 parents 0ca79c5 + 049e44c commit 136efdb

File tree

1 file changed

+86
-40
lines changed

1 file changed

+86
-40
lines changed

src/encoded/static/components/search.js

Lines changed: 86 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ var Dbxref = dbxref.Dbxref;
109109
var age = (result['age'] && result['age'] != 'unknown') ? ' ' + result['age'] : '';
110110
var ageUnits = (result['age_units'] && result['age_units'] != 'unknown' && age) ? ' ' + result['age_units'] : '';
111111
var separator = (lifeStage || age) ? ',' : '';
112+
var rnais = (result.rnais[0] && result.rnais[0].target && result.rnais[0].target.label) ? result.rnais[0].target.label : '';
113+
var constructs = (result.constructs[0] && result.constructs[0].target && result.constructs[0].target.label) ? result.constructs[0].target.label : '';
114+
var treatment = (result.treatments[0] && result.treatments[0].treatment_term_name) ? result.treatments[0].treatment_term_name : '';
112115
return (<li>
113116
<div>
114117
{this.renderActions()}
@@ -127,22 +130,22 @@ var Dbxref = dbxref.Dbxref;
127130
</div>
128131
<div className="data-row">
129132
<div><strong>{columns['biosample_type']['title']}</strong>: {result['biosample_type']}</div>
130-
{result['rnais.target.label'] ?
133+
{rnais ?
131134
<div>
132135
<strong>{columns['rnais.target.label']['title'] + ': '}</strong>
133-
{result['rnais.target.label']}
136+
{rnais}
134137
</div>
135138
: null}
136-
{result['constructs.target.label'] ?
139+
{constructs ?
137140
<div>
138141
<strong>{columns['constructs.target.label']['title'] + ': '}</strong>
139-
{result['constructs.target.label']}
142+
{constructs}
140143
</div>
141144
: null}
142-
{result['treatments.treatment_term_name'] ?
145+
{treatment ?
143146
<div>
144147
<strong>{columns['treatments.treatment_term_name']['title'] + ': '}</strong>
145-
{result['treatments.treatment_term_name']}
148+
{treatment}
146149
</div>
147150
: null}
148151
<div><strong>{columns['source.title']['title']}</strong>: {result['source.title']}</div>
@@ -154,47 +157,90 @@ var Dbxref = dbxref.Dbxref;
154157
globals.listing_views.register(Biosample, 'biosample');
155158

156159

157-
// Returns array length if array 'a' with 1st index 'i' contains all same non-'unknown' value in its 2nd index
158-
// 0 if 'a' contains an 'unknown' value, non-'unknown' values differ, or 'a' has no elements
159-
function homogenousArray(a, i) {
160-
var aLen = a[i] ? a[i].length : 0;
161-
var j = 0;
162-
163-
if (aLen > 0) {
164-
var a0 = a[i][0];
165-
if (a0 !== 'unknown' && a0 !== '') {
166-
for (j = 1; j < aLen; j++) {
167-
if (a[i][j] === 'unknown' || a[i][j] !== a0) {
168-
break;
169-
}
170-
}
171-
}
172-
return j === aLen ? aLen : 0;
173-
}
174-
return 0;
175-
}
176-
177160
var Experiment = module.exports.Experiment = React.createClass({
178161
mixins: [PickerActionsMixin],
179162
render: function() {
180163
var result = this.props.context;
181164
var columns = this.props.columns;
182-
var age = '';
183-
var ageUnits = '';
184165

185166
// See if all life stage, age, and age_unit arrays are all homogeneous
186-
var name = homogenousArray(result, 'replicates.library.biosample.organism.scientific_name') ?
187-
result['replicates.library.biosample.organism.scientific_name'][0] : '';
188-
var lifeStage = homogenousArray(result, 'replicates.library.biosample.life_stage') ?
189-
result['replicates.library.biosample.life_stage'][0] : '';
190-
var ageLen = homogenousArray(result, 'replicates.library.biosample.age');
191-
var ageUnitsLen = homogenousArray(result, 'replicates.library.biosample.age_units');
192-
if (ageLen === ageUnitsLen) {
193-
age = ageLen ? ' ' + result['replicates.library.biosample.age'][0] : '';
194-
ageUnits = ageUnitsLen ? ' ' + result['replicates.library.biosample.age_units'][0] : '';
195-
}
167+
var name, lifeStage, age, ageUnits, homogenous;
168+
169+
// See if all scientific names are the same
170+
homogenous = result.replicates.every(function(replicate) {
171+
if (replicate.library && replicate.library.biosample && replicate.library.biosample.organism &&
172+
replicate.library.biosample.organism.scientific_name) {
173+
if (name) {
174+
return name === replicate.library.biosample.organism.scientific_name;
175+
} else {
176+
// First time, so just seed the name. End if the name exists but is empty
177+
name = replicate.library.biosample.organism.scientific_name;
178+
return name !== '' && name != 'unknown';
179+
}
180+
} else {
181+
// replicate doesn't have data, so we're done.
182+
return false;
183+
}
184+
});
185+
name = homogenous ? name : '';
186+
187+
// See if all life stages are the same
188+
homogenous = result.replicates.every(function(replicate) {
189+
if (replicate.library && replicate.library.biosample && replicate.library.biosample.life_stage) {
190+
if (lifeStage) {
191+
return lifeStage === replicate.library.biosample.life_stage;
192+
} else {
193+
// First time, so just seed the name. End if the name exists but is empty
194+
lifeStage = replicate.library.biosample.life_stage;
195+
return lifeStage !== '' && lifeStage != 'unknown';
196+
}
197+
} else {
198+
// replicate doesn't have data, so we're done.
199+
return false;
200+
}
201+
});
202+
lifeStage = homogenous ? lifeStage : '';
203+
204+
// See if all ages are the same
205+
homogenous = result.replicates.every(function(replicate) {
206+
if (replicate.library && replicate.library.biosample && replicate.library.biosample.age) {
207+
if (age) {
208+
return age === replicate.library.biosample.age;
209+
} else {
210+
// First time, so just seed the name. End if the name exists but is empty
211+
age = replicate.library.biosample.age;
212+
return age !== '' && age != 'unknown';
213+
}
214+
} else {
215+
// replicate doesn't have data, so we're done.
216+
return false;
217+
}
218+
});
219+
age = homogenous ? ' ' + age : '';
220+
221+
// See if all age units are the same
222+
homogenous = result.replicates.every(function(replicate) {
223+
if (replicate.library && replicate.library.biosample && replicate.library.biosample.age_units) {
224+
if (ageUnits) {
225+
return ageUnits === replicate.library.biosample.age_units;
226+
} else {
227+
// First time, so just seed the name. End if the name exists but is empty
228+
ageUnits = replicate.library.biosample.age_units;
229+
return ageUnits !== '';
230+
}
231+
} else {
232+
// replicate doesn't have data, so we're done.
233+
return false;
234+
}
235+
});
236+
ageUnits = homogenous ? ' ' + ageUnits : '';
237+
196238
var separator = (lifeStage || age) ? ', ' : '';
197239

240+
// Get the first treatment
241+
var treatment = (result.replicates[0] && result.replicates[0].library && result.replicates[0].library.biosample &&
242+
result.replicates[0].library.biosample.treatments[0]) ? result.replicates[0].library.biosample.treatments[0].treatment_term_name : '';
243+
198244
return (<li>
199245
<div>
200246
{this.renderActions()}
@@ -223,10 +269,10 @@ var Dbxref = dbxref.Dbxref;
223269
{result['target.label']}
224270
</div>
225271
: null}
226-
{result['replicates.library.biosample.treatments.treatment_term_name'] ?
272+
{treatment ?
227273
<div>
228274
<strong>{columns['replicates.library.biosample.treatments.treatment_term_name']['title'] + ': '}</strong>
229-
{result['replicates.library.biosample.treatments.treatment_term_name']}
275+
{treatment}
230276
</div>
231277
: null}
232278
<div><strong>{columns['lab.title']['title']}</strong>: {result['lab.title']}</div>

0 commit comments

Comments
 (0)