-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgff3.js
46 lines (42 loc) · 1.68 KB
/
gff3.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
var $ = require('jquery');
module.exports = {
process: function(gff3_data, types, longest) {
var features = [];
gff3_data.split('\n').map(function(line) {
if (!line.startsWith('#') && line.length != 0) {
var parts = line.split('\t');
if (parts.length !== 9) {
//the file might use spaces instead of tabs
//ill try to split it by spaces
parts = line.trim().split(/\s+/);
}
if (parts.length == 9) {
var attParts = parts[8].split(';');
var arrayObject = {};
for (var i = 0; i < attParts.length; ++i) {
var pair = attParts[i].split("=");
arrayObject[pair[0]] = pair[1];
}
var feature = {
seqid: parts[0],
source: parts[1],
type: parts[2],
start: parseInt(parts[3]),
end: parseInt(parts[4]),
score: parts[5],
strand: parts[6],
phase: parts[7],
attributes: arrayObject
};
// check if user specified feature type
if (types === undefined || types.indexOf(feature.type) > -1) {
features.push(feature);
}
} else { var err = new Error('9 parts of feature not found');
console.log(err);
}
}
});
return features;
},
};