-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_cancer.js
113 lines (98 loc) · 3.37 KB
/
script_cancer.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// @ts-check
export default {
description: 'Import variants tagged SM/GL and add TMB/MSI',
icon: 'import',
fileFilter: undefined,
async run({
selected, inputs, api: { table, project, cancer, core }, args,
}) {
try {
// args as string[] input list, extended by vspipeline run command context
const [evalId] = args;
const evaluationId = parseInt(evalId);
const sample = await project.currentSampleState();
await addTMB(sample, cancer, evaluationId);
await addMSI(sample, cancer, evaluationId);
console.log("Adding variants tagged SM and GL...");
const variantSomaticIds = await cancer.addProjectVariants({
origin: "SOMATIC",
recordSetInitials: "SM",
maxRecordCount: 500,
evaluationId: evaluationId
});
const variantGermlineIds = await cancer.addProjectVariants({
origin: "GERMLINE_CONFIRMED",
recordSetInitials: "GL",
maxRecordCount: 500,
evaluationId: evaluationId
});
console.log(`Added ${variantSomaticIds.length} somatic and ${variantGermlineIds.length} germline variants.`);
// const cnvBiomarkerIds = await cancer.addProjectCnvs({
// recordSetInitials: "PF",
// maxRecordCount: 500,
// evaluationId: evaluationId
// });
// console.log(`Added ${cnvBiomarkerIds.length} CNVs.`);
} catch (error) {
console.log(error);
throw error;
}
}
};
async function addTMB(sample, cancer, evaluationId) {
try {
const [tmbScoreField = {}] = sample.extraField.filter(f => f.fieldName == "TMB");
let { fieldValue: tmbScore } = tmbScoreField;
if (tmbScore === undefined) {
console.log(`Failed to parse TMB: couldn't find values for ${tmbScore}`);
return;
}
let status = 'Low';
if (parseFloat(tmbScore) >= 20.0) {
status = 'High';
}
const units = 'mut/Mb'
console.log(`Adding TMB with status ${status} for value ${tmbScore}`);
await cancer.addSignature({
signature: 'TMB',
status,
quantitativeValue: tmbScore,
units,
evaluationId
});
} catch (error) {
console.error(`Failed to parse TMB: ${error.toString()}`);
}
}
async function addMSI(sample, cancer, evaluationId) {
try {
const [msiScoreField = {}] = sample.extraField.filter(f => f.fieldName == "MSI");
let { fieldValue: msiScore } = msiScoreField;
if (msiScore === undefined) {
console.log(`Failed to parse MSI: couldn't find values for ${msiScore}`);
return;
}
let status = 'Stable';
const msiScoreFloat = parseFloat(msiScore);
if (msiScoreFloat <= 6.5) {
status = 'Stable';
}
else if (msiScoreFloat >= 8.5) {
status = 'High';
}
else {
status = 'Indeterminate';
}
const units = 'sites'
console.log(`Adding MSI with status ${status} for value ${msiScore}`);
await cancer.addSignature({
signature: 'MSI',
status,
quantitativeValue: msiScore + '%',
units,
evaluationId
});
} catch (error) {
console.error(`Failed to parse TMB: ${error.toString()}`);
}
}