-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata.js
57 lines (48 loc) · 1.61 KB
/
metadata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* metadata.js
*/
const fs = require('node:fs');
const path = require('node:path');
const clone = require('lodash.clonedeep');
const config = require('../config');
const envConfig = require('../envConfig');
const metadata = JSON.parse(fs.readFileSync(envConfig.TRACK_METADATA_PATH).toString());
module.exports = {
getTracks,
};
/**
* @param {Object.<string, Object>} samples
* @param {Object} peak
*/
function getTracks(samples, peak) {
// Variant sample IDs may not match exactly to donor names. This configured function + map/filter extracts the donor
// name from the VCF sample ID.
const samplesByRealName =
Object.fromEntries(
Object.entries(samples)
.map(([key, value]) => [config.samples?.vcfSampleNameConverter(key) ?? undefined, value])
.filter((e) => e[0] !== undefined));
const sampleNames = Object.keys(samplesByRealName)
const assay = peak.assay.toLowerCase()
const tracks =
metadata
.filter(track => {
// TODO test filtering here
if (assay !== track.assay.toLowerCase()) return false;
if (!sampleNames.includes(track.donor)) return false;
// noinspection RedundantIfStatementJS
if (peak.assay === 'RNA-Seq' &&
peak.feature.strand === '+' && track.view !== 'signal_forward') return false;
return true;
})
.map(clone);
tracks.forEach(track => {
track.path = getLocalPath(track);
const sample = samplesByRealName[track.donor];
Object.assign(track, sample);
});
return Promise.resolve(tracks);
}
function getLocalPath(track) {
return path.join(envConfig.TRACKS_DIR, track.path);
}