Skip to content

h5py TypeError '<' not supported between instances of 'str' and 'int' #234

@mtekman

Description

@mtekman

Describe the bug

An H5 file fails to be built from the sample parquet file.

To Reproduce

capcruncher interactions count \
      results/<sample>/<sample>.parquet \
 -o interim/pileups/counts_by_restriction_fragment/<sample>.hdf5 \
 -f  resources/restriction_fragments/genome.digest.bed.gz \
 -v <viewpoints.bed> -p 5 --assay capture

fails with:

*** TypeError: '<' not supported between instances of 'str' and 'int'

Workaround

This can be fixed by patching the cooler library, though I'm not sure if it's correct to, and I'm sure the error occurs elsewhere upstream. This is the fix that I implemented though:

In ~/micromamba/envs/cc/lib/python3.10/site-packages/cooler/create/_create.py, change lines 110-127 from:

    # Store bins
    try:
        chrom_dset = grp.create_dataset(
            "chrom", shape=(n_bins,), dtype=chrom_dtype, data=chrom_ids, **h5opts
        )
    except ValueError:
        # If too many scaffolds for HDF5 enum header,
        # try storing chrom IDs as raw int instead
        if chrom_as_enum:
            chrom_as_enum = False
            chrom_dtype = CHROMID_DTYPE
            chrom_dset = grp.create_dataset(
                "chrom", shape=(n_bins,), dtype=chrom_dtype, data=chrom_ids, **h5opts
            )
        else:
            raise
    if not chrom_as_enum:
        chrom_dset.attrs["enum_path"] = "/chroms/name"

to:

    try:
        chrom_dset = grp.create_dataset(
            "chrom", shape=(n_bins,), dtype=chrom_dtype, data=chrom_ids, **h5opts
        )
    except (ValueError, TypeError):
        # TypeError: '<' not supported between instances of 'str' and 'int'
        # If too many scaffolds for HDF5 enum header,
        # try storing chrom IDs as raw int instead
        if chrom_as_enum:
            chrom_as_enum = False
            chrom_dtype = CHROMID_DTYPE
            chrom_dset = grp.create_dataset(
                "chrom", shape=(n_bins,), dtype=chrom_dtype, data=chrom_ids, **h5opts
            )
        else:
            raise
    if not chrom_as_enum:
        chrom_dset.attrs["enum_path"] = "/chroms/name"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions