Skip to content

Commit

Permalink
Merge pull request #150 from Duke-GCB/138-file-picker-handle-single-f…
Browse files Browse the repository at this point in the history
…ile-array

Simple support for workflows using FASTQReadPairType[]
  • Loading branch information
dleehr authored Apr 17, 2019
2 parents b3d457d + 58cb375 commit 959f0f0
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/components/questionnaire/fastq-file-pair-list.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Ember from 'ember';
import FileGroupList from 'bespin-ui/components/questionnaire/file-group-list';
import { FASTQFileItemList } from 'bespin-ui/utils/fastq-file-item-list';
import layout from 'bespin-ui/templates/components/questionnaire/fastq-file-pair-list';

const FASTQFilePairList = FileGroupList.extend({
layout, // https://github.com/emberjs/rfcs/issues/412#issuecomment-423499140
groupSize: 2,
answerFormErrors: null,
fieldErrors: Ember.computed('answerFormErrors.errors.[]', 'fieldName', function() {
Expand Down
26 changes: 26 additions & 0 deletions app/components/questionnaire/fastq-read-pair-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Ember from 'ember';
import FASTQFilePairList from './fastq-file-pair-list';

export default FASTQFilePairList.extend({
// Primary purpose of this subclass is to provide a different structure from the 'answer'
// method that returns single files wrapped in an array.
answer: Ember.computed('fieldName', 'fileItems.cwlObjectValue.[]', function() {
const fieldName = this.get('fieldName');
// Convert NamedFASTQFilePairType to a FASTQReadPairType
const fastqReadPairs = this.get('fileItems.cwlObjectValue').map(namedPair => {
return Ember.Object.create({
name: namedPair.get('name'),
read1_files: [namedPair.get('file1')],
read2_files: [namedPair.get('file2')]
});
});

const answer = Ember.Object.create();
answer.set(fieldName, fastqReadPairs);
return answer;
}),
// Support Message
featureSupportMessage: Ember.String.htmlSafe('<strong>Note:</strong> This workflow supports multiple file pairs per read. ' +
'However, the web interface only supports choosing one file pair per read. If you wish to run this workflow with multiple files per ' +
'read, please use <a href="https://github.com/Duke-GCB/bespin-cli">bespin-cli</a>.'),
});
3 changes: 3 additions & 0 deletions app/components/questionnaire/file-group-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const FileGroupList = DDSProjectField.extend({
}
},

// Message to display if additional functionality is available elsewhere (e.g. CLI)
featureSupportMessage: null,

init() {
this._super(...arguments);
if(Ember.isEmpty(this.get('fileItems'))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
</div>
<div class="col-md-6 file-group-list-selections">
<label>Selected {{ groupTitle }} {{ groupSizeName }}</label>
{{#if featureSupportMessage}}
<div class="feature-support-message alert alert-warning">
{{featureSupportMessage}}
</div>
{{/if}}
{{#each samples as |pair pairIndex|}}
{{questionnaire/fastq-file-pair-row pair pairIndex (action 'removeAt')}}
{{else}}
Expand Down
14 changes: 14 additions & 0 deletions app/utils/component-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ const ComponentSettings = [
}
]
},
{
// Bespin CWL FASTQReadPairType - pair of arrays
// We support a basic version of this, providing a single file in each array
cwlType: { type: 'array', items: 'FASTQReadPairType'}, // Named in job-questionnaire.user_fields_json
name: 'fastq-read-pair-list', // questionnaire component to render
formats: [
{
title: 'FASTQ Pair',
format: null, // The specific files should be http://edamontology.org/format_1930, but this is a structure
fileNameRegexStr: '.*(fq$)|(fq.gz$)|(fastq$)|(fastq.gz$)',
groupName: 'Sample'
}
]
},
{
// String field
cwlType: 'string', // Named in job-questionnaire.user_fields_json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ test('it correctly observes error array', function(assert) {
assert.equal(this.$('.error-panel').text().trim(), 'Incomplete');
});
});

test('it shows no featureSupportMessage', function(assert) {
const fileItems = Ember.Object.create({
samples: [{},{}]
}
);
this.set('fileItems', fileItems);
this.set('externalAction', () => {});
this.render(hbs`{{questionnaire/fastq-file-pair-list "FieldName" (action externalAction) fileItems=fileItems}}`);
assert.equal(this.$('.feature-support-message').length, 0);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import StoreStub from '../../../helpers/store-stub';
import Ember from 'ember';

moduleForComponent('questionnaire/fastq-read-pair-list', 'Integration | Component | questionnaire/fastq read pair list', {
integration: true,
beforeEach: function() {
this.register('service:store', StoreStub);
}
});

test('it renders using the fastq-file-pair-list template', function(assert) {
const fileItems = Ember.Object.create({
samples: [{},{}]
}
);
this.set('fileItems', fileItems);
this.set('externalAction', () => {});
this.render(hbs`{{questionnaire/fastq-read-pair-list "FieldName" (action externalAction) fileItems=fileItems}}`);
assert.equal(this.$('.fastq-file-pair-row').length, 2);
assert.equal(this.$('div.file-group-list-picker').length, 1);

});

test('It shows the featureSupportMessage', function(assert) {
const fileItems = Ember.Object.create({
samples: [{},{}]
}
);
this.set('fileItems', fileItems);
this.set('externalAction', () => {});
this.render(hbs`{{questionnaire/fastq-read-pair-list "FieldName" (action externalAction) fileItems=fileItems}}`);
assert.equal(this.$('.feature-support-message').length, 1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,9 @@ test('it requires fieldName and answerChanged', function(assert) {
});
this.subject({fieldName: "SomeField", answerChanged: ()=>{}});
});

test('it has no featureSupportMessage', function(assert) {
const fastqFilePairList = this.subject({fieldName: "SomeField", answerChanged: ()=>{}});
const message = fastqFilePairList.get('featureSupportMessage');
assert.notOk(message);
});
35 changes: 35 additions & 0 deletions tests/unit/components/questionnaire/fastq-read-pair-list-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { moduleForComponent, test } from 'ember-qunit';
import Ember from 'ember';

moduleForComponent('questionnaire/fastq-read-pair-list', 'Unit | Component | questionnaire/fastq read pair list', {
// Specify the other units that are required for this test
needs: ['service:dds-projects', 'service:dds-user-credentials'],
unit: true
});

test('it computes answer with field name and files', function (assert) {

const expected = Ember.Object.create({read_pairs: [{name: 'abc', read1_files: [{class: 'File', path: 'abc_1'}], read2_files: [{class: 'File', path: 'abc_2'}]}]});
const fieldName = 'read_pairs';
const mockFileItems = Ember.Object.create({
cwlObjectValue: [
Ember.Object.create({name: 'abc', file1: {class: 'File', path: 'abc_1'}, file2: {class: 'File', path: 'abc_2'}})
]
});

const fastqReadPairList = this.subject({
groupSize: 2,
fileItems: mockFileItems,
fieldName: fieldName,
answerChanged: () => {
}
});
const answer = fastqReadPairList.get('answer');
assert.equal(JSON.stringify(answer), JSON.stringify(expected));
});

test('it provides feature support message with link to bespin-cli', function(assert) {
const fastqReadPairList = this.subject({fieldName: "SomeField", answerChanged: ()=>{}});
const messageString = fastqReadPairList.get('featureSupportMessage.string');
assert.ok(messageString.indexOf('https://github.com/Duke-GCB/bespin-cli') > 0);
});

0 comments on commit 959f0f0

Please sign in to comment.