bgc-viewer 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bgc_viewer/__init__.py +11 -0
- bgc_viewer/app.py +490 -0
- bgc_viewer/templates/index.html +86 -0
- bgc_viewer/tests/test_app.py +83 -0
- bgc_viewer-0.1.0.dist-info/METADATA +182 -0
- bgc_viewer-0.1.0.dist-info/RECORD +9 -0
- bgc_viewer-0.1.0.dist-info/WHEEL +4 -0
- bgc_viewer-0.1.0.dist-info/entry_points.txt +2 -0
- bgc_viewer-0.1.0.dist-info/licenses/LICENSE +201 -0
bgc_viewer/__init__.py
ADDED
bgc_viewer/app.py
ADDED
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
from flask import Flask, render_template, jsonify, request
|
|
2
|
+
from flask_cors import CORS
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from waitress import serve
|
|
8
|
+
from dotenv import load_dotenv
|
|
9
|
+
|
|
10
|
+
# Load environment variables from .env file
|
|
11
|
+
load_dotenv()
|
|
12
|
+
|
|
13
|
+
app = Flask(__name__)
|
|
14
|
+
CORS(app)
|
|
15
|
+
|
|
16
|
+
# Global variable to store currently loaded data
|
|
17
|
+
ANTISMASH_DATA = None
|
|
18
|
+
CURRENT_FILE = None
|
|
19
|
+
|
|
20
|
+
def get_available_files():
|
|
21
|
+
"""Get list of available JSON files in the data directory."""
|
|
22
|
+
data_dir = Path("data")
|
|
23
|
+
if not data_dir.exists():
|
|
24
|
+
return []
|
|
25
|
+
|
|
26
|
+
json_files = []
|
|
27
|
+
for file_path in data_dir.glob("*.json"):
|
|
28
|
+
json_files.append(file_path.name)
|
|
29
|
+
|
|
30
|
+
return sorted(json_files)
|
|
31
|
+
|
|
32
|
+
def load_antismash_data(filename=None):
|
|
33
|
+
"""Load AntiSMASH JSON data from file."""
|
|
34
|
+
if filename is None:
|
|
35
|
+
# Default to Y16952.json if no file specified
|
|
36
|
+
filename = "Y16952.json"
|
|
37
|
+
|
|
38
|
+
data_file = Path("data") / filename
|
|
39
|
+
if data_file.exists():
|
|
40
|
+
with open(data_file, 'r') as f:
|
|
41
|
+
return json.load(f)
|
|
42
|
+
return None
|
|
43
|
+
|
|
44
|
+
def set_current_file(filename):
|
|
45
|
+
"""Set the current file and load its data."""
|
|
46
|
+
global ANTISMASH_DATA, CURRENT_FILE
|
|
47
|
+
data = load_antismash_data(filename)
|
|
48
|
+
if data is not None:
|
|
49
|
+
ANTISMASH_DATA = data
|
|
50
|
+
CURRENT_FILE = filename
|
|
51
|
+
return True
|
|
52
|
+
return False
|
|
53
|
+
|
|
54
|
+
# Load the default data at startup
|
|
55
|
+
# Try to load a default file if it exists, but don't fail if it doesn't
|
|
56
|
+
try:
|
|
57
|
+
if not set_current_file("Y16952.json"):
|
|
58
|
+
# Try to load any available JSON file from data directory
|
|
59
|
+
available_files = get_available_files()
|
|
60
|
+
if available_files:
|
|
61
|
+
set_current_file(available_files[0])
|
|
62
|
+
else:
|
|
63
|
+
print("No JSON files found in data directory. Application will start without loaded data.")
|
|
64
|
+
except Exception as e:
|
|
65
|
+
print(f"Warning: Could not load default data on startup: {e}")
|
|
66
|
+
ANTISMASH_DATA = None
|
|
67
|
+
CURRENT_FILE = None
|
|
68
|
+
|
|
69
|
+
@app.route('/')
|
|
70
|
+
def index():
|
|
71
|
+
"""Serve the SPA."""
|
|
72
|
+
return app.send_static_file('dist/index.html')
|
|
73
|
+
|
|
74
|
+
@app.route('/<path:path>')
|
|
75
|
+
def spa_fallback(path):
|
|
76
|
+
"""Fallback for SPA routing - serve index.html for all non-API routes."""
|
|
77
|
+
if path.startswith('api/'):
|
|
78
|
+
# Let API routes be handled by their specific handlers
|
|
79
|
+
return jsonify({"error": "Not found"}), 404
|
|
80
|
+
return app.send_static_file('dist/index.html')
|
|
81
|
+
|
|
82
|
+
@app.route('/api/status')
|
|
83
|
+
def get_status():
|
|
84
|
+
"""API endpoint to get current file and data loading status."""
|
|
85
|
+
return jsonify({
|
|
86
|
+
"current_file": CURRENT_FILE if CURRENT_FILE else None,
|
|
87
|
+
"has_loaded_data": ANTISMASH_DATA is not None,
|
|
88
|
+
"data_directory_exists": Path("data").exists()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
@app.route('/api/browse')
|
|
92
|
+
def browse_filesystem():
|
|
93
|
+
"""API endpoint to browse the server's filesystem."""
|
|
94
|
+
path = request.args.get('path', '.')
|
|
95
|
+
|
|
96
|
+
try:
|
|
97
|
+
# Resolve the path
|
|
98
|
+
resolved_path = Path(path).resolve()
|
|
99
|
+
|
|
100
|
+
if not resolved_path.exists():
|
|
101
|
+
return jsonify({"error": "Path does not exist"}), 404
|
|
102
|
+
|
|
103
|
+
if not resolved_path.is_dir():
|
|
104
|
+
return jsonify({"error": "Path is not a directory"}), 400
|
|
105
|
+
|
|
106
|
+
items = []
|
|
107
|
+
|
|
108
|
+
# Add parent directory option (except for filesystem root)
|
|
109
|
+
if resolved_path.parent != resolved_path: # Not at filesystem root
|
|
110
|
+
items.append({
|
|
111
|
+
"name": "..",
|
|
112
|
+
"type": "directory",
|
|
113
|
+
"path": str(resolved_path.parent)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
# List directory contents
|
|
117
|
+
for item in sorted(resolved_path.iterdir()):
|
|
118
|
+
try:
|
|
119
|
+
if item.is_dir():
|
|
120
|
+
items.append({
|
|
121
|
+
"name": item.name,
|
|
122
|
+
"type": "directory",
|
|
123
|
+
"path": str(item)
|
|
124
|
+
})
|
|
125
|
+
elif item.suffix.lower() == '.json':
|
|
126
|
+
items.append({
|
|
127
|
+
"name": item.name,
|
|
128
|
+
"type": "file",
|
|
129
|
+
"path": str(item),
|
|
130
|
+
"size": item.stat().st_size
|
|
131
|
+
})
|
|
132
|
+
except (OSError, PermissionError):
|
|
133
|
+
# Skip items we can't access
|
|
134
|
+
continue
|
|
135
|
+
|
|
136
|
+
return jsonify({
|
|
137
|
+
"current_path": str(resolved_path),
|
|
138
|
+
"items": items
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
except PermissionError:
|
|
142
|
+
return jsonify({"error": "Permission denied"}), 403
|
|
143
|
+
except Exception as e:
|
|
144
|
+
return jsonify({"error": f"Failed to browse directory: {str(e)}"}), 500
|
|
145
|
+
|
|
146
|
+
@app.route('/api/scan-folder', methods=['POST'])
|
|
147
|
+
def scan_folder_for_json():
|
|
148
|
+
"""API endpoint to scan a folder recursively for JSON files."""
|
|
149
|
+
data = request.get_json()
|
|
150
|
+
folder_path = data.get('path')
|
|
151
|
+
|
|
152
|
+
if not folder_path:
|
|
153
|
+
return jsonify({"error": "No folder path provided"}), 400
|
|
154
|
+
|
|
155
|
+
try:
|
|
156
|
+
# Resolve the path
|
|
157
|
+
resolved_path = Path(folder_path).resolve()
|
|
158
|
+
|
|
159
|
+
if not resolved_path.exists():
|
|
160
|
+
return jsonify({"error": "Folder does not exist"}), 404
|
|
161
|
+
|
|
162
|
+
if not resolved_path.is_dir():
|
|
163
|
+
return jsonify({"error": "Path is not a directory"}), 400
|
|
164
|
+
|
|
165
|
+
# Scan recursively for JSON files
|
|
166
|
+
json_files = []
|
|
167
|
+
try:
|
|
168
|
+
# Use rglob to recursively find all JSON files
|
|
169
|
+
for json_file in resolved_path.rglob('*.json'):
|
|
170
|
+
try:
|
|
171
|
+
if json_file.is_file():
|
|
172
|
+
# Calculate relative path from the base folder for display
|
|
173
|
+
relative_path = json_file.relative_to(resolved_path)
|
|
174
|
+
json_files.append({
|
|
175
|
+
"name": json_file.name,
|
|
176
|
+
"path": str(json_file),
|
|
177
|
+
"relative_path": str(relative_path),
|
|
178
|
+
"size": json_file.stat().st_size,
|
|
179
|
+
"directory": str(json_file.parent.relative_to(resolved_path)) if json_file.parent != resolved_path else "."
|
|
180
|
+
})
|
|
181
|
+
except (OSError, PermissionError):
|
|
182
|
+
# Skip files we can't access
|
|
183
|
+
continue
|
|
184
|
+
except PermissionError:
|
|
185
|
+
return jsonify({"error": "Permission denied to read folder"}), 403
|
|
186
|
+
|
|
187
|
+
# Sort by relative path for better organization
|
|
188
|
+
json_files.sort(key=lambda x: x['relative_path'])
|
|
189
|
+
|
|
190
|
+
return jsonify({
|
|
191
|
+
"folder_path": str(resolved_path),
|
|
192
|
+
"json_files": json_files,
|
|
193
|
+
"count": len(json_files),
|
|
194
|
+
"scan_type": "recursive"
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
except PermissionError:
|
|
198
|
+
return jsonify({"error": "Permission denied"}), 403
|
|
199
|
+
except Exception as e:
|
|
200
|
+
return jsonify({"error": f"Failed to scan folder: {str(e)}"}), 500
|
|
201
|
+
|
|
202
|
+
@app.route('/api/load-file', methods=['POST'])
|
|
203
|
+
def load_file_from_path():
|
|
204
|
+
"""API endpoint to load a JSON file from a specific path."""
|
|
205
|
+
data = request.get_json()
|
|
206
|
+
file_path = data.get('path')
|
|
207
|
+
|
|
208
|
+
if not file_path:
|
|
209
|
+
return jsonify({"error": "No file path provided"}), 400
|
|
210
|
+
|
|
211
|
+
try:
|
|
212
|
+
# Resolve the path
|
|
213
|
+
resolved_path = Path(file_path).resolve()
|
|
214
|
+
|
|
215
|
+
if not resolved_path.exists():
|
|
216
|
+
return jsonify({"error": "File does not exist"}), 404
|
|
217
|
+
|
|
218
|
+
if not resolved_path.is_file() or resolved_path.suffix.lower() != '.json':
|
|
219
|
+
return jsonify({"error": "Not a JSON file"}), 400
|
|
220
|
+
|
|
221
|
+
# Load the file
|
|
222
|
+
global ANTISMASH_DATA, CURRENT_FILE
|
|
223
|
+
with open(resolved_path, 'r') as f:
|
|
224
|
+
data = json.load(f)
|
|
225
|
+
|
|
226
|
+
ANTISMASH_DATA = data
|
|
227
|
+
CURRENT_FILE = resolved_path.name
|
|
228
|
+
|
|
229
|
+
return jsonify({
|
|
230
|
+
"message": f"Successfully loaded {resolved_path.name}",
|
|
231
|
+
"current_file": CURRENT_FILE,
|
|
232
|
+
"file_path": str(resolved_path)
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
except PermissionError:
|
|
236
|
+
return jsonify({"error": "Permission denied"}), 403
|
|
237
|
+
except json.JSONDecodeError as e:
|
|
238
|
+
return jsonify({"error": f"Invalid JSON file: {str(e)}"}), 400
|
|
239
|
+
except Exception as e:
|
|
240
|
+
return jsonify({"error": f"Failed to load file: {str(e)}"}), 500
|
|
241
|
+
|
|
242
|
+
@app.route('/api/info')
|
|
243
|
+
def get_info():
|
|
244
|
+
"""API endpoint to get basic information about the dataset."""
|
|
245
|
+
if not ANTISMASH_DATA:
|
|
246
|
+
return jsonify({"error": "AntiSMASH data not found"}), 404
|
|
247
|
+
|
|
248
|
+
return jsonify({
|
|
249
|
+
"version": ANTISMASH_DATA.get("version"),
|
|
250
|
+
"input_file": ANTISMASH_DATA.get("input_file"),
|
|
251
|
+
"taxon": ANTISMASH_DATA.get("taxon"),
|
|
252
|
+
"total_records": len(ANTISMASH_DATA.get("records", [])),
|
|
253
|
+
"schema": ANTISMASH_DATA.get("schema"),
|
|
254
|
+
"current_file": CURRENT_FILE
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
@app.route('/api/records')
|
|
258
|
+
def get_records():
|
|
259
|
+
"""API endpoint to get list of all records (regions)."""
|
|
260
|
+
if not ANTISMASH_DATA:
|
|
261
|
+
return jsonify({"error": "AntiSMASH data not found"}), 404
|
|
262
|
+
|
|
263
|
+
records = []
|
|
264
|
+
for record in ANTISMASH_DATA.get("records", []):
|
|
265
|
+
records.append({
|
|
266
|
+
"id": record.get("id"),
|
|
267
|
+
"description": record.get("description"),
|
|
268
|
+
"gc_content": record.get("gc_content"),
|
|
269
|
+
"feature_count": len(record.get("features", []))
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
return jsonify(records)
|
|
273
|
+
|
|
274
|
+
@app.route('/api/records/<record_id>')
|
|
275
|
+
def get_record(record_id):
|
|
276
|
+
"""API endpoint to get a specific record."""
|
|
277
|
+
if not ANTISMASH_DATA:
|
|
278
|
+
return jsonify({"error": "AntiSMASH data not found"}), 404
|
|
279
|
+
|
|
280
|
+
record = next((r for r in ANTISMASH_DATA.get("records", []) if r.get("id") == record_id), None)
|
|
281
|
+
if record:
|
|
282
|
+
return jsonify(record)
|
|
283
|
+
return jsonify({"error": "Record not found"}), 404
|
|
284
|
+
|
|
285
|
+
@app.route('/api/records/<record_id>/regions')
|
|
286
|
+
def get_record_regions(record_id):
|
|
287
|
+
"""API endpoint to get all regions for a specific record."""
|
|
288
|
+
if not ANTISMASH_DATA:
|
|
289
|
+
return jsonify({"error": "AntiSMASH data not found"}), 404
|
|
290
|
+
|
|
291
|
+
record = next((r for r in ANTISMASH_DATA.get("records", []) if r.get("id") == record_id), None)
|
|
292
|
+
if not record:
|
|
293
|
+
return jsonify({"error": "Record not found"}), 404
|
|
294
|
+
|
|
295
|
+
# Filter features to get only regions
|
|
296
|
+
regions = []
|
|
297
|
+
for feature in record.get("features", []):
|
|
298
|
+
if feature.get("type") == "region":
|
|
299
|
+
# Parse location to get start/end coordinates
|
|
300
|
+
location_match = re.match(r'\[(\d+):(\d+)\]', feature.get("location", ""))
|
|
301
|
+
start = int(location_match.group(1)) if location_match else 0
|
|
302
|
+
end = int(location_match.group(2)) if location_match else 0
|
|
303
|
+
|
|
304
|
+
region_info = {
|
|
305
|
+
"id": f"region_{feature.get('qualifiers', {}).get('region_number', ['unknown'])[0]}",
|
|
306
|
+
"region_number": feature.get('qualifiers', {}).get('region_number', ['unknown'])[0],
|
|
307
|
+
"location": feature.get("location"),
|
|
308
|
+
"start": start,
|
|
309
|
+
"end": end,
|
|
310
|
+
"product": feature.get('qualifiers', {}).get('product', ['unknown']),
|
|
311
|
+
"rules": feature.get('qualifiers', {}).get('rules', [])
|
|
312
|
+
}
|
|
313
|
+
regions.append(region_info)
|
|
314
|
+
|
|
315
|
+
return jsonify({
|
|
316
|
+
"record_id": record_id,
|
|
317
|
+
"regions": sorted(regions, key=lambda x: x['start'])
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
@app.route('/api/records/<record_id>/regions/<region_id>/features')
|
|
321
|
+
def get_region_features(record_id, region_id):
|
|
322
|
+
"""API endpoint to get all features within a specific region."""
|
|
323
|
+
if not ANTISMASH_DATA:
|
|
324
|
+
return jsonify({"error": "AntiSMASH data not found"}), 404
|
|
325
|
+
|
|
326
|
+
record = next((r for r in ANTISMASH_DATA.get("records", []) if r.get("id") == record_id), None)
|
|
327
|
+
if not record:
|
|
328
|
+
return jsonify({"error": "Record not found"}), 404
|
|
329
|
+
|
|
330
|
+
# Find the region to get its boundaries
|
|
331
|
+
region_feature = None
|
|
332
|
+
for feature in record.get("features", []):
|
|
333
|
+
if (feature.get("type") == "region" and
|
|
334
|
+
f"region_{feature.get('qualifiers', {}).get('region_number', [''])[0]}" == region_id):
|
|
335
|
+
region_feature = feature
|
|
336
|
+
break
|
|
337
|
+
|
|
338
|
+
if not region_feature:
|
|
339
|
+
return jsonify({"error": "Region not found"}), 404
|
|
340
|
+
|
|
341
|
+
# Parse region boundaries
|
|
342
|
+
region_location = region_feature.get("location", "")
|
|
343
|
+
region_match = re.match(r'\[(\d+):(\d+)\]', region_location)
|
|
344
|
+
if not region_match:
|
|
345
|
+
return jsonify({"error": "Invalid region location format"}), 400
|
|
346
|
+
|
|
347
|
+
region_start = int(region_match.group(1))
|
|
348
|
+
region_end = int(region_match.group(2))
|
|
349
|
+
|
|
350
|
+
# Get optional query parameters
|
|
351
|
+
feature_type = request.args.get('type')
|
|
352
|
+
|
|
353
|
+
# Filter features that fall within the region boundaries
|
|
354
|
+
region_features = []
|
|
355
|
+
for feature in record.get("features", []):
|
|
356
|
+
# Skip the region feature itself
|
|
357
|
+
if feature.get("type") == "region":
|
|
358
|
+
continue
|
|
359
|
+
|
|
360
|
+
# Parse feature location
|
|
361
|
+
feature_location = feature.get("location", "")
|
|
362
|
+
feature_match = re.match(r'\[(\d+):(\d+)\]', feature_location)
|
|
363
|
+
if not feature_match:
|
|
364
|
+
continue
|
|
365
|
+
|
|
366
|
+
feature_start = int(feature_match.group(1))
|
|
367
|
+
feature_end = int(feature_match.group(2))
|
|
368
|
+
|
|
369
|
+
# Check if feature overlaps with region (allow partial overlaps)
|
|
370
|
+
if not (feature_end < region_start or feature_start > region_end):
|
|
371
|
+
# Apply type filter if specified
|
|
372
|
+
if feature_type and feature.get("type") != feature_type:
|
|
373
|
+
continue
|
|
374
|
+
region_features.append(feature)
|
|
375
|
+
|
|
376
|
+
return jsonify({
|
|
377
|
+
"record_id": record_id,
|
|
378
|
+
"region_id": region_id,
|
|
379
|
+
"region_location": region_location,
|
|
380
|
+
"region_boundaries": {"start": region_start, "end": region_end},
|
|
381
|
+
"feature_type": feature_type or "all",
|
|
382
|
+
"count": len(region_features),
|
|
383
|
+
"features": region_features
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
@app.route('/api/records/<record_id>/features')
|
|
387
|
+
def get_record_features(record_id):
|
|
388
|
+
"""API endpoint to get all features for a specific record."""
|
|
389
|
+
if not ANTISMASH_DATA:
|
|
390
|
+
return jsonify({"error": "AntiSMASH data not found"}), 404
|
|
391
|
+
|
|
392
|
+
# Get optional query parameters
|
|
393
|
+
feature_type = request.args.get('type')
|
|
394
|
+
limit = request.args.get('limit', type=int)
|
|
395
|
+
|
|
396
|
+
record = next((r for r in ANTISMASH_DATA.get("records", []) if r.get("id") == record_id), None)
|
|
397
|
+
if not record:
|
|
398
|
+
return jsonify({"error": "Record not found"}), 404
|
|
399
|
+
|
|
400
|
+
features = record.get("features", [])
|
|
401
|
+
|
|
402
|
+
# Filter by type if specified
|
|
403
|
+
if feature_type:
|
|
404
|
+
features = [f for f in features if f.get("type") == feature_type]
|
|
405
|
+
|
|
406
|
+
# Limit results if specified
|
|
407
|
+
if limit:
|
|
408
|
+
features = features[:limit]
|
|
409
|
+
|
|
410
|
+
return jsonify({
|
|
411
|
+
"record_id": record_id,
|
|
412
|
+
"feature_type": feature_type or "all",
|
|
413
|
+
"count": len(features),
|
|
414
|
+
"features": features
|
|
415
|
+
})
|
|
416
|
+
|
|
417
|
+
@app.route('/api/feature-types')
|
|
418
|
+
def get_feature_types():
|
|
419
|
+
"""API endpoint to get all available feature types across all records."""
|
|
420
|
+
if not ANTISMASH_DATA:
|
|
421
|
+
return jsonify({"error": "AntiSMASH data not found"}), 404
|
|
422
|
+
|
|
423
|
+
feature_types = set()
|
|
424
|
+
for record in ANTISMASH_DATA.get("records", []):
|
|
425
|
+
for feature in record.get("features", []):
|
|
426
|
+
if "type" in feature:
|
|
427
|
+
feature_types.add(feature["type"])
|
|
428
|
+
|
|
429
|
+
return jsonify(sorted(list(feature_types)))
|
|
430
|
+
|
|
431
|
+
@app.route('/api/stats')
|
|
432
|
+
def get_stats():
|
|
433
|
+
"""API endpoint to get statistics about the dataset."""
|
|
434
|
+
if not ANTISMASH_DATA:
|
|
435
|
+
return jsonify({"error": "AntiSMASH data not found"}), 404
|
|
436
|
+
|
|
437
|
+
# Calculate statistics
|
|
438
|
+
records = ANTISMASH_DATA.get("records", [])
|
|
439
|
+
total_features = sum(len(r.get("features", [])) for r in records)
|
|
440
|
+
|
|
441
|
+
feature_type_counts = {}
|
|
442
|
+
for record in records:
|
|
443
|
+
for feature in record.get("features", []):
|
|
444
|
+
ftype = feature.get("type", "unknown")
|
|
445
|
+
feature_type_counts[ftype] = feature_type_counts.get(ftype, 0) + 1
|
|
446
|
+
|
|
447
|
+
return jsonify({
|
|
448
|
+
"total_records": len(records),
|
|
449
|
+
"total_features": total_features,
|
|
450
|
+
"feature_types": feature_type_counts,
|
|
451
|
+
"version": ANTISMASH_DATA.get("version"),
|
|
452
|
+
"schema": ANTISMASH_DATA.get("schema")
|
|
453
|
+
})
|
|
454
|
+
|
|
455
|
+
@app.route('/api/health')
|
|
456
|
+
def health_check():
|
|
457
|
+
"""Health check endpoint."""
|
|
458
|
+
return jsonify({"status": "healthy", "message": "Server is running"})
|
|
459
|
+
|
|
460
|
+
@app.errorhandler(404)
|
|
461
|
+
def not_found(error):
|
|
462
|
+
"""Handle 404 errors."""
|
|
463
|
+
return jsonify({"error": "Not found"}), 404
|
|
464
|
+
|
|
465
|
+
@app.errorhandler(500)
|
|
466
|
+
def internal_error(error):
|
|
467
|
+
"""Handle 500 errors."""
|
|
468
|
+
return jsonify({"error": "Internal server error"}), 500
|
|
469
|
+
|
|
470
|
+
def load_custom_data():
|
|
471
|
+
"""Load custom data from a file or database."""
|
|
472
|
+
# This function is deprecated - now using ANTISMASH_DATA
|
|
473
|
+
return load_antismash_data()
|
|
474
|
+
|
|
475
|
+
def main():
|
|
476
|
+
"""Main entry point for the application."""
|
|
477
|
+
|
|
478
|
+
host = os.environ.get('BGCV_HOST', 'localhost')
|
|
479
|
+
port = int(os.environ.get('BGCV_PORT', 5005))
|
|
480
|
+
debug_mode = os.getenv('BGCV_DEBUG_MODE', 'False').lower() == 'true'
|
|
481
|
+
|
|
482
|
+
if debug_mode:
|
|
483
|
+
print(f"Running in debug mode on {host}:{port}")
|
|
484
|
+
app.run(host=host, port=port, debug=True)
|
|
485
|
+
else:
|
|
486
|
+
print(f"Running server on {host}:{port}")
|
|
487
|
+
serve(app, host=host, port=port, threads=4)
|
|
488
|
+
|
|
489
|
+
if __name__ == '__main__':
|
|
490
|
+
main()
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>BGC Viewer</title>
|
|
7
|
+
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div class="container">
|
|
11
|
+
<header>
|
|
12
|
+
<h1>BGC Viewer</h1>
|
|
13
|
+
</header>
|
|
14
|
+
|
|
15
|
+
<main>
|
|
16
|
+
<section class="api-section">
|
|
17
|
+
<h2>API Endpoints</h2>
|
|
18
|
+
<div class="endpoint-list">
|
|
19
|
+
<div class="endpoint">
|
|
20
|
+
<code>GET /api/info</code>
|
|
21
|
+
<p>Get dataset information and metadata</p>
|
|
22
|
+
<button onclick="fetchData('/api/info', 'data-output')">Test</button>
|
|
23
|
+
</div>
|
|
24
|
+
<div class="endpoint">
|
|
25
|
+
<code>GET /api/records</code>
|
|
26
|
+
<p>Get all records (regions) summary</p>
|
|
27
|
+
<button onclick="fetchData('/api/records', 'users-output')">Test</button>
|
|
28
|
+
</div>
|
|
29
|
+
<div class="endpoint">
|
|
30
|
+
<code>GET /api/feature-types</code>
|
|
31
|
+
<p>Get all available feature types</p>
|
|
32
|
+
<button onclick="fetchData('/api/feature-types', 'feature-types-output')">Test</button>
|
|
33
|
+
</div>
|
|
34
|
+
<div class="endpoint">
|
|
35
|
+
<code>GET /api/stats</code>
|
|
36
|
+
<p>Get dataset statistics</p>
|
|
37
|
+
<button onclick="fetchData('/api/stats', 'stats-output')">Test</button>
|
|
38
|
+
</div>
|
|
39
|
+
<div class="endpoint">
|
|
40
|
+
<code>GET /api/health</code>
|
|
41
|
+
<p>Health check endpoint</p>
|
|
42
|
+
<button onclick="fetchData('/api/health', 'health-output')">Test</button>
|
|
43
|
+
</div>
|
|
44
|
+
<div class="endpoint">
|
|
45
|
+
<code>GET /api/records/{record_id}/features?type={type}</code>
|
|
46
|
+
<p>Get features by type for a specific record</p>
|
|
47
|
+
<input type="text" id="record-id" placeholder="Record ID" style="margin: 5px;">
|
|
48
|
+
<input type="text" id="feature-type" placeholder="Feature Type (optional)" style="margin: 5px;">
|
|
49
|
+
<button onclick="fetchRecordFeatures()">Test</button>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
</section>
|
|
53
|
+
|
|
54
|
+
<section class="results-section">
|
|
55
|
+
<h2>API Results</h2>
|
|
56
|
+
<div id="data-output" class="output-box">
|
|
57
|
+
<h3>Dataset Info</h3>
|
|
58
|
+
<pre>Click "Test" buttons above to see API responses</pre>
|
|
59
|
+
</div>
|
|
60
|
+
<div id="users-output" class="output-box">
|
|
61
|
+
<h3>Records</h3>
|
|
62
|
+
<pre></pre>
|
|
63
|
+
</div>
|
|
64
|
+
<div id="feature-types-output" class="output-box">
|
|
65
|
+
<h3>Feature Types</h3>
|
|
66
|
+
<pre></pre>
|
|
67
|
+
</div>
|
|
68
|
+
<div id="stats-output" class="output-box">
|
|
69
|
+
<h3>Dataset Statistics</h3>
|
|
70
|
+
<pre></pre>
|
|
71
|
+
</div>
|
|
72
|
+
<div id="health-output" class="output-box">
|
|
73
|
+
<h3>Health Status</h3>
|
|
74
|
+
<pre></pre>
|
|
75
|
+
</div>
|
|
76
|
+
<div id="record-features-output" class="output-box">
|
|
77
|
+
<h3>Record Features</h3>
|
|
78
|
+
<pre></pre>
|
|
79
|
+
</div>
|
|
80
|
+
</section>
|
|
81
|
+
</main>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<script src="{{ url_for('static', filename='app.js') }}"></script>
|
|
85
|
+
</body>
|
|
86
|
+
</html>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import json
|
|
3
|
+
from bgc_viewer.app import app
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.fixture
|
|
7
|
+
def client():
|
|
8
|
+
"""Create a test client for the Flask application."""
|
|
9
|
+
app.config['TESTING'] = True
|
|
10
|
+
with app.test_client() as client:
|
|
11
|
+
yield client
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_index_route(client):
|
|
15
|
+
"""Test the main index route."""
|
|
16
|
+
response = client.get('/')
|
|
17
|
+
assert response.status_code == 200
|
|
18
|
+
assert b'BGC Viewer' in response.data
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_api_info_route(client):
|
|
22
|
+
"""Test the /api/info endpoint."""
|
|
23
|
+
response = client.get('/api/info')
|
|
24
|
+
assert response.status_code == 200
|
|
25
|
+
data = json.loads(response.data)
|
|
26
|
+
# Could be empty if no data file, but should have consistent structure
|
|
27
|
+
if 'error' not in data:
|
|
28
|
+
assert 'version' in data
|
|
29
|
+
assert 'total_records' in data
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_api_records_route(client):
|
|
33
|
+
"""Test the /api/records endpoint."""
|
|
34
|
+
response = client.get('/api/records')
|
|
35
|
+
assert response.status_code in [200, 404] # 404 if no data file
|
|
36
|
+
data = json.loads(response.data)
|
|
37
|
+
if response.status_code == 200:
|
|
38
|
+
assert isinstance(data, list)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_api_feature_types_route(client):
|
|
42
|
+
"""Test the /api/feature-types endpoint."""
|
|
43
|
+
response = client.get('/api/feature-types')
|
|
44
|
+
assert response.status_code in [200, 404] # 404 if no data file
|
|
45
|
+
data = json.loads(response.data)
|
|
46
|
+
if response.status_code == 200:
|
|
47
|
+
assert isinstance(data, list)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_api_stats_route(client):
|
|
51
|
+
"""Test the /api/stats endpoint."""
|
|
52
|
+
response = client.get('/api/stats')
|
|
53
|
+
assert response.status_code in [200, 404] # 404 if no data file
|
|
54
|
+
data = json.loads(response.data)
|
|
55
|
+
if response.status_code == 200:
|
|
56
|
+
assert 'total_records' in data
|
|
57
|
+
assert 'total_features' in data
|
|
58
|
+
assert 'feature_types' in data
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_health_check_route(client):
|
|
62
|
+
"""Test the /api/health endpoint."""
|
|
63
|
+
response = client.get('/api/health')
|
|
64
|
+
assert response.status_code == 200
|
|
65
|
+
data = json.loads(response.data)
|
|
66
|
+
assert data['status'] == 'healthy'
|
|
67
|
+
assert 'message' in data
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_404_handler(client):
|
|
71
|
+
"""Test 404 error handling."""
|
|
72
|
+
response = client.get('/nonexistent')
|
|
73
|
+
assert response.status_code == 404
|
|
74
|
+
data = json.loads(response.data)
|
|
75
|
+
assert 'error' in data
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_cors_headers(client):
|
|
79
|
+
"""Test that CORS headers are present."""
|
|
80
|
+
response = client.get('/api/health')
|
|
81
|
+
assert response.status_code == 200
|
|
82
|
+
# Flask-CORS should add these headers
|
|
83
|
+
assert 'Access-Control-Allow-Origin' in response.headers
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bgc-viewer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Flask server for Biosynthetic Gene Cluster analysis
|
|
5
|
+
Author-email: Your Name <your.email@example.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.8.1
|
|
9
|
+
Requires-Dist: flask-cors>=4.0.0
|
|
10
|
+
Requires-Dist: flask>=2.3.0
|
|
11
|
+
Requires-Dist: python-dotenv>=1.0.1
|
|
12
|
+
Requires-Dist: waitress>=3.0.0
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: black>=23.0.0; extra == 'dev'
|
|
15
|
+
Requires-Dist: build>=0.10.0; extra == 'dev'
|
|
16
|
+
Requires-Dist: flake8>=6.0.0; extra == 'dev'
|
|
17
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
18
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
19
|
+
Requires-Dist: twine>=4.0.0; extra == 'dev'
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# BGC-Viewer
|
|
23
|
+
|
|
24
|
+
!!Work-in-progress!!
|
|
25
|
+
|
|
26
|
+
A viewer for BGC data.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Project Structure
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
bgc-viewer/
|
|
33
|
+
├── bgc_viewer/
|
|
34
|
+
│ ├── __init__.py
|
|
35
|
+
│ ├── app.py # Main Flask application
|
|
36
|
+
│ ├── static/
|
|
37
|
+
│ │ └── style.css # Styling
|
|
38
|
+
│ │ └── app.js # Frontend JavaScript
|
|
39
|
+
│ └── templates/
|
|
40
|
+
│ └── index.html # Main HTML template
|
|
41
|
+
├── data/
|
|
42
|
+
│ └── custom_data.json # Optional custom data file
|
|
43
|
+
├── tests/
|
|
44
|
+
│ └── test_app.py # Test files
|
|
45
|
+
├── pyproject.toml # Project configuration
|
|
46
|
+
├── README.md
|
|
47
|
+
└── .gitignore
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Setup
|
|
51
|
+
|
|
52
|
+
### Prerequisites
|
|
53
|
+
|
|
54
|
+
- Python 3.8+
|
|
55
|
+
- [uv](https://github.com/astral-sh/uv) package manager
|
|
56
|
+
|
|
57
|
+
### Installation
|
|
58
|
+
|
|
59
|
+
1. Clone or create the project directory:
|
|
60
|
+
```bash
|
|
61
|
+
mkdir bgc-viewer
|
|
62
|
+
cd bgc-viewer
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
2. Create the project structure and files (as shown above)
|
|
66
|
+
|
|
67
|
+
3. Initialize the project with uv:
|
|
68
|
+
```bash
|
|
69
|
+
uv venv
|
|
70
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
71
|
+
uv pip install -e .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
4. For development dependencies:
|
|
75
|
+
```bash
|
|
76
|
+
uv pip install -e ".[dev]"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
### Running the Server
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Using the console script
|
|
85
|
+
serve
|
|
86
|
+
|
|
87
|
+
# Or directly with Python
|
|
88
|
+
python -m bgc_viewer.app
|
|
89
|
+
|
|
90
|
+
# Or with environment variables
|
|
91
|
+
FLASK_DEBUG=true PORT=8000 serve
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The server will start on `http://localhost:5005` by default.
|
|
95
|
+
|
|
96
|
+
### API Endpoints
|
|
97
|
+
|
|
98
|
+
- `GET /` - Main HTML page with interactive API tester
|
|
99
|
+
- `GET /api/data` - Get all custom data
|
|
100
|
+
- `GET /api/users` - Get user list
|
|
101
|
+
- `GET /api/users/<id>` - Get specific user
|
|
102
|
+
- `GET /api/stats` - Get application statistics
|
|
103
|
+
- `GET /api/health` - Health check endpoint
|
|
104
|
+
|
|
105
|
+
### Testing the API
|
|
106
|
+
|
|
107
|
+
Visit `http://localhost:5005` in your browser to access the interactive API tester, or use curl:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# Get all data
|
|
111
|
+
curl http://localhost:5005/api/data
|
|
112
|
+
|
|
113
|
+
# Get users
|
|
114
|
+
curl http://localhost:5005/api/users
|
|
115
|
+
|
|
116
|
+
# Get specific user
|
|
117
|
+
curl http://localhost:5005/api/users/1
|
|
118
|
+
|
|
119
|
+
# Health check
|
|
120
|
+
curl http://localhost:5005/api/health
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Development
|
|
124
|
+
|
|
125
|
+
### Code Formatting
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Format code
|
|
129
|
+
uv run black bgc_viewer/
|
|
130
|
+
|
|
131
|
+
# Lint code
|
|
132
|
+
uv run flake8 bgc_viewer/
|
|
133
|
+
|
|
134
|
+
# Type checking
|
|
135
|
+
uv run mypy bgc_viewer/
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Testing
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# Run tests
|
|
142
|
+
uv run pytest
|
|
143
|
+
|
|
144
|
+
# Run tests with coverage
|
|
145
|
+
uv run pytest --cov=bgc_viewer
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Adding Custom Data
|
|
149
|
+
|
|
150
|
+
1. Create a `data/custom_data.json` file with your data structure
|
|
151
|
+
2. Modify the `load_custom_data()` function in `app.py` to read from your data source
|
|
152
|
+
3. Update the API endpoints to serve your custom data
|
|
153
|
+
|
|
154
|
+
## Customization
|
|
155
|
+
|
|
156
|
+
### Adding New Endpoints
|
|
157
|
+
|
|
158
|
+
1. Add new route functions to `app.py`
|
|
159
|
+
2. Update the HTML template to include new endpoints
|
|
160
|
+
3. Add corresponding JavaScript functions if needed
|
|
161
|
+
|
|
162
|
+
### Styling
|
|
163
|
+
|
|
164
|
+
Modify `static/css/style.css` to customize the appearance of the web interface.
|
|
165
|
+
|
|
166
|
+
### Frontend Behavior
|
|
167
|
+
|
|
168
|
+
Update `static/js/app.js` to add new interactive features.
|
|
169
|
+
|
|
170
|
+
## Environment Variables
|
|
171
|
+
|
|
172
|
+
Environment variables can be set to change the configuration of the viewer.
|
|
173
|
+
A convenient way to change them is to put a file called `.env` in the directory from
|
|
174
|
+
which you are running the application.
|
|
175
|
+
|
|
176
|
+
- `BGCV_HOST` - Server host (default: localhost)
|
|
177
|
+
- `BGCV_PORT` - Server port (default: 5005)
|
|
178
|
+
- `BGCV_DEBUG_MODE` - Enable dev/debug mode (default: False)
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
Apache 2.0
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
bgc_viewer/__init__.py,sha256=01_sUtO7s6Bzr9jzOHl1j7Dpds8GzzCivz74WzjpAws,190
|
|
2
|
+
bgc_viewer/app.py,sha256=h1Kug7SiP4PZJDTlWhHF0U06_Vfkwx4YoZX8pfEMBc0,17349
|
|
3
|
+
bgc_viewer/templates/index.html,sha256=AVvudByHTSXcWZOuL0CQoJEnGtqJ9Zd50fF_EgdRzIw,3738
|
|
4
|
+
bgc_viewer/tests/test_app.py,sha256=TkEnHhdpy0NMbqp8auqo_kucXCpbo1zqmxZfnAgimGc,2521
|
|
5
|
+
bgc_viewer-0.1.0.dist-info/METADATA,sha256=vwrg4tMwXCMfKtW8DN5ENc0we9lVMiGYGstHnhH3NzY,4052
|
|
6
|
+
bgc_viewer-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
bgc_viewer-0.1.0.dist-info/entry_points.txt,sha256=18SDKjHGPlGxb4l2gwU4Sqt4pNCCfFDOsybcxiRdYVY,51
|
|
8
|
+
bgc_viewer-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
9
|
+
bgc_viewer-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|