-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8abc73e
commit 712585d
Showing
6 changed files
with
96 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,95 @@ | ||
define([], function() { | ||
/** | ||
* biom-table | ||
*/ | ||
function BiomTable(obs, samp) { | ||
/** | ||
* The observation table format: | ||
* {sampleID1: [observationIDs], | ||
sampleID2: [observationIDs], | ||
...} | ||
* @private | ||
* biom-table | ||
*/ | ||
this._obs = obs; | ||
function BiomTable(obs, samp) { | ||
/** | ||
* The observation table format: | ||
* {sampleID1: [observationIDs], | ||
sampleID2: [observationIDs], | ||
...} | ||
* @private | ||
*/ | ||
this._obs = obs; | ||
|
||
/** | ||
* @type {Dictionary} | ||
* Sample metedata format: | ||
* {sampleID1: {cat1: val, cat2: val, ...}, | ||
sampleID2: {cat1: val, cat2: val, ...}, | ||
...} | ||
* @private | ||
*/ | ||
this._samp = samp; | ||
}; | ||
|
||
/** | ||
* @type {Dictionary} | ||
* Sample metedata format: | ||
* {sampleID1: {cat1: val, cat2: val, ...}, | ||
sampleID2: {cat1: val, cat2: val, ...}, | ||
...} | ||
* @private | ||
* Returns the list of observations in the sample | ||
* | ||
* @param {String} The sample Id | ||
* | ||
* @return {Array} | ||
*/ | ||
this._samp = samp; | ||
}; | ||
BiomTable.prototype.getSampleObs = function(sId) { | ||
var result = new Set(); | ||
return this._obs[sId]; | ||
}; | ||
|
||
/** | ||
* Returns a dictionary of observation ids whose keys are the values of a sample | ||
* category. | ||
* | ||
* @param {String} The category to return observation | ||
* | ||
* @return {Dictionary} | ||
*/ | ||
BiomTable.prototype.getObsBy = function(cat) { | ||
var result = {}; | ||
var cVal; | ||
for (var sample in this._samp) { | ||
cVal = this._samp[sample][cat]; | ||
if (!(cVal in result)) { | ||
result[cVal] = new Set(); | ||
} | ||
for (var i = 0; i < this._obs[sample].length; i++) { | ||
result[cVal].add(this._obs[sample][i]); | ||
/** | ||
* Returns a dictionary of observation ids whose keys are the values of a sample | ||
* category. | ||
* | ||
* @param {String} The category to return observation | ||
* | ||
* @return {Dictionary} | ||
*/ | ||
BiomTable.prototype.getObsBy = function(cat) { | ||
var result = {}; | ||
var cVal; | ||
for (var sample in this._samp) { | ||
cVal = this._samp[sample][cat]; | ||
if (!(cVal in result)) { | ||
result[cVal] = new Set(); | ||
} | ||
for (var i = 0; i < this._obs[sample].length; i++) { | ||
result[cVal].add(this._obs[sample][i]); | ||
} | ||
} | ||
} | ||
|
||
for (var key in result) { | ||
result[key] = Array.from(result[key]); | ||
} | ||
for (var key in result) { | ||
result[key] = Array.from(result[key]); | ||
} | ||
|
||
return result; | ||
}; | ||
return result; | ||
}; | ||
|
||
/** | ||
* Returns number of unique observations in samples. | ||
* | ||
* @return {Number} | ||
*/ | ||
BiomTable.prototype.getUniqueObs = function() { | ||
var obs = new Set(); | ||
/** | ||
* Returns number of unique observations in samples. | ||
* | ||
* @return {Number} | ||
*/ | ||
BiomTable.prototype.getUniqueObs = function() { | ||
var obs = new Set(); | ||
|
||
for (var sample in this._samp) { | ||
for (var i = 0; i < this._obs[sample].length; i++) { | ||
obs.add(this._obs[sample][i]); | ||
for (var sample in this._samp) { | ||
for (var i = 0; i < this._obs[sample].length; i++) { | ||
obs.add(this._obs[sample][i]); | ||
} | ||
} | ||
} | ||
|
||
return obs.size; | ||
}; | ||
return obs.size; | ||
}; | ||
|
||
|
||
|
||
/** | ||
* Returns a list of sample categories | ||
* | ||
* @return{Array} | ||
*/ | ||
BiomTable.prototype.getSampleCats = function() { | ||
return Object.keys((Object.values(this._samp)[0])).sort(); | ||
}; | ||
/** | ||
* Returns a list of sample categories | ||
* | ||
* @return{Array} | ||
*/ | ||
BiomTable.prototype.getSampleCats = function() { | ||
return Object.keys((Object.values(this._samp)[0])).sort(); | ||
}; | ||
|
||
return BiomTable; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters