Question: Header In Mpileup Output File
gravatar for upendrakumar.devisetty
5.6 years ago by
United States
upendrakumar.devisetty350 wrote:

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

samtools mpileup • 1.9k views
ADD COMMENTlink modified 5.5 years ago by swbarnes26.7k • written 5.6 years ago by upendrakumar.devisetty350
gravatar for pcantalupo
5.5 years ago by
United States
pcantalupo120 wrote:

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: 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.

ADD COMMENTlink written 5.5 years ago by pcantalupo120
gravatar for swbarnes2
5.5 years ago by
United States
swbarnes26.7k wrote:

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.

ADD COMMENTlink modified 5.4 years ago • written 5.5 years ago by swbarnes26.7k

I think I may have misunderstood the OP question. Can you please add the exact command line that you used to perform this?


ADD REPLYlink written 5.5 years ago by pcantalupo120
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1393 users visited in the last hour