Skip to content
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
41 changes: 41 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: test

on: [push,pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

- name: Clear conda cache
run: conda clean --all -y

- name: Conda setup
uses: conda-incubator/setup-miniconda@v4
with:
activate-environment: tdbsumstat
environment-file: base_environment.yml
auto-update-conda: true
auto-activate-base: false
python-version: ${{ matrix.python-version }}
miniforge-version: latest

- name: Install project
shell: bash -el {0}
run: |
make dependencies
make install

- name: Run test
shell: bash -el {0}
run: |
make test-unit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/*
work/
results/
.nextflow*
.coverage
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ clean:
find . -type d -name '__pycache__' -exec rm -rf {} +
rm -rf dist build

test-all:
pytest --cov=tdbsumstat --cov-report=term-missing

test-unit:
pytest tests/unit

dependencies:
poetry install --no-root

Expand Down
16 changes: 0 additions & 16 deletions run_ingestion_pkgh.sh

This file was deleted.

1 change: 0 additions & 1 deletion tdbsumstat/utils/harmonize_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __init__(self, mapping_file: str, uri: str, type_sumstat: str, pvar_file: st
self.mac = mac
self.maf = maf
self.permuted = permuted
print(self.permuted)

def create_mapping(self):
df = pd.read_csv(self.mapping_file, header=None, names=["key", "value"])
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions tests/unit/core/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest
import pandas as pd
from tdbsumstat.utils.harmonize_ingest import Harmonize

@pytest.fixture
def create_df_sumstat():
ensg00 = pd.read_csv('tests/data/dummy_out_ENSG0000010001.tsv.gz', sep = '\t')
return ensg00

@pytest.fixture
def create_harmonized_obj(tmp_path):
obj = Harmonize(
mapping_file= 'tests/data/mapping_file_test.csv',
uri = str(tmp_path / "test_tiledb_array"),
type_sumstat = "qtl",
pvar_file = str(tmp_path / "temp_pvar.pvar"),
type_trait = 'quant',
permuted = False,
mac = 10,
maf = 0.001,
)
return obj

@pytest.fixture
def create_pvar(tmp_path):
# Added list brackets to ensure pandas creates rows correctly
pvar = pd.DataFrame({
"CHROM": ["1"],
"POS": ["1234"],
"SNPID": ["1:1234:A:G"],
"REF": ["A"],
"ALT": ["G"]
})

# CRITICAL: index=False prevents pandas from writing a row-number column
pvar_path = f"{tmp_path}/temp_pvar.pvar"
pvar.to_csv(pvar_path, sep='\t', index=False)

return pvar_path
40 changes: 40 additions & 0 deletions tests/unit/core/test_ingestion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import polars as pl
from tdbsumstat.utils.harmonize_ingest import Harmonize

def test_create_mapping(create_harmonized_obj):
# 1. Execute the method
create_harmonized_obj.create_mapping()
# 2. Check the attribute on the object
assert create_harmonized_obj.mapping_types == {
"Chr": "CHR",
"Gene": "GENE",
"cell.type": "CELL",
"pos": "POS",
"a0": "A1",
"a1": "A2",
"p": "P",
"N": "N",
"beta": "BETA",
"se": "SE",
}

def test_create_tiledb(create_harmonized_obj, tmp_path):
create_harmonized_obj.create_tiledb()
# 2. Check the attribute on the object
assert os.path.exists(f'{tmp_path}/test_tiledb_array')

def test_align_alleles(create_harmonized_obj, create_pvar):
create_harmonized_obj.chunk_pl = pl.DataFrame({
"CHR": 1,
"POS": 1234,
"SNPID": "1:1234:A:G",
"BETA": -0.1,
"SE": 0.01,
"EAF": 0.3
})
create_harmonized_obj.align_alleles()
result_df = create_harmonized_obj.chunk_pl
assert result_df.select("BETA").item() == 0.1
assert result_df.select("EAF").item() == 0.7

Loading