-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
111 lines (99 loc) · 3.04 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<style>
body {
background-color: #eee;
white-space: pre;
font-family: monospace;
}
.dropzone {
width: 300px;
height: 300px;
margin: 0 auto;
display: block;
border: 2px solid black;
border-radius: 5px;
background-color: lightYellow;
padding: 1em;
font-family: sans-serif;
text-align: center;
white-space: normal;
}
</style>
</head>
<body>
<div class="dropzone">Drag 'n' Drop file here to convert GFF3 to GTF2</div>
<script>
// Treat LHS as a nonterminal that maps deterministically to all RHS
var mappings = {
"Parent": [ "gene_id", "transcript_id" ]
};
$(document).on('drop', '.dropzone', function (e) {
// stop the browser from loading the file in the window
e.stopPropagation();
e.preventDefault();
var $dropzone = $(this);
$dropzone.text("thinking...");
var reader = new FileReader();
reader.readAsText(e.originalEvent.dataTransfer.files[0]);
reader.onload = function () {
var rows = reader.result
// split into rows along newline characters
.split('\n')
.map(function (row) {
// skip comments
if (row[0] === '#') return row;
// split into columns along tab characters
row = row.split('\t');
// the key-value pair properties are the last column
var props = row[8] || "";
row = row.slice(0, 8);
props = props
// KVPs colon delimited
.split(';')
.reduce(function (memo, curr) {
// evil nonprintables!!
if (!(curr || "").trim()) return memo;
// K/V are equals-delineated
var x = curr.split('=');
// finish conversion of KVP string into an objcet
memo[x[0]] = x[1].trim();
return memo;
}, {});
props = Object.getOwnPropertyNames(props)
.reduce(function (memo, prop) {
// create an object of the properties with their new Key names
(mappings[prop] || [])
.forEach(function (newProp) {
memo[newProp] = props[prop];
});
return memo;
}, {});
row.push(Object.getOwnPropertyNames(props)
.map(function (prop) {
// write back to a KVP string in the GTF2 format
return prop + " \"" + props[prop] + "\"";
})
.join('; '));
// re-assemble the columns
row = row.join('\t');
return row;
});
// re-assemble the rows
rows = rows.join('\n');
var blob = new Blob([rows], { type: 'text/plain' });
var $a = $("<a href=''>Right-click to download</a>");
$a.attr('href', window.URL.createObjectURL(blob));
$dropzone.empty().append($a);
}
});
$(document).on('dragover', '.dropzone', function (e) {
e.stopPropagation();
e.preventDefault();
e.originalEvent.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
});
</script>
</body>
</html>