Skip to content

Commit 009b350

Browse files
committed
update autoapi docs
1 parent 915dae6 commit 009b350

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

pgscatalog.calclib/src/pgscatalog/calclib/ancestry/tools.py pgscatalog.calclib/src/pgscatalog/calclib/_ancestry/tools.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ def pgs_adjust(
280280
:param norm2_2step: boolean (default=False) whether to use the two-step model vs. the full-fit
281281
:param ref_train_col: column name with true/false labels of samples that should be included in training PGS methods
282282
:param n_pcs: number of genetic PCs that will be used for PGS-adjustment
283-
:return: [results_ref:df , results_target:df , results_models: dict] adjusted dfs for reference and target
284-
populations, and a dictionary with model fit/parameters.
283+
:return: [results_ref:df , results_target:df , results_models: dict] adjusted dfs for reference and target populations, and a dictionary with model fit/parameters.
285284
"""
286285
# Check that datasets have the correct columns
287286
## Check that score is in both dfs

pgscatalog.calclib/src/pgscatalog/calclib/polygenicscore.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
import pandas as pd
88

9-
from .ancestry.tools import (
9+
from ._ancestry.tools import (
1010
compare_ancestry,
1111
choose_pval_threshold,
1212
pgs_adjust,
1313
write_model,
1414
)
1515
from .principalcomponents import PopulationType
16-
from .ancestry import read
16+
from ._ancestry import read
1717

1818

1919
logger = logging.getLogger(__name__)
@@ -41,7 +41,7 @@ def __post_init__(self):
4141

4242
@dataclasses.dataclass(frozen=True)
4343
class AdjustResults:
44-
"""Results returned by the adjust method of a PolygenicScore"""
44+
"""Results returned by :class:`AggregatedPGS.adjust()`"""
4545

4646
target_label: str
4747
models: pd.DataFrame
@@ -51,6 +51,7 @@ class AdjustResults:
5151
scorecols: list[str]
5252

5353
def write(self, directory):
54+
"""Write model, PGS, and PCA data to a directory"""
5455
self._write_model(directory)
5556
self._write_pgs(directory)
5657
self._write_pca(directory)
@@ -105,7 +106,9 @@ def _write_pgs(self, directory):
105106

106107

107108
class AggregatedPGS:
108-
"""A PGS that's been aggregated and melted, and may contain a reference panel and a target set
109+
"""A PGS that's been aggregated, melted, and probably contains samples from a reference panel and a target population.
110+
111+
The most useful method in this class adjusts PGS based on :func:`genetic ancestry similarity estimation <pgscatalog.calclib.AggregatedPGS.adjust>`.
109112
110113
>>> from ._config import Config
111114
>>> score_path = Config.ROOT_DIR / "tests" / "aggregated_scores.txt.gz"
@@ -156,9 +159,9 @@ def _check_overlap(self, ref_pc, target_pc):
156159
raise ValueError
157160

158161
def adjust(self, *, ref_pc, target_pc, adjust_arguments=None):
159-
"""Adjust a PGS based on genetic ancestry similarity.
162+
"""Adjust a PGS based on genetic ancestry similarity estimations.
160163
161-
Adjusting a PGS returns AdjustResults:
164+
:returns: :class:`AdjustResults`
162165
163166
>>> from ._config import Config
164167
>>> from .principalcomponents import PrincipalComponents
@@ -255,7 +258,7 @@ def adjust(self, *, ref_pc, target_pc, adjust_arguments=None):
255258

256259

257260
class PolygenicScore:
258-
"""Represents the output of plink2 --score written to a file
261+
"""Represents the output of ``plink2 --score`` written to a file
259262
260263
>>> from ._config import Config
261264
>>> import reprlib
@@ -340,6 +343,7 @@ def __add__(self, other):
340343

341344
@property
342345
def df(self):
346+
"""A generator that yields dataframe chunks."""
343347
if self.path is not None:
344348
self._df = self.lazy_read()
345349
elif self._bigdf is not None:

pgscatalog.calclib/src/pgscatalog/calclib/principalcomponents.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
import itertools
33
import logging
44

5-
from .ancestry import read
5+
from ._ancestry import read
66

77
logger = logging.getLogger(__name__)
88

99

1010
class PopulationType(enum.Enum):
11+
"""PGS can be calculated on a reference panel or target population.
12+
13+
This enum mostly helps to disambiguate instances of :class:`PrincipalComponents`."""
14+
1115
TARGET = "target"
1216
REFERENCE = "reference"
1317

1418

1519
class PrincipalComponents:
1620
"""
17-
This class represents principal components data calculated by fraposa-pgsc
21+
This class represents principal components analysis (PCA) data calculated by ``fraposa-pgsc``.
22+
23+
PCA data may come from a reference population or a target population. Target populations have been projected onto the reference population.
1824
1925
>>> from ._config import Config
2026
>>> related_path = Config.ROOT_DIR / "tests" / "ref.king.cutoff.id"
@@ -24,7 +30,6 @@ class PrincipalComponents:
2430
PrincipalComponents(dataset='reference', pop_type=PopulationType.REFERENCE, pcs_path=[PosixPath('.../pgscatalog.calclib/tests/ref.pcs')], psam_path=PosixPath('.../pgscatalog.calclib/tests/ref.psam'))
2531
>>> ref_pc.df.to_dict()
2632
{'PC1': {('reference', 'HG00096'): -23.8212, ('reference', 'HG00097'): -24.8106, ...
27-
2833
>>> target_pcs = PrincipalComponents(pcs_path=Config.ROOT_DIR / "tests" / "target.pcs", dataset="target", pop_type=PopulationType.TARGET)
2934
>>> target_pcs
3035
PrincipalComponents(dataset='target', pop_type=PopulationType.TARGET, pcs_path=[PosixPath('.../pgscatalog.calclib/tests/target.pcs')], psam_path=None)
@@ -65,18 +70,25 @@ def __repr__(self):
6570

6671
@property
6772
def pop_type(self):
73+
"""See :class:`PopulationType`"""
6874
return self._pop_type
6975

7076
@property
7177
def psam_path(self):
78+
"""Path to a plink2 sample information file for the reference population"""
7279
return self._psam_path
7380

7481
@property
7582
def related_path(self):
83+
"""Path to a plink2 kinship cutoff file
84+
85+
Related reference samples are removed from analysis
86+
"""
7687
return self._related_path
7788

7889
@property
7990
def poplabel(self):
91+
"""The group label used to assign target samples that are similar to reference population groups, e.g. SAS/EUR/AFR"""
8092
return self._poplabel
8193

8294
@property
@@ -98,7 +110,7 @@ def npcs_popcomp(self, value):
98110

99111
@property
100112
def npcs_norm(self):
101-
"""Number of PCs used for population NORMALIZATION (default = 4)"""
113+
"""Number of PCs used for population normalization (default = 4)"""
102114
return self._npcs_norm
103115

104116
@npcs_norm.setter
@@ -110,6 +122,12 @@ def npcs_norm(self, value):
110122

111123
@property
112124
def df(self):
125+
"""A pandas dataframe that contains PCA data.
126+
127+
Reference data also contains population label columns loaded from sample information files.
128+
129+
:raises ValueError: If the reference population consists of fewer than 100 samples
130+
"""
113131
if self._df is None:
114132
df = read.read_pcs(
115133
loc_pcs=self.pcs_path,

0 commit comments

Comments
 (0)