Skip to content

Commit ad523d0

Browse files
committed
Doc changes for consistency across tskit-dev
1 parent 54a5ccb commit ad523d0

File tree

7 files changed

+476
-599
lines changed

7 files changed

+476
-599
lines changed

docs/_config.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,9 @@ html:
2222
use_repository_button: true
2323
use_edit_page_button: true
2424

25-
extra_footer: |
26-
<div>
27-
tstrait __TSTRAIT_VERSION__
28-
</div>
2925

3026
sphinx:
3127
extra_extensions:
32-
- numpydoc
3328
- sphinx_copybutton
3429
- sphinx_design
3530
- sphinx.ext.autodoc
@@ -38,9 +33,15 @@ sphinx:
3833
- sphinx.ext.viewcode
3934
- sphinx.ext.intersphinx
4035
- sphinx_issues
36+
- IPython.sphinxext.ipython_console_highlighting
4137

4238
config:
4339
html_theme: sphinx_book_theme
40+
html_theme_options:
41+
pygments_dark_style: monokai
42+
navigation_with_keys: false
43+
logo:
44+
text: "Version __TSTRAIT_VERSION__"
4445
myst_enable_extensions:
4546
- colon_fence
4647
- deflist

tstrait/genetic_value.py

Lines changed: 62 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ def _accumulate_individual_values(
4949
class _GeneticValue:
5050
"""GeneticValue class to compute genetic values of individuals.
5151
52-
Parameters
53-
----------
54-
ts : tskit.TreeSequence
55-
Tree sequence data with mutation
56-
trait_df : pandas.DataFrame
57-
Dataframe that includes causal site ID, causal allele, simulated effect
58-
size, and trait ID.
52+
:param ts: Tree sequence data with mutation
53+
:type ts: tskit.TreeSequence
54+
:param trait_df: Dataframe that includes causal site ID, causal allele,
55+
simulated effect size, and trait ID.
56+
:type trait_df: pandas.DataFrame
5957
"""
6058

6159
def __init__(self, ts, trait_df):
@@ -102,10 +100,8 @@ def _individual_genetic_values(self, tree, site, causal_allele, effect_size):
102100
def _run(self):
103101
"""Computes genetic values of individuals.
104102
105-
Returns
106-
-------
107-
pandas.DataFrame
108-
Dataframe with genetic value, individual ID, and trait ID.
103+
:returns: Dataframe with genetic value, individual ID, and trait ID.
104+
:rtype: pandas.DataFrame
109105
"""
110106

111107
num_ind = self.ts.num_individuals
@@ -139,56 +135,53 @@ def genetic_value(ts, trait_df):
139135
"""
140136
Obtains genetic value from a trait dataframe.
141137
142-
Parameters
143-
----------
144-
ts : tskit.TreeSequence
145-
The tree sequence data that will be used in the quantitative trait
138+
:param ts: The tree sequence data that will be used in the quantitative trait
146139
simulation.
147-
trait_df : pandas.DataFrame
148-
Trait dataframe.
149-
150-
Returns
151-
-------
152-
pandas.DataFrame
153-
Pandas dataframe that includes genetic value of individuals in the
140+
:type ts: tskit.TreeSequence
141+
:param trait_df: Trait dataframe.
142+
:type trait_df: pandas.DataFrame
143+
:returns: Pandas dataframe that includes genetic value of individuals in the
154144
tree sequence.
145+
:rtype: pandas.DataFrame
146+
147+
.. seealso::
148+
:func:`trait_model` Return a trait model, which can be used as `model` input.
149+
150+
:func:`sim_trait` Return a trait dataframe, which can be used as a
151+
`trait_df` input.
155152
156-
See Also
157-
--------
158-
trait_model : Return a trait model, which can be used as `model` input.
159-
sim_trait : Return a trait dataframe, whch can be used as a `trait_df` input.
160-
sim_env : Genetic value dataframe output can be used as an input to simulate
161-
environmental noise.
153+
:func:`sim_env` Genetic value dataframe output can be used as an input
154+
to simulate environmental noise.
162155
163-
Notes
164-
-----
165-
The `trait_df` input has some requirements that will be noted below.
156+
.. note::
157+
The `trait_df` input has some requirements that will be noted below.
166158
167-
1. Columns
159+
1. Columns
168160
169-
The following columns must be included in `trait_df`:
161+
The following columns must be included in `trait_df`:
170162
171-
* **site_id**: Site IDs that have causal allele.
172-
* **effect_size**: Simulated effect size of causal allele.
173-
* **causal_allele**: Causal allele.
174-
* **trait_id**: Trait ID.
163+
* **site_id**: Site IDs that have causal allele.
164+
* **effect_size**: Simulated effect size of causal allele.
165+
* **causal_allele**: Causal allele.
166+
* **trait_id**: Trait ID.
175167
176-
2. Data requirements
168+
2. Data requirements
177169
178-
* Site IDs in **site_id** column must be sorted in an ascending order. Please
179-
refer to :py:meth:`pandas.DataFrame.sort_values` for details on sorting
180-
values in a :class:`pandas.DataFrame`.
170+
* Site IDs in **site_id** column must be sorted in an ascending order. Please
171+
refer to :py:meth:`pandas.DataFrame.sort_values` for details on sorting
172+
values in a :class:`pandas.DataFrame`.
181173
182-
* Trait IDs in **trait_id** column must start from zero and be consecutive.
174+
* Trait IDs in **trait_id** column must start from zero and be consecutive.
183175
184-
The genetic value dataframe contains the following columns:
176+
The genetic value dataframe contains the following columns:
185177
186-
* **trait_id**: Trait ID.
187-
* **individual_id**: Individual ID inside the tree sequence input.
188-
* **genetic_value**: Genetic values that are obtained from the trait dataframe.
178+
* **trait_id**: Trait ID.
179+
* **individual_id**: Individual ID inside the tree sequence input.
180+
* **genetic_value**: Genetic values that are obtained from the trait
181+
dataframe.
182+
183+
.. rubric:: Examples
189184
190-
Examples
191-
--------
192185
See :ref:`genetic_value` for worked examples.
193186
"""
194187

@@ -217,44 +210,34 @@ def genetic_value(ts, trait_df):
217210
def normalise_genetic_value(genetic_df, mean=0, var=1, ddof=1):
218211
"""Normalise genetic value dataframe.
219212
220-
Parameters
221-
----------
222-
genetic_df : pandas.DataFrame
223-
Genetic value dataframe.
224-
mean : float, default 0
225-
Mean of the resulting genetic value.
226-
var : float, default 1
227-
Variance of the resulting genetic value.
228-
ddof : int, default 1
229-
Delta degrees of freedom. The divisor used in computing the variance
213+
:param genetic_df: Genetic value dataframe.
214+
:type genetic_df: pandas.DataFrame
215+
:param mean: Mean of the resulting genetic value.
216+
:type mean: float
217+
:param var: Variance of the resulting genetic value.
218+
:type var: float
219+
:param ddof: Delta degrees of freedom. The divisor used in computing the variance
230220
is N - ddof, where N represents the number of elements.
221+
:type ddof: int
222+
:returns: Dataframe with normalised genetic value.
223+
:rtype: pandas.DataFrame
224+
:raises ValueError: If `var` <= 0.
231225
232-
Returns
233-
-------
234-
pandas.DataFrame
235-
Dataframe with normalised genetic value.
236-
237-
Raises
238-
------
239-
ValueError
240-
If `var` <= 0.
226+
.. note::
227+
The following columns must be included in `genetic_df`:
241228
242-
Notes
243-
-----
244-
The following columns must be included in `genetic_df`:
229+
* **trait_id**: Trait ID.
230+
* **individual_id**: Individual ID inside the tree sequence input.
231+
* **genetic_value**: Simulated genetic values.
245232
246-
* **trait_id**: Trait ID.
247-
* **individual_id**: Individual ID inside the tree sequence input.
248-
* **genetic_value**: Simulated genetic values.
233+
The dataframe output has the following columns:
249234
250-
The dataframe output has the following columns:
235+
* **trait_id**: Trait ID.
236+
* **individual_id**: Individual ID inside the tree sequence input.
237+
* **genetic_value**: Normalised genetic values.
251238
252-
* **trait_id**: Trait ID.
253-
* **individual_id**: Individual ID inside the tree sequence input.
254-
* **genetic_value**: Normalised genetic values.
239+
.. rubric:: Examples
255240
256-
Examples
257-
--------
258241
See :ref:`normalise_genetic_value` section for worked examples.
259242
"""
260243
if var <= 0:

tstrait/simulate_effect_size.py

Lines changed: 60 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ class _FreqResult:
1515
"""
1616
Data class that contains simulated effect size and allele frequency.
1717
18-
Attributes
19-
----------
20-
beta_array : numpy.array
21-
Numpy array that includes simulated effect size.
22-
allele_freq : numpy.array
23-
Allele frequency of each causal mutation.
18+
:ivar beta_array: Numpy array that includes simulated effect size.
19+
:vartype beta_array: numpy.array
20+
:ivar allele_freq: Allele frequency of each causal mutation.
21+
:vartype allele_freq: numpy.array
2422
"""
2523

2624
beta_array: np.array
@@ -31,18 +29,16 @@ class _TraitSimulator:
3129
"""Simulator class to select causal alleles and simulate effect sizes of causal
3230
mutations.
3331
34-
Parameters
35-
----------
36-
ts : tskit.TreeSequence
37-
Tree sequence data with mutation.
38-
causal_sites : list
39-
List of causal site IDs.
40-
model : TraitModel
41-
Trait model that will be used to simulate effect sizes.
42-
alpha : float
43-
Parameter that determines the degree of the frequency dependence model.
44-
rng : numpy.random.Generator
45-
Generator object that will be used to generate random numbers.
32+
:param ts: Tree sequence data with mutation.
33+
:type ts: tskit.TreeSequence
34+
:param causal_sites: List of causal site IDs.
35+
:type causal_sites: list
36+
:param model: Trait model that will be used to simulate effect sizes.
37+
:type model: TraitModel
38+
:param alpha: Parameter that determines the degree of the frequency dependence model.
39+
:type alpha: float
40+
:param rng: Generator object that will be used to generate random numbers.
41+
:type rng: numpy.random.Generator
4642
"""
4743

4844
def __init__(self, ts, causal_sites, model, alpha, rng):
@@ -169,62 +165,53 @@ def sim_trait(
169165
"""
170166
Simulates traits.
171167
172-
Parameters
173-
----------
174-
ts : tskit.TreeSequence
175-
The tree sequence data that will be used in the quantitative trait
168+
:param ts: The tree sequence data that will be used in the quantitative trait
176169
simulation.
177-
model : tstrait.TraitModel
178-
Trait model that will be used to simulate effect sizes.
179-
num_causal : int, default None
180-
Number of causal sites that will be randomly selected . If both `num_causal` and
181-
`causal_sites` are None, number of causal sites will be 1.
182-
causal_sites : list, default None
183-
List of site IDs that have causal allele. If None, causal site IDs will be
184-
chosen randomly according to `num_causal`.
185-
alpha : float, default None
186-
Parameter that determines the degree of the frequency dependence model. Please
187-
see :ref:`frequency_dependence` for details on how this parameter influences
188-
effect size simulation. If None, alpha will be 0.
189-
random_seed : int, default None
190-
Random seed of simulation. If None, simulation will be conducted randomly.
191-
192-
Returns
193-
-------
194-
pandas.DataFrame
195-
Trait dataframe that includes simulated effect sizes.
196-
197-
Raises
198-
------
199-
ValueError
200-
If the number of mutations in `ts` is smaller than `num_causal`.
201-
ValueError
202-
If both `num_causal` and `causal_sites` are specified.
203-
ValueError
204-
If there are repeated values in `causal_sites`.
205-
206-
See Also
207-
--------
208-
trait_model : Return a trait model, which can be used as `model` input.
209-
genetic_value : The trait dataframe output can be used as an input to obtain
210-
genetic values.
211-
212-
Notes
213-
-----
214-
The simulation output is given as a :py:class:`pandas.DataFrame` and contains the
215-
following columns:
216-
217-
* **position**: Position of sites that have causal allele in genome coordinates.
218-
* **site_id**: Site IDs that have causal allele. The output dataframe has sorted
219-
site IDs.
220-
* **effect_size**: Simulated effect size of causal allele.
221-
* **causal_allele**: Causal allele.
222-
* **allele_freq**: Allele frequency of causal allele. It is described in detail
223-
in :ref:`trait_frequency_dependence`.
224-
* **trait_id**: Trait ID.
225-
226-
Examples
227-
--------
170+
:type ts: tskit.TreeSequence
171+
:param model: Trait model that will be used to simulate effect sizes.
172+
:type model: tstrait.TraitModel
173+
:param num_causal: Number of causal sites that will be randomly selected.
174+
If both `num_causal` and `causal_sites` are None, number of causal sites
175+
will be 1.
176+
:type num_causal: int
177+
:param causal_sites: List of site IDs that have causal allele. If None,
178+
causal site IDs will be chosen randomly according to `num_causal`.
179+
:type causal_sites: list
180+
:param alpha: Parameter that determines the degree of the frequency
181+
dependence model. Please see :ref:`frequency_dependence` for details on how
182+
this parameter influences effect size simulation. If None, alpha will be 0.
183+
:type alpha: float
184+
:param random_seed: Random seed of simulation. If None, simulation will be
185+
conducted randomly.
186+
:type random_seed: int
187+
:returns: Trait dataframe that includes simulated effect sizes.
188+
:rtype: pandas.DataFrame
189+
:raises ValueError: If the number of mutations in `ts` is smaller than `num_causal`.
190+
:raises ValueError: If both `num_causal` and `causal_sites` are specified.
191+
:raises ValueError: If there are repeated values in `causal_sites`.
192+
193+
.. seealso::
194+
:func:`trait_model` Return a trait model, which can be used as `model` input.
195+
196+
:func:`genetic_value` The trait dataframe output can be used as an input
197+
to obtain genetic values.
198+
199+
.. note::
200+
The simulation output is given as a :py:class:`pandas.DataFrame` and contains the
201+
following columns:
202+
203+
* **position**: Position of sites that have causal allele in genome
204+
coordinates.
205+
* **site_id**: Site IDs that have causal allele. The output dataframe
206+
has sorted site IDs.
207+
* **effect_size**: Simulated effect size of causal allele.
208+
* **causal_allele**: Causal allele.
209+
* **allele_freq**: Allele frequency of causal allele. It is described
210+
in detail in :ref:`trait_frequency_dependence`.
211+
* **trait_id**: Trait ID.
212+
213+
.. rubric:: Examples
214+
228215
See :ref:`sim_trait` for worked examples.
229216
"""
230217
ts = _check_instance(ts, "ts", tskit.TreeSequence)

0 commit comments

Comments
 (0)