biocore/empress

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

オープン

#546 opened on 2021/08/12

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (32 件のフォーク)auto 404
good first issuenice to haverefactoring

Repository metrics

Stars
 (56 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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

コントリビューターガイド