Skip to content

Keep SEQid to a single field in the output tables - #46

Open
alexlancaster wants to merge 1 commit into
masterfrom
tsv-safe-seqid
Open

Keep SEQid to a single field in the output tables#46
alexlancaster wants to merge 1 commit into
masterfrom
tsv-safe-seqid

Conversation

@alexlancaster

Copy link
Copy Markdown
Contributor

recreated from #41 & #42 as the fork was deleted.

summary below is by @ssiddhantsharma:

Sequence names are copied verbatim from the FASTA header into the SEQid column, and both output tables are tab-delimited. A tab inside a header therefore splits SEQid across several fields and shifts every column after it.

Nothing errors. The header row keeps its 41 columns while affected data rows gain one field per tab, so anything reading the table by column index silently reads the wrong values:

$ printf '>sp|P00001|TEST_HUMAN\tGeneID:1\tMYGENE\nMQNSNQSQNQGQFQQNNMQQQQQQQQQQNQFQQNMPMHQFNMQNQGQFQQNGMQPQFHQQ\n' > tab.fasta
$ java -jar plaac.jar -i tab.fasta | grep -v '^#' | awk -F'\t' '{print NR, NF}'
1 41      <- header row
2 43      <- data row

MitoCarta and several other curated FASTA distributions ship tab-separated headers (>accession<TAB>GeneID:nnn<TAB>SYMBOL), which is how this is usually met. Reading COREscore by index off such a table returns whatever sits two columns to its left.

A related inconsistency comes from fastareader.nextfasta(), which discards the result of its trim():

name = line.substring(1);
name.trim();            // result thrown away; String is immutable

The first record of a file takes its name from hasmorefastas(), which does trim, while later records took it from nextfasta(), which did not. So a file whose headers carry trailing whitespace could produce a different column count for its first record than for the rest:

$ printf '>REC_ONE\t\n<seq>\n>REC_TWO\t\n<seq>\n' > trailing.fasta   # before this change
  cols=41  SEQid=[REC_ONE]
  cols=42  SEQid=[REC_TWO]

The change

A small tsvSafeName() helper maps tabs, newlines and other control characters in the name to spaces and trims it, applied where the name is written into each of the two tables. nextfasta() now assigns the trimmed name.

Sanitising at the point of output rather than at capture keeps -p print-list matching untouched, and also covers names supplied through a print list rather than the FASTA.

Names with no control characters and no surrounding whitespace are returned unchanged, embedded spaces included, so the MOT3 golden output is byte-identical and tests/test_mot3.sh passes unmodified.

Tests

cli/tests/test_seqid_field.sh, following the existing test_common.sh conventions, covers:

  1. a tab inside a header does not change the data row's column count
  2. the tab- and space-separated forms of the same header give identical tables
  3. trailing tabs give every record of a multi-record file the same column count
  4. trailing spaces are trimmed consistently across records
  5. the per-residue table under -p all matches between the two header forms
  6. ordinary names are unchanged

Five of the six fail without the source change. Wired into cli.yml beside the MOT3 and input-validation tests.

Verified locally on Java 17: test_mot3.sh, test_input_validation.sh and test_seqid_field.sh all pass, and the Python wrapper suite passes against the patched jar (23 passed with PLAAC_JAR pointed at it).

Sequence names are copied verbatim from the FASTA header into the SEQid column of
both output tables, which are tab-delimited. A tab inside a header therefore split
SEQid across several fields and shifted every column after it. Nothing failed: the
header row kept its 41 columns while affected data rows gained one field per tab, so
anything reading the table by column index silently read values from the wrong
columns. MitoCarta and several other curated FASTA distributions ship tab-separated
headers, which is how this is usually met.

A related inconsistency came from fastareader.nextfasta(), which discarded the result
of its trim(). The first record of a file takes its name from hasmorefastas(), which
does trim, while later records took it from nextfasta(), which did not. A file whose
headers carried trailing whitespace could therefore produce a different column count
for its first record than for the rest.

Map tabs, newlines and other control characters in the name to spaces and trim it, so
SEQid is always exactly one field, and assign the trimmed name in nextfasta(). Names
without control characters or surrounding whitespace are unchanged, embedded spaces
included, so the MOT3 golden output is byte-identical.

cli/tests/test_seqid_field.sh covers a tab inside a header, agreement between the
tab- and space-separated forms of the same header, trailing tabs and spaces across a
multi-record file, the per-residue table under -p, and that ordinary names are left
alone. Five of its six checks fail without this change. Wired into cli.yml alongside
the MOT3 and input-validation tests.
@alexlancaster alexlancaster self-assigned this Sep 4, 2026
@alexlancaster alexlancaster added this to the 1.1.0 milestone Sep 4, 2026
@alexlancaster

Copy link
Copy Markdown
Contributor Author

hey @oliverking since this touches the Java code, could you take a look at this? it looks fine to me. there are unit tests that check that it covers the cases, it doesn't change any of the existing test outputs

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants