Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fedarko opened this issue Aug 12, 2021 · 0 comments
Labels
good first issue nice to have refactoring Use best practices or improve the usage of public APIs

Comments

@fedarko
Copy link
Collaborator

fedarko commented Aug 12, 2021

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

BIOMTable.prototype._getSampleMetadataColIndex = function (col) {
var colIdx = _.indexOf(this._smCols, col);
if (colIdx < 0) {
throw new Error(
'Sample metadata column "' + col + '" not in BIOM table.'
);
}
return colIdx;
};

@fedarko fedarko added nice to have good first issue refactoring Use best practices or improve the usage of public APIs labels Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue nice to have refactoring Use best practices or improve the usage of public APIs
Projects
None yet
Development

No branches or pull requests

1 participant