Add write gtf feature - Issue #21 - #46
Closed
Benoitdw wants to merge 2 commits into
Closed
Conversation
gamazeps
reviewed
Apr 11, 2024
| def test_write_gtf(tmp_path): | ||
| gtf_dict = read_gtf(REFSEQ_GTF_PATH) | ||
| write_gtf(gtf_dict, tmp_path/"dummy_gtf.gtf") | ||
| assert isinstance(read_gtf(str(tmp_path/"dummy_gtf.gtf")), DataFrame) |
There was a problem hiding this comment.
Check for equality of this gtf and the original one too ?
|
Looks good to me at least :) @iskandr all good with you too ? |
Contributor
|
Thanks @Benoitdw — sorry this sat so long! I've adopted your I made a few fixes on top of your version so it could land:
Closing this in favor of #72 — really appreciate the original contribution, which is what got the feature moving. 🙏 |
iskandr
added a commit
that referenced
this pull request
Jul 8, 2026
…tions Addresses the review findings on the first draft: - Faithful missing-value handling. read_gtf represents an absent attribute as null (numeric *_version columns) or the empty string (string columns) and cannot tell absent from present-but-empty. The writer now omits both null and "" so that read -> write -> read reproduces the parsed frame exactly, including column order, on multi-feature GTFs (GENCODE). A non-empty falsy value such as "0" is still written (the original #46 bug). - Vectorized. The attribute field and full line are built with polars expressions (concat_str/format) instead of per-row Python; ~200k rows x 6 attributes now writes in ~0.1s. - gzip output. A path ending in .gz is gzip-compressed, mirroring read_gtf which transparently reads gzipped GTFs. - Dropped the redundant fixed-column filter; fixed columns are always written in canonical order (the missing-column guard runs first). - Documented that "\"" and ";" in attribute values cannot round-trip (a limitation shared with read_gtf, which strips quotes and splits on ";"). Tests now cover both directions across RefSeq/Ensembl/GENCODE/StringTie fixtures: write(read(...)) recovers the parsed frame and is byte-idempotent (a fixed point); read(write(...)) recovers a DataFrame's values. Plus gzip, pandas input, the "0"-vs-empty-vs-null semantics, "." for missing fixed values, header lines, the structural-character limitation, and the missing-column error. Co-authored-by: Benoitdw <[email protected]> Claude-Session: https://claude.ai/code/session_014fNxSBm5zvdsDNwN3nhmpS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixe #21