Skip to content

Reader class attributes immutable (Cannot edit "sample_id" field of mutable read object) #115

Closed
@jennifergribble-nanopore

Description

Issue Description

I have installed the pod5 package via pip and were attempting to use it via a custom Python script as referenced in this issue:

https://github.com/nanoporetech/pod5-file-format/issues/100

to edit the sample_id field. The error is:

Exception has occurred: FrozenInstanceError
cannot assign to field 'sample_id'
File "/data/TS_data_analysis/jgribble/abrf_methylation/pod5_rename/pod5_rename_test.py", line 12, in
read.run_info.sample_id = str('NA24385_MGI_Lib1_New_flowcell')
^^^^^^^^^^^^^^^^^^^^^^^
dataclasses.FrozenInstanceError: cannot assign to field 'sample_id'

To my understanding, this appears that the following code block does not create a mutable RunInfo attribute? Is this intended or should users be able to edit RunInfo fields using this package?

import pod5

# New output file for edited data
with pod5.Writer("output.pod5") as writer:
    # Read all records
    with pod5.Reader("input.pod5") as reader:
          # Iterate over immutable ReadRecords
          for record in reader:
               # Convert to mutable Read
               read = record.to_read()
               # Edit the value
               read.run_info.sample_id = str('NA24385_MGI_Lib1_New_flowcell')

Specifications

  • Pod5 Version: 0.3.6
  • Python Version: 3.11
  • Platform: conda env on Linux (Ubuntu 20.04)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions