Header In Mpileup Output File
2
0
Entering edit mode
10.1 years ago

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

mpileup samtools • 3.0k views
ADD COMMENT
1
Entering edit mode
10.0 years ago
pcantalupo ▴ 120

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 Xis the column number starting from 1. I hope this helps you.

ADD COMMENT
0
Entering edit mode
10.0 years ago

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 COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 3156 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6