Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(study_index): change numeric columns from long to integers #371

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/otg/assets/schemas/study_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@
},
{
"name": "nCases",
"type": "long",
"type": "integer",
"nullable": true,
"metadata": {}
},
{
"name": "nControls",
"type": "long",
"type": "integer",
"nullable": true,
"metadata": {}
},
{
"name": "nSamples",
"type": "long",
"type": "integer",
"nullable": true,
"metadata": {}
},
Expand Down Expand Up @@ -150,7 +150,7 @@
"fields": [
{
"name": "sampleSize",
"type": "long",
"type": "integer",
"nullable": true,
"metadata": {}
},
Expand All @@ -176,7 +176,7 @@
"fields": [
{
"name": "sampleSize",
"type": "long",
"type": "integer",
"nullable": true,
"metadata": {}
},
Expand Down
10 changes: 5 additions & 5 deletions src/otg/datasource/eqtl_catalogue/study_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ def _all_attributes() -> List[Column]:
).alias("traitFromSourceMappedIds"),
]
sample_attributes = [
f.lit(838).cast("long").alias("nSamples"),
f.lit(838).cast("integer").alias("nSamples"),
f.lit("838 (281 females and 557 males)").alias("initialSampleSize"),
f.array(
f.struct(
f.lit(715).cast("long").alias("sampleSize"),
f.lit(715).cast("integer").alias("sampleSize"),
f.lit("European American").alias("ancestry"),
),
f.struct(
f.lit(103).cast("long").alias("sampleSize"),
f.lit(103).cast("integer").alias("sampleSize"),
f.lit("African American").alias("ancestry"),
),
f.struct(
f.lit(12).cast("long").alias("sampleSize"),
f.lit(12).cast("integer").alias("sampleSize"),
f.lit("Asian American").alias("ancestry"),
),
f.struct(
f.lit(16).cast("long").alias("sampleSize"),
f.lit(16).cast("integer").alias("sampleSize"),
f.lit("Hispanic or Latino").alias("ancestry"),
),
).alias("discoverySamples"),
Expand Down
10 changes: 6 additions & 4 deletions src/otg/datasource/finngen/study_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ def from_source(
f.lit(f"{cls.finngen_release_prefix}_"), f.col("phenocode")
).alias("studyId"),
f.col("phenostring").alias("traitFromSource"),
f.col("num_cases").alias("nCases"),
f.col("num_controls").alias("nControls"),
(f.col("num_cases") + f.col("num_controls")).alias("nSamples"),
f.col("num_cases").cast("integer").alias("nCases"),
f.col("num_controls").cast("integer").alias("nControls"),
(f.col("num_cases") + f.col("num_controls"))
.cast("integer")
.alias("nSamples"),
f.lit(cls.finngen_release_prefix).alias("projectId"),
f.lit("gwas").alias("studyType"),
f.lit(True).alias("hasSumstats"),
Expand All @@ -62,7 +64,7 @@ def from_source(
),
f.array(
f.struct(
f.lit(377277).cast("long").alias("sampleSize"),
f.lit(377277).cast("integer").alias("sampleSize"),
f.lit("Finnish").alias("ancestry"),
)
).alias("discoverySamples"),
Expand Down
14 changes: 7 additions & 7 deletions src/otg/datasource/gwas_catalog/study_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _parse_discovery_samples(discovery_samples: Column) -> Column:
+--------------------------------------------+
<BLANKLINE>
"""
# To initialize return objects for aggregate functions, schema has to be definied:
# To initialize return objects for aggregate functions, schema has to be defined:
schema = t.ArrayType(
t.StructType(
[
Expand All @@ -96,7 +96,7 @@ def _parse_discovery_samples(discovery_samples: Column) -> Column:
),
lambda ancestry: f.struct(
ancestry.alias("ancestry"),
f.lit(0).cast(t.LongType()).alias("sampleSize"),
f.lit(0).alias("sampleSize"),
),
)

Expand Down Expand Up @@ -155,7 +155,7 @@ def _normalize_ancestries(merged: Column, ancestry: Column) -> Column:
f.struct(
a.ancestry.alias("ancestry"),
(a.sampleSize + ancestry.sampleSize)
.cast(t.LongType())
.cast(t.IntegerType())
.alias("sampleSize"),
),
).otherwise(a),
Expand Down Expand Up @@ -387,7 +387,7 @@ def annotate_ancestries(
f.struct(
f.col("broadAncestralCategory").alias("ancestry"),
f.col("numberOfIndividuals")
.cast(t.LongType())
.cast(t.IntegerType())
.alias("sampleSize"),
)
)
Expand Down Expand Up @@ -543,9 +543,9 @@ def annotate_discovery_sample_sizes(
# Aggregating sample sizes for all ancestries:
.groupBy("studyId") # studyId has not been split yet
.agg(
f.sum("nCases").alias("nCases"),
f.sum("nControls").alias("nControls"),
f.sum("sampleSize").alias("nSamples"),
f.sum("nCases").cast("integer").alias("nCases"),
f.sum("nControls").cast("integer").alias("nControls"),
f.sum("sampleSize").cast("integer").alias("nSamples"),
)
)
self.df = self.df.join(sample_size_lut, on="studyId", how="left")
Expand Down
4 changes: 2 additions & 2 deletions src/otg/datasource/ukbiobank/study_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def from_source(
"publicationJournal"
),
f.col("n_total").cast("string").alias("initialSampleSize"),
f.col("n_cases").cast("long").alias("nCases"),
f.col("n_cases").cast("integer").alias("nCases"),
f.array(
f.struct(
f.col("n_total").cast("long").alias("sampleSize"),
f.col("n_total").cast("integer").alias("sampleSize"),
f.concat(f.lit("European="), f.col("n_total")).alias(
"ancestry"
),
Expand Down