Question: Header In Mpileup Output File
0
gravatar for upendrakumar.devisetty
6.2 years ago by
United States
upendrakumar.devisetty360 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 • 2.1k views
ADD COMMENTlink modified 6.1 years ago by swbarnes27.7k • written 6.2 years ago by upendrakumar.devisetty360
1
gravatar for pcantalupo
6.1 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 Xis the column number starting from 1. I hope this helps you.

ADD COMMENTlink modified 4 months ago by RamRS27k • written 6.1 years ago by pcantalupo120
0
gravatar for swbarnes2
6.1 years ago by
swbarnes27.7k
United States
swbarnes27.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 4 months ago by RamRS27k • written 6.1 years ago by swbarnes27.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 modified 4 months ago by RamRS27k • written 6.1 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: 1816 users visited in the last hour