Closed leon945945 closed 7 months ago
In gdb
, it looks like you didn't give any arguments when running your program, so it crashed when trying to access argv[1]
. (You've also commented out the exit(EXIT_FAILURE);
after the usage message, which would have prevented this.) Inside gdb
, you need to use something like this:
run BailiuNO.bam . > Illumina.readsTag.txt
to see where the program is really going wrong.
From a quick look, I expect the problem may be that one of the reads doesn't have an AS
or NM
tag, so bax_aux_get()
returned NULL. Passing that to bam_aux2i()
will have resulted in it trying to dereference a NULL pointer. A safer version would be:
//output
uint8_t *as_tag = bam_aux_get(aln,"AS");
uint8_t *nm_tag = bam_aux_get(aln,"NM");
printf("%s\t%s\t%ld\t%ld\t%ld\t%d\t%d\t%d\t%.2f\t%s",
bam_get_qname(aln),
hdr->target_name[aln->core.tid],
aln->core.pos,
as_tag ? bam_aux2i(as_tag) : -1,
nm_tag ? bam_aux2i(nm_tag) : -1,
alnLen,
aln->core.n_cigar,
readLen,
ratio,
mark);
That will output -1 when the tags are missing, you may want to change that depending on your use case.
@daviesrob So happy to solve this problem, you are the best! Thank you so much.
Hello, I learned htslib and
c
program myself due to the slow running speed ofPySam
, therefore I did't fully master c program and htslib.I have tried to write some htslib
c
programs to get reads Tag and alignment position, they ran normally on HiFi bam files aligned withminimap2
, but when I applied it to Illumina bam files aligned withbwa
, it throwedsegmentation fault (core dumped)
.Here are my codes:
Illumina bam:
It ran normally on HiFi bam:
And I tried to debug it with gdb:
Sorry to have no idea on how to fix it, Please give me some suggestions to modify this program, then making it run normally on Illumina bam file. Thanks very much.