8000 to_gtf() serializes repeated tag attributes as a single comma-separated value · Issue #214 · pyranges/pyranges1 · GitHub
[go: up one dir, main page]

Skip to content

to_gtf() serializes repeated tag attributes as a single comma-separated value #214

Open

Description

@CaptainLabMan

Hello,

When reading a GTF file with duplicate_attr=True and then exporting it with to_gtf(), repeated tag attributes are written as a single comma-separated value.

Minimal example:

import pyranges1 as pr

gtf_pr = pr.read_gtf(input_gtf_filepath, duplicate_attr=True)
gtf_pr.to_gtf(output_gtf_filepath)

Original attributes:

tag "gencode_basic"; tag "gencode_primary"; tag "Ensembl_canonical";

Exported attributes:

tag "gencode_basic,gencode_primary,Ensembl_canonical";

Expected output:

tag "gencode_basic"; tag "gencode_primary"; tag "Ensembl_canonical";

Although the exported value is a valid quoted string, it no longer represents three separate tag attributes as in the original Ensembl/GENCODE GTF. Downstream tools may interpret it as one unrecognized tag.

Is there an option to preserve repeated attributes when exporting to GTF? If not, could support for this be added?

Thank you!

Activity

  1. changed the title [-]Title: to_gtf() serializes repeated tag attributes as a single comma-separated value[/-] [+]to_gtf() serializes repeated tag attributes as a single comma-separated value[/+] on Nov 2, 2026
  2. endrebak commented on Nov 3, 2026

    @endrebak
    Collaborator

    It would be simple to add. I can try to do so this weekend. I will have to look at the file spec first and see it is valid though.

  3. CaptainLabMan commented on Nov 3, 2026

    @CaptainLabMan
    Author

    I can fix this and create a pull request if that’s okay with you. Actually, I’ve already fixed the problem and I’m going to test it tomorrow =)
    But I’m also happy to wait if you’d prefer to handle it yourself.

  4. endrebak commented on Nov 4, 2026

    @endrebak
    Collaborator

    Feel free to create a PR.

  5. CaptainLabMan commented on Nov 5, 2026

    @CaptainLabMan
    Author

    I fixed the formatting of tag attributes in GTF output.

    The updated output matches the format used by GENCODE and Ensembl, where each tag value is written as a separate tag attribute:

    tag "gencode_basic"; tag "gencode_primary"; tag "Ensembl_canonical";

    In the NCBI RefSeq GTF examples I checked, each feature had only one tag attribute, such as:

    tag "MANE Select";

    Single tag values are unaffected by this change.

    I tested the changes on an Ensembl (Homo_sapiens.GRCh38.116.chr.gtf.gz) GTF file. After the fix, to_gtf() produced separate tag attributes as expected.

    The GENCODE format documentation explicitly allows multiple occurrences of tag and includes examples:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      0