-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
190 lines (180 loc) · 6.14 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDB to FASTA Converter</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.44.0/min/vs/loader.js"></script>
<style>
body {
font-family: system-ui, -apple-system, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-top: 20px;
}
.editor-container {
background: white;
border-radius: 8px;
padding: 16px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1 {
color: #2d3748;
margin-bottom: 8px;
}
.description {
color: #4a5568;
margin-bottom: 24px;
}
#pdbInput, #fastaOutput {
width: 100%;
height: 400px;
border: 1px solid #e2e8f0;
border-radius: 4px;
}
.button-container {
margin-top: 16px;
display: flex;
gap: 8px;
}
button {
background-color: #4299e1;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.2s;
}
button:hover {
background-color: #3182ce;
}
.upload-btn {
background-color: #48bb78;
}
.upload-btn:hover {
background-color: #38a169;
}
.clear-btn {
background-color: #e53e3e;
}
.clear-btn:hover {
background-color: #c53030;
}
</style>
</head>
<body>
<h1>PDB to FASTA Converter</h1>
<p class="description">
Convert PDB (Protein Data Bank) files to FASTA format.
Paste your PDB content or upload a file to get started.
</p>
<div class="container">
<div class="editor-container">
<h2>Input (PDB)</h2>
<div id="pdbInput"></div>
<div class="button-container">
<input type="file" id="fileInput" style="display: none" accept=".pdb">
<button class="upload-btn" onclick="document.getElementById('fileInput').click()">
Upload PDB File
</button>
<button onclick="convertToFasta()">Convert</button>
<button class="clear-btn" onclick="clearInput()">Clear</button>
</div>
</div>
<div class="editor-container">
<h2>Output (FASTA)</h2>
<div id="fastaOutput"></div>
<div class="button-container">
<button onclick="copyToClipboard()">Copy to Clipboard</button>
<button onclick="downloadFasta()">Download FASTA</button>
</div>
</div>
</div>
<script type="module">
import init, { pdb_to_fasta_js } from './pdb2fasta_wasm_rust.js';
window.pdbEditor = null;
window.fastaEditor = null;
require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.44.0/min/vs' } });
require(['vs/editor/editor.main'], function() {
window.pdbEditor = monaco.editor.create(document.getElementById('pdbInput'), {
value: '',
language: 'plaintext',
theme: 'vs-light',
minimap: { enabled: false },
lineNumbers: 'on',
renderWhitespace: 'all',
scrollBeyondLastLine: false,
});
window.fastaEditor = monaco.editor.create(document.getElementById('fastaOutput'), {
value: '',
language: 'plaintext',
theme: 'vs-light',
minimap: { enabled: false },
lineNumbers: 'on',
readOnly: true,
scrollBeyondLastLine: false,
});
window.addEventListener('resize', function() {
if (window.pdbEditor) {
window.pdbEditor.layout();
}
if (window.fastaEditor) {
window.fastaEditor.layout();
}
});
});
// Initialize WebAssembly module
await init();
// Make conversion function available globally
window.convertToFasta = function() {
try {
const pdbContent = window.pdbEditor.getValue();
const fastaContent = pdb_to_fasta_js(pdbContent);
window.fastaEditor.setValue(fastaContent);
} catch (error) {
alert('Error converting PDB to FASTA: ' + error.message);
}
};
window.clearInput = function() {
window.pdbEditor.setValue('');
window.fastaEditor.setValue('');
};
window.copyToClipboard = function() {
const content = window.fastaEditor.getValue();
navigator.clipboard.writeText(content)
.then(() => alert('Copied to clipboard!'))
.catch(err => alert('Failed to copy: ' + err));
};
window.downloadFasta = function() {
const content = window.fastaEditor.getValue();
const blob = new Blob([content], { type: 'text/plain' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'converted.fasta';
a.click();
window.URL.revokeObjectURL(url);
};
// File upload handler
document.getElementById('fileInput').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
window.pdbEditor.setValue(e.target.result);
};
reader.readAsText(file);
}
});
</script>
</body>
</html>