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

Handle removed replisomes in superhelical density calculations #269

Merged
merged 8 commits into from
Dec 17, 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
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.3
hooks:
# Run the linter.
- id: ruff
types_or: [ python, pyi ]
args: [ --fix ]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi ]
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ finishes, close and reopen your terminal before continuing with the
> **Tip:** If any step in the `nextflow` installation fails,
> try rerunning a few times to see if that fixes the issue.

If you are installing the model for active development, we strongly
recommend that you also install the development dependencies using:

uv sync --frozen --extra dev

After that, you can run ``uv run pre-commit install`` to install
a pre-commit hook that will run the ``ruff`` linter and formatter
before all of your commits.

The development dependencies also include ``pytest``, which lets
you run the test suite, and ``mypy``, which can be invoked to
perform static type checking.

## Test Installation

To test your installation, from the top-level of the cloned repository, invoke:
Expand Down
15 changes: 12 additions & 3 deletions doc/stores.rst
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,7 @@ molecule). All unique molecules will have the following named fields:
generate the new unique indices. If you need to reference the unique
indices of new molecules in the same process AND timestep in which they
are generated, see :py:meth:`ecoli.library.schema.create_unique_indices`.
Note that unique indices are only unique for a cell and its ancestors. For
example, two daughter cells from the same parent cell will have conflicting
unique indices.
Note that unique indices are only unique within a single cell.
2. ``_entryState`` (:py:attr:`numpy.int8`): 1 for active row, 0 for inactive row
When unique molecules are deleted (e.g. RNA degradation), all of their data,
including the ``_entryState`` field, is set to 0. When unique molecues are
Expand All @@ -352,6 +350,17 @@ molecule). All unique molecules will have the following named fields:
changing protein mass of the polypeptide associated with an actively
translating ribosome.

.. note::
Unique molecules are instances of :py:class:`~ecoli.library.schema.MetadataArray`,
a subclass of Numpy arrays that adds a ``metadata`` attribute. This attribute
is used to store the next unique index to be assigned to a new unique molecule.
If you wish to add a custom unique molecule type, after you have
created a structured Numpy array with at least the above attributes,
create a :py:class:`~ecoli.library.schema.MetadataArray` instance from it using
``MetadataArray(array, next_unique_index)``, where ``array`` is your structured
Numpy array and ``next_unique_index`` is the next unique index to be assigned.


Initialization
==============
See :ref:`initialization`.
Expand Down
3 changes: 2 additions & 1 deletion doc/workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ is a list workflow behaviors enabled in our model to handle unexpected errors.
- If you realize that a code issue is the cause of job failure(s), stop
the workflow run if it is not already (e.g. ``control + c``, ``scancel``,
etc.), make the necessary code fixes, and rerun :py:mod:`runscripts.workflow`
with the same configuration JSON and the ``--resume`` command-line argument.
with the same configuration JSON and the ``--resume`` command-line argument,
supplying the experiment ID (with time suffix if using ``suffix_time`` option).
Nextflow will intelligently resume workflow execution from the last successful
job in each chain of job dependencies (e.g. generation 7 of a cell lineage
depends on generation 6, :py:mod:`runscripts.create_variants` depends on
Expand Down
5 changes: 1 addition & 4 deletions ecoli/library/initial_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,10 +1240,7 @@ def initialize_transcription(
unique_molecules["RNA"] = np.concatenate((partial_rnas, full_rnas))
# Have to recreate unique indices or else there will be conflicts between
# full and partial RNAs
unique_mol_names = list(
sim_data.internal_state.unique_molecule.unique_molecule_definitions.keys()
)
unique_prefix = unique_mol_names.index("RNA") << 59
unique_prefix = np.min(unique_molecules["RNA"]["unique_index"])
unique_molecules["RNA"]["unique_index"] = np.arange(
unique_prefix, unique_prefix + len(unique_molecules["RNA"])
)
Expand Down
12 changes: 12 additions & 0 deletions ecoli/library/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ class MetadataArray(np.ndarray):
def __new__(cls, input_array, metadata=None):
# Input array should be an array instance
obj = np.asarray(input_array).view(cls)
# Ensure unique_index field exists and is unique
if "unique_index" in obj.dtype.names:
if "_entryState" in obj.dtype.names:
unique_indices = obj["unique_index"][obj["_entryState"].view(np.bool_)]
if len(unique_indices) != len(set(unique_indices)):
raise ValueError(
"All elements in the 'unique_index' field must be unique."
)
else:
raise ValueError("Input array must have an '_entryState' field.")
else:
raise ValueError("Input array must have a 'unique_index' field.")
obj.metadata = metadata
return obj

Expand Down
Loading
Loading