Using ngless, of course. Just run the following on the command line to take the sequences from
ngless -e 'write(as_reads(samfile("input.bam")), ofile="sequences.fq.gz")'
Let me unpack that a bit. This is equivalent to writing the following script:
ngless "0.0" # Load a SAM or BAM file sam_or_bam = samfile("input.bam") # Get the reads out reads = as_reads(sam_or_bam) # Write them out write(reads, ofile="sequences.fq.gz")
The exact behaviour will depend on whether you have paired or single-ended reads. If you have single-ended reads, they will be saved to
sequences.fq.gz. If you have paired-end reads, they will be saved to
sequences.pair.2.fq.gz (and if there are any single-ends mixed in,