Skip to content

Commit 128fb94

Browse files
committed
Linting...
1 parent bedbddf commit 128fb94

21 files changed

+562
-650
lines changed

api/Archive/analyze_efp_schemas.py

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,21 @@
2020

2121
# Extra columns that some databases have (we want to know which ones)
2222
EXTRA_COLUMNS = {
23-
"channel", "data_call", "data_num", "data_p_val", "data_p_value",
24-
"genome", "genome_id", "log", "orthogroup", "p_val", "project_id",
25-
"qvalue", "sample_file_name", "sample_tissue", "version",
23+
"channel",
24+
"data_call",
25+
"data_num",
26+
"data_p_val",
27+
"data_p_value",
28+
"genome",
29+
"genome_id",
30+
"log",
31+
"orthogroup",
32+
"p_val",
33+
"project_id",
34+
"qvalue",
35+
"sample_file_name",
36+
"sample_tissue",
37+
"version",
2638
}
2739

2840

@@ -94,7 +106,9 @@ def main():
94106

95107
# ---- 2. Group databases by their 3-column signature ----
96108
print("\n" + "=" * 80)
97-
print("GROUPING BY SIGNATURE (probeset_type, probeset_nullable, signal_nullable, signal_default, bot_type, bot_nullable)")
109+
print(
110+
"GROUPING BY SIGNATURE (probeset_type, probeset_nullable, signal_nullable, signal_default, bot_type, bot_nullable)"
111+
)
98112
print("=" * 80)
99113

100114
sig_groups = defaultdict(list)
@@ -103,7 +117,9 @@ def main():
103117
sig_groups[sig].append(db)
104118

105119
for sig, dbs in sorted(sig_groups.items(), key=lambda x: -len(x[1])):
106-
print(f"\n Signature: probeset={sig[0]}(nullable={sig[1]}) signal(nullable={sig[2]}, default={sig[3]}) bot={sig[4]}(nullable={sig[5]})")
120+
print(
121+
f"\n Signature: probeset={sig[0]}(nullable={sig[1]}) signal(nullable={sig[2]}, default={sig[3]}) bot={sig[4]}(nullable={sig[5]})"
122+
)
107123
print(f" Count: {len(dbs)}")
108124
print(f" DBs: {', '.join(dbs[:10])}{'...' if len(dbs) > 10 else ''}")
109125

@@ -135,15 +151,17 @@ def main():
135151
# Determine extra columns this DB needs
136152
extras = set(cols.keys()) - NEEDED_COLUMNS - {"proj_id", "sample_id"}
137153

138-
compact_entries.append({
139-
"db": db,
140-
"probeset_len": probeset_len, # None = tinytext
141-
"probeset_type": probeset_type,
142-
"bot_len": bot_len, # None = tinytext
143-
"bot_type": bot_type,
144-
"signal_nullable": signal_nullable,
145-
"extras": extras,
146-
})
154+
compact_entries.append(
155+
{
156+
"db": db,
157+
"probeset_len": probeset_len, # None = tinytext
158+
"probeset_type": probeset_type,
159+
"bot_len": bot_len, # None = tinytext
160+
"bot_type": bot_type,
161+
"signal_nullable": signal_nullable,
162+
"extras": extras,
163+
}
164+
)
147165

148166
# ---- 4. Show the most compact table-driven representation ----
149167
print("\n" + "=" * 80)
@@ -180,9 +198,7 @@ def main():
180198
for e in compact_entries:
181199
# Filter out databases that ONLY have unneeded extras
182200
# (sample_file_name, data_call, data_p_val etc. are not needed)
183-
has_important_extras = e["extras"] - {
184-
"sample_file_name", "data_call", "data_p_val", "data_p_value", "data_num"
185-
}
201+
has_important_extras = e["extras"] - {"sample_file_name", "data_call", "data_p_val", "data_p_value", "data_num"}
186202
if has_important_extras:
187203
complex_dbs.append(e)
188204
else:
@@ -217,11 +233,13 @@ def main():
217233
with open(SAMPLE_DATA_CSV, newline="") as f:
218234
reader = csv.DictReader(f)
219235
for row in reader:
220-
db_samples[row["source_database"]].append({
221-
"data_bot_id": row["data_bot_id"],
222-
"data_probeset_id": row["data_probeset_id"],
223-
"data_signal": row["data_signal"],
224-
})
236+
db_samples[row["source_database"]].append(
237+
{
238+
"data_bot_id": row["data_bot_id"],
239+
"data_probeset_id": row["data_probeset_id"],
240+
"data_signal": row["data_signal"],
241+
}
242+
)
225243

226244
print(f"Total databases with sample data: {len(db_samples)}")
227245
print(f"Total sample rows: {sum(len(v) for v in db_samples.values())}")

api/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def create_app():
4242
mysql_efp_base = bar_app.config.get("MYSQL_EFP_BASE_URI")
4343
if mysql_efp_base:
4444
from api.models.efp_schemas import SIMPLE_EFP_DATABASE_SCHEMAS
45+
4546
binds = bar_app.config.get("SQLALCHEMY_BINDS") or {}
4647
base = mysql_efp_base.rstrip("/")
4748
for db_name in SIMPLE_EFP_DATABASE_SCHEMAS:
@@ -70,9 +71,9 @@ def create_app():
7071
# On BAR, MySQL binds come from the server config — never build SQLite mirrors there.
7172
# For CI and local dev, determine whether to build SQLite mirrors.
7273
needs_sqlite_mirrors = (
73-
is_ci # always build on CI
74-
or bar_app.config.get("TESTING") # config requests test mode
75-
or "pytest" in os.sys.modules # running under pytest
74+
is_ci # always build on CI
75+
or bar_app.config.get("TESTING") # config requests test mode
76+
or "pytest" in os.sys.modules # running under pytest
7677
or os.environ.get("BAR_API_AUTO_SQLITE_MIRRORS") == "1" # explicit override
7778
)
7879

api/models/bar_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Bridge file to maintain backward compatibility with imports
22
from api.utils.bar_utils import BARUtils
33

4-
__all__ = ['BARUtils']
4+
__all__ = ["BARUtils"]

api/resources/fastpheno.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from api.utils.bar_utils import BARUtils
1414
from markupsafe import escape
1515

16-
1716
fastpheno = Namespace("FastPheno", description="FastPheno API service", path="/fastpheno")
1817

1918

@@ -240,9 +239,7 @@ def get(self, tree_site_id, band):
240239
class FastPhenoSites(Resource):
241240
def get(self):
242241
"""Returns all sites with coordinates, for initializing the map view."""
243-
rows = db.session.execute(
244-
db.select(Sites).order_by(Sites.site_name)
245-
).scalars().all()
242+
rows = db.session.execute(db.select(Sites).order_by(Sites.site_name)).scalars().all()
246243

247244
res = [
248245
{
@@ -266,11 +263,11 @@ def get(self, sites_pk):
266263
if not BARUtils.is_integer(str(sites_pk)):
267264
return BARUtils.error_exit("Invalid sites_pk"), 400
268265

269-
rows = db.session.execute(
270-
db.select(Flights)
271-
.where(Flights.sites_pk == sites_pk)
272-
.order_by(Flights.flight_date)
273-
).scalars().all()
266+
rows = (
267+
db.session.execute(db.select(Flights).where(Flights.sites_pk == sites_pk).order_by(Flights.flight_date))
268+
.scalars()
269+
.all()
270+
)
274271

275272
if len(rows) == 0:
276273
return BARUtils.error_exit("No flights found for the given site"), 400
@@ -297,12 +294,16 @@ def get(self, flights_pk):
297294
if not BARUtils.is_integer(str(flights_pk)):
298295
return BARUtils.error_exit("Invalid flights_pk"), 400
299296

300-
rows = db.session.execute(
301-
db.select(Bands.band)
302-
.where(Bands.flights_pk == flights_pk)
303-
.distinct()
304-
.order_by(db.func.cast(db.func.regexp_replace(Bands.band, "[^0-9]", ""), db.Integer))
305-
).scalars().all()
297+
rows = (
298+
db.session.execute(
299+
db.select(Bands.band)
300+
.where(Bands.flights_pk == flights_pk)
301+
.distinct()
302+
.order_by(db.func.cast(db.func.regexp_replace(Bands.band, "[^0-9]", ""), db.Integer))
303+
)
304+
.scalars()
305+
.all()
306+
)
306307

307308
if len(rows) == 0:
308309
return BARUtils.error_exit("No bands found for the given flight"), 400

api/resources/gene_expression.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414
)
1515

1616
gene_expression = Namespace(
17-
'Gene Expression',
18-
description='Gene expression data from BAR eFP databases',
19-
path='/gene_expression',
17+
"Gene Expression",
18+
description="Gene expression data from BAR eFP databases",
19+
path="/gene_expression",
2020
)
2121

2222

2323
@gene_expression.route("/expression/<string:database>/<string:gene_id>")
24-
@gene_expression.doc(
25-
description="Retrieve gene expression values from a specified eFP database."
26-
)
24+
@gene_expression.doc(description="Retrieve gene expression values from a specified eFP database.")
2725
@gene_expression.param(
2826
"gene_id",
2927
"Gene ID (e.g. AT1G01010 for Arabidopsis, or a probeset like 261585_at)",
@@ -76,4 +74,4 @@ def get(self, database, gene_id):
7674
return BARUtils.error_exit(result["error"]), result.get("error_code", 500)
7775

7876

79-
gene_expression.add_resource(GeneExpression, '/expression/<string:database>/<string:gene_id>')
77+
gene_expression.add_resource(GeneExpression, "/expression/<string:database>/<string:gene_id>")

api/resources/gene_information.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from api import db
1616
from sqlalchemy import func
1717

18-
1918
gene_information = Namespace("Gene Information", description="Information about Genes", path="/gene_information")
2019

2120
parser = gene_information.parser()
@@ -91,9 +90,9 @@ def post(self):
9190

9291
# Query must be run individually for each species
9392
lowered_genes = [gene.lower() for gene in genes]
94-
rows = db.session.execute(
95-
db.select(database).where(func.lower(database.agi).in_(lowered_genes))
96-
).scalars().all()
93+
rows = (
94+
db.session.execute(db.select(database).where(func.lower(database.agi).in_(lowered_genes))).scalars().all()
95+
)
9796

9897
# If there are any isoforms found, return data
9998
data = []
@@ -286,9 +285,9 @@ def post(self):
286285
gene_ids = []
287286
gene_fail = []
288287
for one_term in terms:
289-
query = db.select(alias_database.agi).where(
290-
func.lower(alias_database.agi).contains(one_term.lower())
291-
).limit(1)
288+
query = (
289+
db.select(alias_database.agi).where(func.lower(alias_database.agi).contains(one_term.lower())).limit(1)
290+
)
292291
result = db.session.execute(query).fetchone()
293292
if result is not None:
294293
gene_ids.append(result[0])

api/resources/interactions.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def get(self, tag=""):
474474
"image_url": ex.image_url,
475475
"grn_title": ex.grn_title,
476476
"cyjs_layout": _normalize_cyjs_layout(ex.cyjs_layout),
477-
"tag": "|".join(_sort_tag_strings(src_tag_match[ex.source_id]))
477+
"tag": "|".join(_sort_tag_strings(src_tag_match[ex.source_id])),
478478
}
479479
result.append(one_source[source_id])
480480

@@ -544,7 +544,7 @@ def get(self, number=""):
544544
"url": row.url,
545545
"image_url": row.image_url,
546546
"grn_title": row.grn_title,
547-
"cyjs_layout": _normalize_cyjs_layout(row.cyjs_layout)
547+
"cyjs_layout": _normalize_cyjs_layout(row.cyjs_layout),
548548
}
549549
)
550550

@@ -607,20 +607,14 @@ def get(self, stringAGI=""):
607607
"source_name": row.source_name,
608608
"comments": row.comments,
609609
"cyjs_layout": _normalize_cyjs_layout(row.cyjs_layout),
610-
"tags": []
610+
"tags": [],
611611
}
612612

613613
tag_entry = f"{row.tag_name}:{row.tag_group}"
614614
if tag_entry not in result_dict[source_id]["tags"]: # DISTINCT
615615
result_dict[source_id]["tags"].append(tag_entry)
616616

617-
result = [
618-
{
619-
**data,
620-
"tags": "|".join(_sort_tag_strings(data["tags"]))
621-
}
622-
for data in result_dict.values()
623-
]
617+
result = [{**data, "tags": "|".join(_sort_tag_strings(data["tags"]))} for data in result_dict.values()]
624618
result.sort(key=lambda item: (item["grn_title"] or ""))
625619

626620
if len(result) == 0:
@@ -681,18 +675,15 @@ def get(self, AGI_1="", AGI_2=""):
681675
"source_name": row.source_name,
682676
"comments": row.comments,
683677
"cyjs_layout": _normalize_cyjs_layout(row.cyjs_layout),
684-
"tags": []
678+
"tags": [],
685679
}
686680

687681
tag_entry = f"{row.tag_name}:{row.tag_group}"
688682
if tag_entry not in result_dict[source_id]["tags"]:
689683
result_dict[source_id]["tags"].append(tag_entry)
690684

691685
result = [
692-
{
693-
**data,
694-
"tags": "|".join(_sort_tag_strings_natural_case_sensitive(data["tags"]))
695-
}
686+
{**data, "tags": "|".join(_sort_tag_strings_natural_case_sensitive(data["tags"]))}
696687
for data in result_dict.values()
697688
]
698689
result.sort(key=lambda item: item["source_id"])
@@ -746,7 +737,7 @@ def get(self):
746737
"image_url": ex.image_url,
747738
"grn_title": ex.grn_title,
748739
"cyjs_layout": _normalize_cyjs_layout(ex.cyjs_layout),
749-
"tag": "|".join(_sort_tag_strings(src_tag_match[ex.source_id]))
740+
"tag": "|".join(_sort_tag_strings(src_tag_match[ex.source_id])),
750741
}
751742
result.append(one_source[source_id])
752743

api/resources/llama3.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from api import db
1111
from api.models.llama3 import Summaries
1212

13-
1413
llama3 = Namespace("LLaMA", description="Endpoint for retreiving LLaMA3 results", path="/LLaMA")
1514

1615

0 commit comments

Comments
 (0)