Spaces:
Runtime error
Runtime error
File size: 7,137 Bytes
f42f43e | 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 | 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() |