Hi, does anybody how to add header information into samtools mpileup output file? I have over 72 bam files and i would like to have names of all the bam files as header corresponding to each column in mpileup output.
Thanks
Upendra
Hi, does anybody how to add header information into samtools mpileup output file? I have over 72 bam files and i would like to have names of all the bam files as header corresponding to each column in mpileup output.
Thanks
Upendra
You could use a Perl script like this (as long as samtools
is in your PATH
):
#!/usr/bin/env perl
use strict;
use warnings;
while (my $file = shift) {
my @results = `samtools mpileup $file`;
my @fields = split (/\t/, $results[0]);
my @header = ();
for (my $i=1; $i<=@fields; $i++) {
push (@header, $file . ".col" . $i);
}
open (my $out, ">", $file . ".mpileup") or die;
print $out join ("\t", @header), "\n";
print $out @results;
}
and use it like this:
script.pl BAMFILE [BAMFILE...]
The script will output a file with the suffix .mpileup
file for each bamfile. The first row of the output file will contain column names with the format of BAMFILE.colX
where X
is the column number starting from 1. I hope this helps you.
The software already puts the name of each .bam file at the top of each column. I made one with 192 samples just yesterday, and each column had the right name attached.
Sorry, I am mistaken. I never run mpileup without piping into bcftools to make a vcf, and THAT always has the sample names.
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
I think I may have misunderstood the OP question. Can you please add the exact command line that you used to perform this?