Skip to content

Instantly share code, notes, and snippets.

@ben-heil
Created November 29, 2022 21:30
Show Gist options
  • Save ben-heil/fc5c3b8738c5674e4986229bacdb1910 to your computer and use it in GitHub Desktop.
Save ben-heil/fc5c3b8738c5674e4986229bacdb1910 to your computer and use it in GitHub Desktop.
export const mapActivities = (activities, state) => {
if (
!isArray(activities) ||
!activities.length ||
!isArray(state.experiments.list) ||
!state.experiments.list.length
)
return { bySignature: {}, byExperiment: [] };
// get all activities in signature, and min/max
const values = activities.map((activity) => activity.value);
const min = arrayMin(values); // Math.min(...values);
const max = arrayMax(values); // Math.max(...values);
const bySignature = { values, min, max };
// bring sample info out of activities and into map
const activityMap = {};
const scoreMap = {};
for (const { sample, value } of activities) activityMap[sample] = value;
for (const { sample, score } of activities) scoreMap[sample] = score;
// get activities by experiment
const byExperiment = state.experiments.list
.map((experiment) => {
// get experiment samples info
const samples = experiment.samples;
// get activity value of each sample
const values = samples
.map((sample) => activityMap[sample])
.filter((value) => value);
const score = samples
.map((sample) => scoreMap[sample])
.filter( <IDK HOW TO GET THE FIRST THING IN A LIST IN JAVASCRIPT BUT I WOULD DO IT HERE>)
// return all needed info
return {
id: experiment.id,
accession: experiment.accession,
values,
count: values.length,
score,
samples
};
})
.filter((experiment) => experiment.count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment