-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoxog_varbam_annotate_util.js
163 lines (155 loc) · 4.2 KB
/
oxog_varbam_annotate_util.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
function filterFileArray(str, inArr) {
var arr = [];
for (var i = 0; i < inArr.length; i++) {
if (inArr[i].basename.indexOf(str) >= 0) {
// Return the first match.
return inArr[i]
}
}
return arr;
}
function appendBam(str) {
return str.concat(".bam")
}
function appendBai(str) {
return str.concat(".bai")
}
function flatten_nested_arrays(array_of_arrays)
{
var flattened_array = []
for (var i in array_of_arrays)
{
var item = array_of_arrays[i]
if (item instanceof Array)
{
// console.log("found subarray")
// recursively flatten subarrays.
var flattened_sub_array = flatten_nested_arrays(item)
for (var k in flattened_sub_array)
{
flattened_array.push(flattened_sub_array[k])
}
}
else
{
flattened_array.push(item)
}
}
return flattened_array
}
function createArrayOfFilesForOxoG(in_data, vcfsForOxoG) {
//TODO: Move this function to separate JS file.
var vcfsToUse = []
// Need to search through vcfsForOxoG (cleaned VCFs that have been zipped and index) and preprocess_vcfs/extractedSNVs to find VCFs
// that match the names of those in in_data.inputs.associatedVCFs
//
var associatedVcfs = in_data.associatedVcfs
for ( var i in associatedVcfs )
{
if ( associatedVcfs[i].indexOf(".snv") !== -1 )
{
for ( var j in vcfsForOxoG )
{
if ( vcfsForOxoG[j].basename.indexOf( associatedVcfs[i].replace(".vcf.gz","") ) !== -1 && /.*\.gz$/.test(vcfsForOxoG[j].basename))
{
vcfsToUse.push ( vcfsForOxoG[j] )
}
}
}
if ( associatedVcfs[i].indexOf(".indel") !== -1 )
{
for ( var j in vcfsForOxoG )
{
if ( vcfsForOxoG[j].basename.replace(".pass-filtered.cleaned.vcf.normalized.extracted-SNVs.vcf.gz","").indexOf( associatedVcfs[i].replace(".vcf.gz","") ) !== -1 && /.*\.gz$/.test(vcfsForOxoG[j].basename))
{
vcfsToUse.push ( vcfsForOxoG[j] )
}
}
}
//vcfsToUse.concat(extractedSnvs)
}
return vcfsToUse
}
function chooseINDELsForAnnotator(oxogVCFs, tumours_list)
{
var vcfsToUse = [];
var flattened_oxogs = flatten_nested_arrays(oxogVCFs);
var associated_indels = tumours_list.associatedVcfs.filter( function(item)
{
return item.indexOf("indel") !== -1;
});
for (var i in associated_indels)
{
for (var j in flattened_oxogs)
{
//if ( flattened_oxogs[j].basename.indexOf(associated_indels[i].replace(".vcf.gz","")) !== -1 )
{
vcfsToUse.push(flattened_oxogs[j]);
}
}
}
return vcfsToUse;
}
function chooseVCFsForAnnotator(VCFs, associatedVcfs)
{
var vcfsToUse = [];
//this might be a nested array if it came from the OxoG output.
var flattened_array = flatten_nested_arrays(VCFs);
// var associated_vcfs = tumours_list.associatedVcfs.filter( function(item)
// {
// return item.indexOf("indel") !== -1;
// });
var associated_vcfs = associatedVcfs
for (var i in associated_vcfs)
{
for (var j in flattened_array)
{
if ( flattened_array[j].basename.indexOf(associated_vcfs[i].replace(".vcf.gz","")) !== -1 )
{
//console.log("OK "+flattened_array[j].basename + " was in "+associated_vcfs[i] +" so it will be annotated!")
vcfsToUse.push( flattened_array[j] );
}
else
{
//console.log("Not OK "+ flattened_array[j].basename + " was NOT in "+associated_vcfs[i] +" so it will NOT be annotated!")
}
}
}
return vcfsToUse;
}
function chooseMiniBamForAnnotator(tumourMinibams, tumours_record)
{
// var minibamToUse
for (var j in tumourMinibams )
{
// The minibam should be named the same as the regular bam, except for the "mini-" prefix.
// This condition should only ever be satisfied once.
if (tumourMinibams[j].basename.indexOf( tumours_record.bamFileName ) !== -1 )
{
return tumourMinibams[j]
}
}
//return minibamToUse
return undefined
}
function chooseSNVsForAnnotator(oxogVCFs, tumours_list)
{
var vcfsToUse = []
var flattened_oxogs = flatten_nested_arrays(oxogVCFs)
var associated_snvs = tumours_list.associatedVcfs.filter( function(item)
{
return item.indexOf("snv") !== -1
}
)
for (var i in associated_snvs)
{
for (var j in flattened_oxogs)
{
//if ( flattened_oxogs[j].basename.indexOf(associated_snvs[i].replace(".vcf.gz","")) !== -1 )
{
vcfsToUse.push(flattened_oxogs[j])
}
}
}
return vcfsToUse
}