Question: Header In Mpileup Output File
0
gravatar for upendrakumar.devisetty
5.1 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.8k views
ADD COMMENTlink modified 4.9 years ago by swbarnes25.0k • written 5.1 years ago by upendrakumar.devisetty350
1
gravatar for pcantalupo
4.9 years ago by
pcantalupo120
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:

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.

ADD COMMENTlink written 4.9 years ago by pcantalupo120
0
gravatar for swbarnes2
4.9 years ago by
swbarnes25.0k
United States
swbarnes25.0k 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 4.9 years ago • written 4.9 years ago by swbarnes25.0k

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 4.9 years ago by pcantalupo120
Please log in to add an answer.

Help
Access

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