Just "samtools view -H input.bam > newHeader.txt", remove the lines the entries with no alignments (if the BAM file is sorted and indexed, then just look at the output of idxstats) and then "cat newHeader.txt <(samtools view input.bam) | samtools view -Sbo input.header_replaced.bam".
Devon -- Devon Ryan, Ph.D. Email: [email protected] Data Manager/Bioinformatician Max Planck Institute of Immunobiology and Epigenetics Stübeweg 51 79108 Freiburg Germany On Tue, Aug 11, 2015 at 10:40 AM, Bala Ani Akpinar <[email protected]> wrote: > Dear everyone, > > I am using > > $ samtools view -h -F 4 input.bam > input_only_mapped.sam > > to filter out unmapped reads from my bam file. However, this command does > not affect the header section. I would like to remove reference sequences > without any alignments from the header, as well (The reason is, the number > of the lines in the header section exceeds the limit of a downstream > program. This is stemming from the reference file I use to make the > alignments, but I have no other options). So, I am wondering whether it is > possible to remove reference sequences that are not mapped by any reads from > the header section? Any help is greatly appreciated. > > Thank you in advance, > Best regards, > Ani Akpinar > > ------------------------------------------------------------------------------ > > _______________________________________________ > Samtools-help mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/samtools-help > ------------------------------------------------------------------------------ _______________________________________________ Samtools-help mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/samtools-help
