I ran Kallisto with the --pseudobam option. How do I extract all the short reads that are mapped to a single transcript (e.g. ENST00000367969.8)? As a person without any previous SAM/BAM experience, I tried the following things without success. Really appreciate some help here.

I first tried:

samtools view -S pseudoalignments.bam ENST00000367969.8

but got the following error:

[E::idx_find_and_load] Could not retrieve index file for 'pseudoalignments.bam'
[main_samview] random alignment retrieval only works for indexed BAM or CRAM files.

I tried to index the file using:

samtools index pseudoalignments.bam

but get the following error:

[E::hts_idx_push] NO_COOR reads not in a single block at the end 79729 -1
[E::sam_index] Read 'A00742:184:HLTF2DSXY:4:1101:4417:1000' with ref_name='ENST00000556431.1', ref_length=4142, flags=83, pos=2098 cannot be indexed
samtools index: failed to create index for "pseudoalignments.bam"
  • $\begingroup$ Cross-posted on biostars: biostars.org/p/9488897. See this thread: bioinformatics.meta.stackexchange.com/questions/265/…. Do not shotgun post on multiple communities, it is inconsiderate. $\endgroup$
    – Ram RS
    Sep 13 at 14:57
  • $\begingroup$ @RamRS Will try to avoid using my shotgun next time :) $\endgroup$
    – Dr. Who
    Oct 1 at 16:48
  • $\begingroup$ It’s not a complicated concept that needs to be tried and avoided. Just don’t post on multiple fora. $\endgroup$
    – Ram RS
    Oct 2 at 17:04

Sort the BAM file again with samtools sort and then run samtools index on the result. That should fix the issue.


What Devon said. Alternatively, you could also just convert the bam to sam and then look for lines where the 3rd field (the reference the sequence is aligned to) is what you want:

samtools view pseudoalignments.bam | awk '$3=="ENST00000367969.8"'

But really, it's far better to sort and index the file as Devon suggested so you can use dedicated tools in future.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.