empress icon indicating copy to clipboard operation
empress copied to clipboard

Add convenience method to empress.js that gets the 0-based index of a feature metadata column

Open fedarko opened this issue 2 years ago • 0 comments

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...)

https://github.com/biocore/empress/blob/582c0544d5d75db2adb4328376a5b7748d1ef174/empress/support_files/js/biom-table.js#L159-L167

fedarko avatar Aug 12 '21 19:08 fedarko