Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

watch and bam: panics, and asked output that is missing with exit 0

Open
#616 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go

Research direction

Start with the watch and bam command entry points and their tests; reproduce the listed cases using the supplied FASTQ, SAM/BAM, and configuration examples. Trace each panic, silent output, and option error to its handling path, then add regression coverage. Done means invalid inputs return tagged errors with exit 255, valid BAM records are preserved in the stated modes, and the listed edge cases no longer panic.

Written by the indexing model from the issue text.

Description

Version: seqkit v2.14.0 (bioconda), Linux x86_64

Test files. The bam examples use two small BAM files made with samtools:

$ printf '@SQ\tSN:chr1\tLN:40\nr1\t0\tchr1\t1\t60\t10M\t*\t0\t0\tACGTACGTAC\tIIIIIIIIII\tNM:i:0\nr2\t0\tchr1\t5\t30\t10M\t*\t0\t0\tACGTACGTAC\tIIIIIIIIII\n' > x.sam
$ samtools view -b -o x.bam x.sam          # r2 has no NM tag
$ sed 's/IIIIIIIIII$/IIIIIIIIII\tNM:i:0/' x.sam > z.sam
$ samtools view -b -o z.bam z.sam          # every record has NM
$ printf '>chr1\nACGT\n' > notbam.bam      # not a BAM file
$ printf '@a\nACGT\n+\n#III\n' > q.fq

watch and bam: the histogram and picture code panics

$ : > empty.fq
$ seqkit watch empty.fq                    # on a terminal
panic: runtime error: index out of range [0] with length 0

$ printf '@a\nAAAA\n+\nIIII\n' > noGC.fq
$ seqkit watch -f GCSkew -O h.png noGC.fq
panic: runtime error: index out of range [0] with length 0

$ seqkit watch -O h.xyz q.fq               # also with no extension
panic: unsupported format: "xyz"           # and an empty h.xyz is left

$ seqkit watch -O /nonexist/h.png q.fq
panic: open /nonexist/h.png: no such file or directory

$ seqkit bam -f MapQual -O h.txt -Q x.bam
panic: unsupported format: "txt"

Each exits 2.

Expected

An [ERRO] message and exit 255, as for other bad input. No empty file is
left.

watch -f MeanQual: a quality letter below -b panics

$ seqkit watch -f MeanQual -y -b 40 q.fq
panic: runtime error: index out of range [-5]
$ echo $?
2

The same class of problem as #598.

Expected

An error that names the bad quality letter, exit 255.

watch: a terminal narrower than 11 columns panics

$ printf '>a\nACGT\n>b\nACGTACGTAC\n' > two.fa
$ script -qec "stty cols 5; seqkit watch -y two.fa" /dev/null
panic: runtime error: makeslice: len out of range

Exit code 2, also with -y (no plot).

Expected

The automatic bin count is at least 1.

watch -f and bam -f: a bad field name exits 1 with no [ERRO] tag

$ seqkit watch -f foo q.fq
Invalid field: foo
$ echo $?
1

$ seqkit bam -f foo x.bam > out.txt
Invalid field: foo
The valid fields are:
$ echo $?
1
$ head -2 out.txt                          # the field list goes to stdout
Read
Ref

All other option errors give [ERRO] and exit 255.

Expected

[ERRO] Invalid field: foo, exit 255, and the field list on stderr.

bam: a mapped record with no NM tag panics

What happens

The NM tag is optional in SAM, but seqkit bam x.bam (the default table)
panics at the first mapped record that has no NM tag. The output is cut.
-f Acc, the top mode and the toolbox do the same.

$ seqkit bam x.bam
Read	Ref	Pos	EndPos	MapQual	Acc	...
r1	chr1	0	10	60	100	...
panic: no NM tag
$ echo $?
2

$ seqkit bam -T '{AccStats: {Tsv: "-"}, Sink: True}' x.bam
panic: No NM tag in the BAM record!
Expected

An error that names the read, exit 255. Or the accuracy fields are computed
from MD/CIGAR, or left empty for that record.

bam -?: a negative value panics

$ seqkit bam -f MapQual -@ top.bam -? -1 -Q x.bam
panic: runtime error: makeslice: len out of range

Exit code 2.

Expected

An error such as value of flag --top-size should not be negative.

bam -x: the field table mode and -s pass no records (exit 0)

$ seqkit bam -x -f Read,MapQual z.bam > pass.bam
$ echo $?
0
$ samtools view -c pass.bam
[W::bam_hdr_read] EOF marker is absent. The input is probably truncated
0

$ seqkit bam -x -s z.bam | wc -c
0

With one field, -x passes the records.

Expected

pass.bam holds the 2 input records. With -s, the records pass or an error
says that -x and -s cannot be used together.

bam -T: an input that is not BAM panics

$ seqkit bam -T '{AccStats: {Tsv: "-"}, Sink: True}' notbam.bam
panic: runtime error: invalid memory address or nil pointer dereference
$ seqkit bam -s notbam.bam
[ERRO] gzip: invalid header
Expected

The same [ERRO] gzip: invalid header as the other modes, exit 255.

bam -@: no top file, no message, exit 0

With no -f, with two fields, or with a text field such as Ref, the file of
-@ is not written and nothing says why.

$ seqkit bam -f Ref -@ top.bam -? 3 -Q z.bam > /dev/null; echo $?
0
$ ls top.bam
ls: cannot access 'top.bam': No such file or directory
Expected

An error such as --top-bam requires a single numeric --field.

bam -s: one bad file removes the lines of the good files

$ cp z.bam w.bam
$ seqkit bam -s z.bam w.bam
PrimAlnPerc	MultimapPerc	PrimAln	...	File
100.00	0.00	2	...	z.bam
100.00	0.00	2	...	w.bam
$ seqkit bam -s z.bam notbam.bam w.bam
[ERRO] gzip: invalid header
$ echo $?
255

$ cat z.bam | seqkit bam -s - -
[ERRO] EOF
Expected

The header and the line for z.bam, then the error. (stats has the same
kind of problem, #599.)

bam -T Dump: an unknown field name is dropped with no message

$ cat dump.yml
Dump:
  Tsv: "-"
  Fields: ["Read","Foo"]
Sink: True
$ seqkit bam -T '{Yaml: "dump.yml"}' z.bam
Read
r1
r2
$ echo $?
0
Expected

An error such as Dump: unknown field: Foo.

Dominant language
Go
Stars
1.6k
Forks
189
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from shenwei356/seqkit

All issues in shenwei356/seqkit

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.