We repeat this paradigm a lot in empress.js (five times just using this._featureMetadataColumns, by my count, and I'm pretty sure most of these are my fault :P):
var fmIdx = _.indexOf(this._featureMetadataColumns, cat);
if (fmIdx < 0) {
throw 'Feature metadata column "' + cat + '" not present in data.';
}
It'd be nice to just make a convenience function for this:
// retrieves index in this._featureMetadataColumns and automatically does validation
var fmIdx = this.getFMIdx(cat);
For what it's worth, the BIOM table JS also does something similar with sample metadata. We could essentially just copy over this function and change it to reference feature instead of sample metadata. (I guess it'd be extra nice to make both these functions call another utility function that actually uses _.indexOf(), but at a certain point abstracting things like this stops being useful...)
We repeat this paradigm a lot in
empress.js
(five times just usingthis._featureMetadataColumns
, by my count, and I'm pretty sure most of these are my fault :P):It'd be nice to just make a convenience function for this:
For what it's worth, the BIOM table JS also does something similar with sample metadata. We could essentially just copy over this function and change it to reference feature instead of sample metadata. (I guess it'd be extra nice to make both these functions call another utility function that actually uses
_.indexOf()
, but at a certain point abstracting things like this stops being useful...)https://github.com/biocore/empress/blob/582c0544d5d75db2adb4328376a5b7748d1ef174/empress/support_files/js/biom-table.js#L159-L167