Skip to content

Commit

Permalink
Merge pull request #384 from monarch-initiative/383-duckdbduckdbparse…
Browse files Browse the repository at this point in the history
…rexception-parser-error-syntax-error-at-or-near-1

383 duckdbduckdbparserexception parser error syntax error at or near 1
  • Loading branch information
yaseminbridges authored Jan 16, 2025
2 parents e783ceb + 378aafb commit d2aeac0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pheval"
version = "0.4.4"
version = "0.4.5"
description = ""
authors = ["Yasemin Bridges <y.bridges@qmul.ac.uk>",
"Julius Jacobsen <j.jacobsen@qmul.ac.uk>",
Expand Down
4 changes: 2 additions & 2 deletions src/pheval/analyse/benchmark_db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def add_column_integer_default(self, table_name: str, column: str, default: int
"""
try:
self.conn.execute(
f'ALTER TABLE {table_name} ADD COLUMN "{column}" INTEGER DEFAULT {default}'
f'ALTER TABLE "{table_name}" ADD COLUMN "{column}" INTEGER DEFAULT {default}'
)
self.conn.execute(f'UPDATE {table_name} SET "{column}" = ?', (default,))
self.conn.execute(f'UPDATE "{table_name}" SET "{column}" = ?', (default,))
self.conn.commit()
except duckdb.CatalogException:
pass
Expand Down
4 changes: 2 additions & 2 deletions src/pheval/analyse/disease_prioritisation_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def assess_disease_prioritisation(
"""
relevant_ranks = []
df = self.conn.execute(
f"SELECT * FROM {self.table_name} WHERE phenopacket = ? ",
f"SELECT * FROM '{self.table_name}' WHERE phenopacket = ? ",
(phenopacket_path.name,),
).fetchdf()
for _i, row in df.iterrows():
Expand All @@ -58,7 +58,7 @@ def assess_disease_prioritisation(
relevant_ranks.append(disease_match)
primary_key = f"{phenopacket_path.name}-{row['disease_identifier']}"
self.conn.execute(
f'UPDATE {self.table_name} SET "{self.column}" = ? WHERE identifier = ?',
f'UPDATE "{self.table_name}" SET "{self.column}" = ? WHERE identifier = ?',
(disease_match, primary_key),
)
elif len(result) == 0:
Expand Down
4 changes: 2 additions & 2 deletions src/pheval/analyse/gene_prioritisation_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def assess_gene_prioritisation(
"""
relevant_ranks = []
df = self.conn.execute(
f"""SELECT * FROM {self.table_name} WHERE phenopacket = '{phenopacket_path.name}'"""
f"""SELECT * FROM "{self.table_name}" WHERE phenopacket = '{phenopacket_path.name}'"""
).fetchdf()
for _i, row in df.iterrows():
result = (
Expand All @@ -55,7 +55,7 @@ def assess_gene_prioritisation(
relevant_ranks.append(gene_match)
primary_key = f"{phenopacket_path.name}-{row['gene_symbol']}"
self.conn.execute(
f'UPDATE {self.table_name} SET "{self.column}" = ? WHERE identifier = ?',
f'UPDATE "{self.table_name}" SET "{self.column}" = ? WHERE identifier = ?',
(gene_match, primary_key),
)
if not result:
Expand Down
14 changes: 7 additions & 7 deletions src/pheval/analyse/parse_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _create_gene_table(self) -> None:
"""
self.conn.execute(
f"""
CREATE TABLE IF NOT EXISTS {self.table_name}_gene (
CREATE TABLE IF NOT EXISTS "{self.table_name}_gene" (
identifier VARCHAR(255) PRIMARY KEY,
phenopacket VARCHAR,
gene_symbol VARCHAR,
Expand All @@ -96,7 +96,7 @@ def _create_variant_table(self) -> None:
"""
self.conn.execute(
f"""
CREATE TABLE IF NOT EXISTS {self.table_name}_variant (
CREATE TABLE IF NOT EXISTS "{self.table_name}_variant" (
identifier VARCHAR(255) PRIMARY KEY,
phenopacket VARCHAR,
chrom VARCHAR,
Expand All @@ -113,7 +113,7 @@ def _create_disease_table(self):
"""
self.conn.execute(
f"""
CREATE TABLE IF NOT EXISTS {self.table_name}_disease (
CREATE TABLE IF NOT EXISTS "{self.table_name}_disease" (
identifier VARCHAR(255) PRIMARY KEY,
phenopacket VARCHAR,
disease_identifier VARCHAR,
Expand Down Expand Up @@ -147,7 +147,7 @@ def _insert_genes(self, phenopacket_path: Path, genes: List[ProbandCausativeGene
identifier = f"{phenopacket_path.name}-{gene.gene_symbol}"
self.conn.execute(
f"""
INSERT OR IGNORE INTO {self.table_name}_gene (identifier, phenopacket, gene_symbol, gene_identifier)
INSERT OR IGNORE INTO "{self.table_name}_gene" (identifier, phenopacket, gene_symbol, gene_identifier)
VALUES (?, ?, ?, ?)
""",
(identifier, phenopacket_path.name, gene.gene_symbol, gene.gene_identifier),
Expand All @@ -166,7 +166,7 @@ def _insert_variants(self, phenopacket_path: Path, variants: List[GenomicVariant
)
self.conn.execute(
f"""
INSERT OR IGNORE INTO {self.table_name}_variant (identifier, phenopacket, chrom, pos, "ref", alt)
INSERT OR IGNORE INTO "{self.table_name}_variant" (identifier, phenopacket, chrom, pos, "ref", alt)
VALUES (?, ?, ?, ?, ?, ?)
""",
(
Expand All @@ -189,8 +189,8 @@ def _insert_diseases(self, phenopacket_path: Path, diseases: List[ProbandDisease
for disease in diseases:
identifier = f"{phenopacket_path.name}-{disease.disease_identifier}"
self.conn.execute(
f"INSERT OR IGNORE INTO {self.table_name}_disease "
f"(identifier, phenopacket, disease_identifier, disease_name) VALUES (?, ?, ?, ?)",
f"""INSERT OR IGNORE INTO "{self.table_name}_disease" """
f"""(identifier, phenopacket, disease_identifier, disease_name) VALUES (?, ?, ?, ?)""",
(
identifier,
phenopacket_path.name,
Expand Down
6 changes: 3 additions & 3 deletions src/pheval/analyse/rank_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _execute_count_query(
Returns:
int: Count query result.
"""
query = f'SELECT COUNT(*) FROM {table_name} WHERE "{column_name}" {condition}'
query = f'SELECT COUNT(*) FROM "{table_name}" WHERE "{column_name}" {condition}'
return conn.execute(query).fetchone()[0]

@staticmethod
Expand All @@ -85,7 +85,7 @@ def _fetch_reciprocal_ranks(
Returns:
List[float]: List of reciprocal ranks.
"""
query = f'SELECT "{column_name}" FROM {table_name}'
query = f'SELECT "{column_name}" FROM "{table_name}"'
return [1 / rank[0] if rank[0] > 0 else 0 for rank in conn.execute(query).fetchall()]

@staticmethod
Expand All @@ -103,7 +103,7 @@ def _fetch_relevant_ranks(
List[List[int]]: List of relevant ranks.
"""
query = (
f'SELECT LIST("{column_name}") as values_list FROM {table_name} GROUP BY phenopacket'
f'SELECT LIST("{column_name}") as values_list FROM "{table_name}" GROUP BY phenopacket'
)
return [rank[0] for rank in conn.execute(query).fetchall()]

Expand Down
4 changes: 2 additions & 2 deletions src/pheval/analyse/variant_prioritisation_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def assess_variant_prioritisation(
"""
relevant_ranks = []
df = self.conn.execute(
f"""SELECT * FROM {self.table_name} WHERE phenopacket = '{phenopacket_path.name}'"""
f"""SELECT * FROM "{self.table_name}" WHERE phenopacket = '{phenopacket_path.name}'"""
).fetchdf()
for _i, row in df.iterrows():
causative_variant = GenomicVariant(
Expand Down Expand Up @@ -67,7 +67,7 @@ def assess_variant_prioritisation(
f"{causative_variant.ref}-{causative_variant.alt}"
)
self.conn.execute(
f'UPDATE {self.table_name} SET "{self.column}" = ? WHERE identifier = ?',
f'UPDATE "{self.table_name}" SET "{self.column}" = ? WHERE identifier = ?',
(variant_match, primary_key),
)
elif len(result) == 0:
Expand Down

0 comments on commit d2aeac0

Please sign in to comment.