Add type annotations for public APIs and CLI entrypoints#207
Open
FuqingZh wants to merge 1 commit intobroadinstitute:masterfrom
Open
Add type annotations for public APIs and CLI entrypoints#207FuqingZh wants to merge 1 commit intobroadinstitute:masterfrom
FuqingZh wants to merge 1 commit intobroadinstitute:masterfrom
Conversation
There was a problem hiding this comment.
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 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( |
| genotypes_t = genotypes_t[:,genotype_ix_t] | ||
| print( | ||
| f"\rCalculating aFC for {group.replace('_id', '')} {k}/{n}", | ||
| end="" if k != n else None, |
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 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." | ||
| ) |
| 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 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]}.", "")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
core.py,post.py,pgen.py,genotypeio.py, andtensorqtl.pyValidation
Checked locally with import/CLI and lightweight smoke tests covering:
import tensorqtlpython -m tensorqtl --helpread_phenotype_bed(...)PgenReader(...)and genotype loading paths