-
Notifications
You must be signed in to change notification settings - Fork 4
/
msa.js
66 lines (58 loc) · 1.7 KB
/
msa.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
var msa = require("msa");
var ncbi = require('bionode-ncbi');
var es = require('event-stream');
var filter = require('through2-filter');
var concat = require('concat-stream');
var tool = require('tool-stream');
var $ = require('jquery');
var msaDiv = document.createElement('div');
document.body.appendChild(msaDiv);
var concatStream = concat(function(sequences) {
sequences = sequences.map(function(seq) {
var props = seq.id.split('|');
seq.id = props[1];
seq.name = props[4];
return seq;
});
createMSAViz(sequences);
});
function createMSAViz(seqs) {
var m = new msa({
el: msaDiv,
seqs: seqs
});
var menu = new msa.menu.defaultmenu({
msa: m
});
m.addView('menu', menu);
m.render();
}
var species = [];
function runPipe() {
ncbi.search('protein', 'mbp1')
.pipe(filter.obj(function (obj) {
return obj.title.match(/^mbp1p?.*\[.*\]$/i);
}))
.pipe(filter.obj(function (obj) {
var specieName = obj.title.substring(obj.title.indexOf('[') + 1, obj.title.length-1);
specieName = specieName.split(' ').slice(0,1).join(' ');
if (species.indexOf(specieName) >= 0) {
return false;
} else {
species.push(specieName);
return true;
}
}))
.pipe(tool.extractProperty('gi'))
.pipe(ncbi.fetch('protein'))
.pipe(concatStream);
}
function runFetch() {
$.get('http://localhost:3000/aligned?q=' + $('#query').val()).then(function(data) {
createMSAViz(data.seqs);
});
}
$('#submit').on('click', function() {
msaDiv.innerHTML = 'Loading...';
runFetch();
});