Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecations #1301

Merged
merged 1 commit into from
Apr 18, 2024
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
2 changes: 1 addition & 1 deletion doc/long_vignettes/tskit_metadata_vignette.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fwdpy11.evolvets(rng, pop, params,
simplification_interval=100,
suppress_table_indexing=True)

ts = pop.dump_tables_to_tskit(demes_graph=graph)
ts = pop.dump_tables_to_tskit()
```

Now that we have some data, let's look at how the `fwdpy11` mutation and individual information got encoded as `tskit` metadata!
Expand Down
127 changes: 1 addition & 126 deletions doc/long_vignettes/tskitconvert_vignette.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,84 +161,6 @@ ts = pop.dump_tables_to_tskit(model_params=params)
assert fwdpy11.ModelParams(**eval(ts.metadata["model_params"])) == params
```

### Including a `demes` graph

You may include a {class}`demes.Graph` in the top-level metadata.
If you also include a {class}`fwdpy11.ModelParams` (see above), including the `demes` graph gives redundant information.
However, including the graph may be useful if downstream analysis will involve other tools compatible with the `demes` specification.
With the graph as metadata, you can extract it and reconstruct the original `YAML` file, or send it to another Python package that understands it.

The following hidden code block defines a function to return a {class}`demes.Graph` from `YAML` input stored in a string literal.

```{code-cell} python
---
tags: [ "hide-input" ]
---
def gutenkunst():
import demes
yaml = """
description: The Gutenkunst et al. (2009) OOA model.
doi:
- https://doi.org/10.1371/journal.pgen.1000695
time_units: years
generation_time: 25

demes:
- name: ancestral
description: Equilibrium/root population
epochs:
- {end_time: 220e3, start_size: 7300}
- name: AMH
description: Anatomically modern humans
ancestors: [ancestral]
epochs:
- {end_time: 140e3, start_size: 12300}
- name: OOA
description: Bottleneck out-of-Africa population
ancestors: [AMH]
epochs:
- {end_time: 21.2e3, start_size: 2100}
- name: YRI
description: Yoruba in Ibadan, Nigeria
ancestors: [AMH]
epochs:
- start_size: 12300
- name: CEU
description: Utah Residents (CEPH) with Northern and Western European Ancestry
ancestors: [OOA]
epochs:
- {start_size: 1000, end_size: 29725}
- name: CHB
description: Han Chinese in Beijing, China
ancestors: [OOA]
epochs:
- {start_size: 510, end_size: 54090}

migrations:
- {demes: [YRI, OOA], rate: 25e-5}
- {demes: [YRI, CEU], rate: 3e-5}
- {demes: [YRI, CHB], rate: 1.9e-5}
- {demes: [CEU, CHB], rate: 9.6e-5}
"""
return demes.loads(yaml)
```

```{code-cell} python
graph = gutenkunst()
ts = pop.dump_tables_to_tskit(demes_graph=graph)
```

```{code-cell} python
assert demes.Graph.fromdict(ts.metadata["demes_graph"]) == graph
```

Since this is an optional metadata field, accessing it will return `None` if no graph was provided:

```{code-cell} python
ts = pop.dump_tables_to_tskit()
assert "demes_graph" not in ts.metadata
```

### User-defined metadata

It may be useful to store arbitrary data in the output.
Expand Down Expand Up @@ -279,51 +201,4 @@ Further, if the data are very large, then other output formats are likely more a

## Setting population table metadata

You can also set the population table metadata when exporting data.
Doing so requires a {class}`dict` mapping the integer label for each population to another {class}`dict`.

For example, let's create an demographic model from the `demes` graph that used above:

```{code-cell}python
model = fwdpy11.discrete_demography.from_demes(gutenkunst())
type(model)
```

This object contains a mapping from integer labels to the deme names:

```{code-cell} python
model.metadata['deme_labels']
```

We can make the required `dict` like this:

```{code-cell} python
pop_md = {}
for key, value in model.metadata['deme_labels'].items():
pop_md[key] = {'name': value}
```

To actually illustrate the use of this metadata, we need to make sure that our `tskit` output actually has a population table:

```{code-cell} python
# initialize a population with the right number of demes...
multideme_pop = fwdpy11.DiploidPopulation([100]*len(pop_md), 1.)
ts = multideme_pop.dump_tables_to_tskit(population_metadata=pop_md)
for pop in ts.populations():
print(pop.metadata)
```

We could also easily add the deme description to the metadata from the `demes` graph:

```{code-cell} python
graph = gutenkunst()
graph.demes
```

```{code-cell} python
pop_md = {}
for i,deme in enumerate(graph.demes):
pop_md[i] = {'name': deme.name, "description": deme.description}

pop_md
```
TODO
6 changes: 3 additions & 3 deletions doc/misc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ Bug fixes

Breaking changes

* {func}`fwdpy11.TableCollection.fs` no longer accepts more than two sample sets.
* `fwdpy11.TableCollection.fs` no longer accepts more than two sample sets.
This change allowed us to drop `sparse` as a dependency that was causing
headaches when new Python point releases come out.
PR {pr}`924`. Issues {issue}`876`, {issue}`919`.
Expand Down Expand Up @@ -1055,7 +1055,7 @@ Fixes:
This is a point release adding more documentation:

* {ref}`Demes vignette <demes_vignette>` updated.
* {func}`fwdpy11.TableCollection.fs` docstring updated regarding some perhaps unexpected behavior of `sparse.COO`.
* `fwdpy11.TableCollection.fs` docstring updated regarding some perhaps unexpected behavior of `sparse.COO`.

## 0.14.0

Expand Down Expand Up @@ -1494,7 +1494,7 @@ release candidates (see below) plus the following:
{issue}`389`
{issue}`390`
{issue}`392`
* {func}`fwdpy11.TableCollection.fs` added. See `tablefs`.
* `fwdpy11.TableCollection.fs` added. See `tablefs`.
PR {pr}`387`
PR {pr}`399`
* Creating populations from `msprime` input improved.
Expand Down
4 changes: 0 additions & 4 deletions doc/pages/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
:rtype: int
```

```{eval-rst}
.. autofunction:: fwdpy11.simplify
```

```{eval-rst}
.. autofunction:: fwdpy11.simplify_tables
```
Expand Down
4 changes: 1 addition & 3 deletions doc/pages/genetic_values.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ For some background, see {ref}`definitions`.
```

```{eval-rst}
.. autoclass:: fwdpy11.StrictAdditiveMultivariateEffects
.. autoclass:: fwdpy11.AdditivePleiotropy
:members: asdict, fromdict, asblack, shape, genetic_values, maps_to_fitness, maps_to_trait_value
```


1 change: 1 addition & 0 deletions doc/short_vignettes/incomplete_sweep.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def setup(prune_selected=False):
"rates": (0, 0, None),
"prune_selected": False,
"simlen": 200,
"demography": fwdpy11.ForwardDemesGraph.tubes([pop.N], burnin=10)
}
params = fwdpy11.ModelParams(**pdict)

Expand Down
1 change: 1 addition & 0 deletions doc/short_vignettes/selective_sweep.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def setup(prune_selected=False):
"rates": (0, 0, None),
"prune_selected": False,
"simlen": 200,
"demography": fwdpy11.ForwardDemesGraph.tubes([pop.N], burnin=10)
}
params = fwdpy11.ModelParams(**pdict)

Expand Down
1 change: 1 addition & 0 deletions doc/short_vignettes/trackmutationfates.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def setup(prune_selected=False):
"rates": (0, 0, None),
"prune_selected": False,
"simlen": 200,
"demography": fwdpy11.ForwardDemesGraph.tubes([pop.N], burnin=10)
}
params = fwdpy11.ModelParams(**pdict)

Expand Down
1 change: 1 addition & 0 deletions doc/short_vignettes/workingexample_fitness.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ p = {
"prune_selected": True,
"demography": None,
"simlen": 10 * N,
"demography": fwdpy11.ForwardDemesGraph.tubes([N], burnin=10)
}
params = fwdpy11.ModelParams(**p)
```
Expand Down
7 changes: 0 additions & 7 deletions fwdpy11/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,11 @@
PleiotropicOptima,
Optimum,
GaussianStabilizingSelection,
GSS,
GSSmo,
MultivariateGSS,
MultivariateGSSmo,
NoNoise,
GaussianNoise,
Additive,
Multiplicative,
GBR,
StrictAdditiveMultivariateEffects,
AdditivePleiotropy,
PyDiploidGeneticValue,
TimingError,
Expand All @@ -84,8 +79,6 @@
from ._functions import ( # NOQA
data_matrix_from_tables,
infinite_sites,
make_data_matrix,
simplify,
simplify_tables,
_validate_regions,
) # NOQA
Expand Down
11 changes: 1 addition & 10 deletions fwdpy11/_evolvets.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,7 @@ def evolvets(
except Exception as e:
raise e
else:
# Build a default model of "tubes"
from fwdpy11 import ForwardDemesGraph

sizes = pop.deme_sizes()[1].tolist()
msg = "Applying a default demographic model "
msg += f"where deme sizes are {sizes} "
msg += f"and the burn-in length is 10*{sum(sizes)}. "
msg += "This will raise an error in future releases."
warnings.warn(msg, DeprecationWarning, stacklevel=2)
demographic_model = ForwardDemesGraph.tubes(sizes, 10)
raise ValueError("params.demography cannot be None")

for r in params.sregions:
if isinstance(r, fwdpy11.mvDES):
Expand Down
4 changes: 2 additions & 2 deletions fwdpy11/_functions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .data_matrix_from_tables import data_matrix_from_tables, make_data_matrix # NOQA
from .data_matrix_from_tables import data_matrix_from_tables # NOQA
from .import_demes import demography_from_demes # NOQa
from .simplify_tables import simplify, simplify_tables # NOQA
from .simplify_tables import simplify_tables # NOQA

from fwdpy11._fwdpy11 import _infinite_sites
from fwdpy11 import GSLrng, DiploidPopulation
Expand Down
33 changes: 0 additions & 33 deletions fwdpy11/_functions/data_matrix_from_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,6 @@
from .._types import DataMatrix, DiploidPopulation, TableCollection


def make_data_matrix(
pop: DiploidPopulation,
samples: Union[List, np.ndarray],
record_neutral: bool,
record_selected: bool,
) -> DataMatrix:
"""
Create a :class:`fwdpy11.DataMatrix` from a table collection.

:param pop: A population
:type pop: :class:`fwdpy11.PopulationBase`
:param samples: A list of sample nodes
:type samples: list
:param record_neutral: If True, generate data for neutral variants
:type record_neutral: bool
:param record_selected: If True, generate data for selected variants
:type record_selected: bool

.. deprecated:: 0.3.0

Prefer :func:`fwdpy11.data_matrix_from_tables`.

"""
from warnings import warn

warn(
"fwdpy11.make_data_matrix is deprecated."
" Please use fwdpy11.data_matrix_from_tables.",
FutureWarning,
)
return DataMatrix(_make_data_matrix(pop, samples, record_neutral, record_selected))


def data_matrix_from_tables(
tables: TableCollection,
samples: Union[List, np.ndarray],
Expand Down
55 changes: 0 additions & 55 deletions fwdpy11/_functions/simplify_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,6 @@
import numpy as np


def simplify(pop, samples):
"""
Simplify a TableCollection stored in a Population.

:param pop: A :class:`fwdpy11.DiploidPopulation`
:param samples: A list of samples (node indexes).

:return: The simplified tables and array mapping input sample
IDs to output IDS

:rtype: tuple

Note that the samples argument is agnostic with respect to the time of
the nodes in the input tables. Thus, you may do things like simplify
to a set of "currently-alive" nodes plus some or all ancient samples by
including some node IDs from
:attr:`fwdpy11.DiploidPopulation.ancient_sample_metadata`.

If the input contains ancient samples,
and you wish to include them in the output,
then you need to include their IDs in the samples argument.

.. note::

Due to node ID remapping, the metadata corresponding
to nodes becomes a bit more difficult to look up.
You need to use the output ID map, the original IDs, and
the population's metadata containers.

.. deprecated:: 0.3.0

Prefer :func:`fwdpy11.simplify_tables`

.. versionchanged:: 0.3.0

Ancient samples are no longer kept by default

.. versionchanged:: 0.5.0

No longer requires a :class:`MutationVector` argument.

"""
import warnings

warnings.warn(
"This function is deprecated and will be removed soon."
"Please use fwdpy11.simplify_tables instead",
category=FutureWarning,
stacklevel=2,
)

ll_t, idmap = fwdpy11._fwdpy11._simplify(pop, samples)
return fwdpy11._types.TableCollection(ll_t), idmap


def simplify_tables(
tables: fwdpy11._types.TableCollection, samples: Union[List, np.ndarray]
) -> Tuple[fwdpy11._types.TableCollection, np.ndarray]:
Expand Down
Loading
Loading