Skip to content

Commit

Permalink
Ensure uniqueness of unique_indices field
Browse files Browse the repository at this point in the history
  • Loading branch information
thalassemia committed Dec 17, 2024
1 parent 5074a96 commit 340f97e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
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
4 changes: 4 additions & 0 deletions ecoli/processes/chromosome_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,7 @@ def generate_flow(self, config):
full_chromosomes.flags.writeable = True
full_chromosomes["_entryState"][0] = 1
full_chromosomes["domain_index"][0] = 0
full_chromosomes["unique_index"][0] = 0
full_chromosomes.flags.writeable = False
# Set up chromosome domains
chromosome_domains, replisome_idx = get_free_indices(
Expand All @@ -1399,6 +1400,7 @@ def generate_flow(self, config):
chromosome_domains.flags.writeable = True
chromosome_domains["_entryState"][replisome_idx] = 1
chromosome_domains["domain_index"][replisome_idx] = np.arange(5)
chromosome_domains["unique_index"][replisome_idx] = np.arange(5)
chromosome_domains["child_domains"][replisome_idx] = [
[1, 2],
[3, 4],
Expand All @@ -1413,6 +1415,7 @@ def generate_flow(self, config):
oriCs.flags.writeable = True
oriCs["_entryState"][oriC_idx] = 1
oriCs["domain_index"][oriC_idx] = [2, 3, 4]
oriCs["unique_index"][oriC_idx] = np.arange(3)
oriCs.flags.writeable = False
template_initial_state["unique"]["oriC"] = oriCs
# Set up replisome for actively replicating domain
Expand Down Expand Up @@ -1538,6 +1541,7 @@ def generate_flow(self, config):
)
chromosomal_segments["domain_index"][segment_idx] = domain_index
chromosomal_segments["linking_number"][segment_idx] = linking_number
chromosomal_segments["unique_index"][segment_idx] = np.arange(len(linking_number))
chromosomal_segments.flags.writeable = False
template_initial_state["unique"]["chromosomal_segment"] = chromosomal_segments
# Since unique numpy updater is an class method, internal
Expand Down

0 comments on commit 340f97e

Please sign in to comment.