Skip to content

Add type annotations for public APIs and CLI entrypoints#207

Open
FuqingZh wants to merge 1 commit intobroadinstitute:masterfrom
FuqingZh:master
Open

Add type annotations for public APIs and CLI entrypoints#207
FuqingZh wants to merge 1 commit intobroadinstitute:masterfrom
FuqingZh:master

Conversation

@FuqingZh
Copy link
Copy Markdown

Summary

This PR adds type annotations to public APIs and CLI-facing entrypoints, and includes a few low-risk cleanups surfaced during the process.

Changes

  • add type annotations in core.py, post.py, pgen.py, genotypeio.py, and tensorqtl.py
  • replace selected star imports with explicit imports in CLI and post-processing entrypoints
  • fix a few small typing-related issues without changing algorithms or output formats

Validation

Checked locally with import/CLI and lightweight smoke tests covering:

  • import tensorqtl
  • python -m tensorqtl --help
  • read_phenotype_bed(...)
  • PgenReader(...) and genotype loading paths

Copilot AI review requested due to automatic review settings April 16, 2026 06:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds/cleans up Python type annotations across tensorQTL’s public modules and CLI entrypoint, while also replacing star imports with explicit imports to make the API surface clearer and more type-checker-friendly.

Changes:

  • Added type annotations and refined function signatures in core utilities, genotype I/O, PLINK2 pgen reader utilities, and post-processing helpers.
  • Updated CLI entrypoint imports to avoid import * and make dependencies explicit.
  • Minor refactors/formatting changes surfaced during typing work (e.g., more explicit conversions, stronger assertions).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tensorqtl/tensorqtl.py Refactors CLI entrypoint to explicit imports and typed main(), plus chunked-output handling changes.
tensorqtl/post.py Adds type hints and explicit core imports for post-processing utilities (q-values, aFC, replication, annotations).
tensorqtl/pgen.py Adds type hints and refactors sample/variant selection logic in the PLINK2 pgen reader wrapper.
tensorqtl/genotypeio.py Adds type hints and small refactors in genotype loading and chunking utilities.
tensorqtl/core.py Adds type hints and refines R/rpy2 capability detection and core math helper signatures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tensorqtl/tensorqtl.py
Comment on lines +93 to +97
"--logp",
action="store_true",
help="Compute nominal p-values as -log10(P) for added precision (requires R)",
)
parser.add_argument(
Comment thread tensorqtl/post.py
genotypes_t = genotypes_t[:,genotype_ix_t]
print(
f"\rCalculating aFC for {group.replace('_id', '')} {k}/{n}",
end="" if k != n else None,
Comment thread tensorqtl/post.py
Comment on lines 164 to +165
except:
print(f'WARNING: aFC calculation failed for {phenotype_id}')
print(f"WARNING: aFC calculation failed for {phenotype_id}")
Comment thread tensorqtl/core.py
Comment on lines 15 to +35
# check R
has_rpy2 = False
rfunc = None
try:
subprocess.check_call('which R', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.check_call("R -e 'library(qvalue)'", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
import rpy2
subprocess.check_call(
"which R", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
subprocess.check_call(
"R -e 'library(qvalue)'",
shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
import rfunc
import rpy2

has_rpy2 = True
except:
print("Warning: 'rfunc' cannot be imported. R with the 'qvalue' library and the 'rpy2' Python package are needed to compute q-values.")
print(
"Warning: 'rfunc' cannot be imported. R with the 'qvalue' library and the 'rpy2' Python package are needed to compute q-values."
)
Comment thread tensorqtl/tensorqtl.py
for chrom, chr_df in chunk_df.groupby("chr", sort=False):
print(
f"\rConcatenating outputs for {chrom}",
end="" if chrom != chunk_df["chr"].iloc[-1] else None,
Comment thread tensorqtl/tensorqtl.py
Comment on lines 459 to 462
for f in chunk_files:
x = re.findall(f"{args.prefix}\.(chunk\d+)", os.path.basename(f))
x = re.findall(rf"{args.prefix}\.(chunk\d+)", os.path.basename(f))
assert len(x) == 1
os.rename(f, f.replace(f"{x[0]}.", ""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants