Spaces:
Runtime error
Runtime error
Download init_db.py from ShoaibAI/apiweb-local: direct link, hf CLI and curl.
- Browser
- Download file 7.14 kB
-
https://huggingface.co/spaces/ShoaibAI/apiweb-local/resolve/main/init_db.py
- Command line
-
hf download hf://spaces/ShoaibAI/apiweb-local/init_db.py
-
curl -L -o init_db.py https://huggingface.co/spaces/ShoaibAI/apiweb-local/resolve/main/init_db.py
7.14 kB
| import sqlite3 | |
| import os | |
| def init_database(): | |
| """Initialize SQLite database with species and biochemical profiles""" | |
| conn = sqlite3.connect('microid.db') | |
| cursor = conn.cursor() | |
| # Create tables | |
| cursor.execute(''' | |
| CREATE TABLE IF NOT EXISTS species ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| genus TEXT NOT NULL, | |
| species TEXT NOT NULL, | |
| full_name TEXT UNIQUE NOT NULL, | |
| gram_stain TEXT, | |
| morphology TEXT, | |
| notes TEXT | |
| ) | |
| ''') | |
| cursor.execute(''' | |
| CREATE TABLE IF NOT EXISTS biochemical_tests ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| test_code TEXT UNIQUE NOT NULL, | |
| test_name TEXT NOT NULL, | |
| description TEXT, | |
| position INTEGER | |
| ) | |
| ''') | |
| cursor.execute(''' | |
| CREATE TABLE IF NOT EXISTS species_profiles ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| species_id INTEGER, | |
| test_id INTEGER, | |
| reaction TEXT NOT NULL, | |
| probability REAL DEFAULT 0.95, | |
| FOREIGN KEY (species_id) REFERENCES species(id), | |
| FOREIGN KEY (test_id) REFERENCES biochemical_tests(id) | |
| ) | |
| ''') | |
| # Insert biochemical tests | |
| tests = [ | |
| (1, 'ONPG', 'Beta-galactosidase', 1), | |
| (2, 'ADH', 'Arginine dihydrolase', 2), | |
| (3, 'LDC', 'Lysine decarboxylase', 3), | |
| (4, 'ODC', 'Ornithine decarboxylase', 4), | |
| (5, 'CIT', 'Citrate utilization', 5), | |
| (6, 'H2S', 'Hydrogen sulfide', 6), | |
| (7, 'URE', 'Urease', 7), | |
| (8, 'TDA', 'Tryptophan deaminase', 8), | |
| (9, 'IND', 'Indole production', 9), | |
| (10, 'VP', 'Voges-Proskauer', 10), | |
| (11, 'GEL', 'Gelatinase', 11), | |
| (12, 'GLU', 'Glucose fermentation', 12), | |
| (13, 'MAN', 'Mannitol', 13), | |
| (14, 'INO', 'Inositol', 14), | |
| (15, 'SOR', 'Sorbitol', 15), | |
| (16, 'RHA', 'Rhamnose', 16), | |
| (17, 'SAC', 'Sucrose', 17), | |
| (18, 'MEL', 'Melibiose', 18), | |
| (19, 'AMY', 'Amygdalin', 19), | |
| (20, 'ARA', 'Arabinose', 20) | |
| ] | |
| for test in tests: | |
| cursor.execute(''' | |
| INSERT OR IGNORE INTO biochemical_tests (id, test_code, test_name, position) | |
| VALUES (?, ?, ?, ?) | |
| ''', test) | |
| # Insert species | |
| species_list = [ | |
| ('Escherichia', 'coli', 'Escherichia coli', 'negative', 'rod'), | |
| ('Pseudomonas', 'aeruginosa', 'Pseudomonas aeruginosa', 'negative', 'rod'), | |
| ('Staphylococcus', 'aureus', 'Staphylococcus aureus', 'positive', 'coccus'), | |
| ('Streptococcus', 'pneumoniae', 'Streptococcus pneumoniae', 'positive', 'coccus'), | |
| ('Klebsiella', 'pneumoniae', 'Klebsiella pneumoniae', 'negative', 'rod'), | |
| ('Proteus', 'mirabilis', 'Proteus mirabilis', 'negative', 'rod'), | |
| ('Enterococcus', 'faecalis', 'Enterococcus faecalis', 'positive', 'coccus'), | |
| ('Neisseria', 'gonorrhoeae', 'Neisseria gonorrhoeae', 'negative', 'coccus'), | |
| ('Haemophilus', 'influenzae', 'Haemophilus influenzae', 'negative', 'rod'), | |
| ('Candida', 'albicans', 'Candida albicans', 'yeast', 'yeast'), | |
| ('Salmonella', 'typhimurium', 'Salmonella typhimurium', 'negative', 'rod'), | |
| ('Shigella', 'flexneri', 'Shigella flexneri', 'negative', 'rod'), | |
| ('Bacillus', 'subtilis', 'Bacillus subtilis', 'positive', 'rod'), | |
| ('Clostridium', 'perfringens', 'Clostridium perfringens', 'positive', 'rod'), | |
| ('Listeria', 'monocytogenes', 'Listeria monocytogenes', 'positive', 'rod'), | |
| ('Acinetobacter', 'baumannii', 'Acinetobacter baumannii', 'negative', 'coccus'), | |
| ('Enterobacter', 'cloacae', 'Enterobacter cloacae', 'negative', 'rod'), | |
| ('Serratia', 'marcescens', 'Serratia marcescens', 'negative', 'rod'), | |
| ('Citrobacter', 'freundii', 'Citrobacter freundii', 'negative', 'rod'), | |
| ('Morganella', 'morganii', 'Morganella morganii', 'negative', 'rod'), | |
| ('Yersinia', 'enterocolitica', 'Yersinia enterocolitica', 'negative', 'rod'), | |
| ('Vibrio', 'cholerae', 'Vibrio cholerae', 'negative', 'rod'), | |
| ('Campylobacter', 'jejuni', 'Campylobacter jejuni', 'negative', 'curved rod'), | |
| ('Bacteroides', 'fragilis', 'Bacteroides fragilis', 'negative', 'rod'), | |
| ('Lactobacillus', 'acidophilus', 'Lactobacillus acidophilus', 'positive', 'rod'), | |
| ('Streptococcus', 'pyogenes', 'Streptococcus pyogenes', 'positive', 'coccus'), | |
| ('Staphylococcus', 'epidermidis', 'Staphylococcus epidermidis', 'positive', 'coccus'), | |
| ('Candida', 'glabrata', 'Candida glabrata', 'yeast', 'yeast'), | |
| ('Candida', 'parapsilosis', 'Candida parapsilosis', 'yeast', 'yeast'), | |
| ('Candida', 'tropicalis', 'Candida tropicalis', 'yeast', 'yeast'), | |
| ('Cryptococcus', 'neoformans', 'Cryptococcus neoformans', 'yeast', 'yeast') | |
| ] | |
| for species in species_list: | |
| cursor.execute(''' | |
| INSERT OR IGNORE INTO species (genus, species, full_name, gram_stain, morphology) | |
| VALUES (?, ?, ?, ?, ?) | |
| ''', species) | |
| # Get species IDs | |
| cursor.execute('SELECT id, full_name FROM species') | |
| species_map = {row[1]: row[0] for row in cursor.fetchall()} | |
| # Get test IDs | |
| cursor.execute('SELECT id, test_code FROM biochemical_tests') | |
| test_map = {row[1]: row[0] for row in cursor.fetchall()} | |
| # Insert profiles (simplified - add more for full database) | |
| profiles = { | |
| 'Escherichia coli': { | |
| 'ONPG':'+', 'ADH':'-', 'LDC':'+', 'ODC':'+', 'CIT':'-', | |
| 'H2S':'-', 'URE':'-', 'TDA':'-', 'IND':'+', 'VP':'-', | |
| 'GEL':'-', 'GLU':'+', 'MAN':'+', 'INO':'-', 'SOR':'+', | |
| 'RHA':'+', 'SAC':'+', 'MEL':'+', 'AMY':'-', 'ARA':'+' | |
| }, | |
| 'Pseudomonas aeruginosa': { | |
| 'ONPG':'-', 'ADH':'+', 'LDC':'-', 'ODC':'-', 'CIT':'+', | |
| 'H2S':'-', 'URE':'-', 'TDA':'-', 'IND':'-', 'VP':'-', | |
| 'GEL':'+', 'GLU':'+', 'MAN':'-', 'INO':'-', 'SOR':'-', | |
| 'RHA':'-', 'SAC':'-', 'MEL':'-', 'AMY':'-', 'ARA':'-' | |
| }, | |
| 'Staphylococcus aureus': { | |
| 'ONPG':'+', 'ADH':'-', 'LDC':'-', 'ODC':'-', 'CIT':'V', | |
| 'H2S':'-', 'URE':'+', 'TDA':'-', 'IND':'-', 'VP':'+', | |
| 'GEL':'V', 'GLU':'+', 'MAN':'+', 'INO':'-', 'SOR':'+', | |
| 'RHA':'V', 'SAC':'+', 'MEL':'-', 'AMY':'V', 'ARA':'-' | |
| } | |
| } | |
| # Add more species profiles (I'll add more in the complete version) | |
| for species_name, reactions in profiles.items(): | |
| if species_name in species_map: | |
| species_id = species_map[species_name] | |
| for test_code, reaction in reactions.items(): | |
| test_id = test_map[test_code] | |
| cursor.execute(''' | |
| INSERT OR IGNORE INTO species_profiles (species_id, test_id, reaction) | |
| VALUES (?, ?, ?) | |
| ''', (species_id, test_id, reaction)) | |
| conn.commit() | |
| conn.close() | |
| print("Database initialized successfully!") | |
| if __name__ == "__main__": | |
| init_database() |