Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • samtools and awk depth calculation

    Trying to calculate the average depth of a .bam file: Any ideas?

    Essentialy I just want to get the ....X coverage.

    Code:
     
    samtools depth IonXpress_001.bam | awk '{sum+=$3} END { print "Average = ",sum/NR}' > output.txt
    -bash: samtools: command not found
    awk: cmd. line:1: fatal: division by zero attempted
    Thank you .

    EDIT: I also tried the below to calculate the genome of the .bam for 'NR', but it says samtools command not found.

    Code:
     ./samtools view -H IonXpress_001.bam | grep -P '^@SQ' | cut -f 3 -d ':' | awk '{sum+=$1} END {print sum}'
    = 3095693981
    Last edited by cmccabe; 06-11-2015, 01:07 PM.

  • #2
    Figured it out, just forgot to add samtools to PATH.... oops, but the average is calculated to 0, should it not be $3 or is there somehing else? Thank you

    Code:
     ./samtools depth IonXpress_001.bam | awk '{sum+=$1} END { print "Average = ",sum/3095693981}' > output.txt
    Last edited by cmccabe; 06-11-2015, 01:06 PM.

    Comment


    • #3
      Here is a thread with multiple options (including an awk solution): https://www.biostars.org/p/5165/

      Comment


      • #4
        Thank you, I will try some of the other solutions in the post. Do you see why theawk is not working? I am trying to figure it out as our lab is doing more ngs and different data is often desired. Thank you .

        Comment


        • #5
          Is that BAM directly from Ion software or did you make it yourself? Is the samtools depth part producing an output that looks reasonable?

          Comment


          • #6
            The bam is from Ion software and I will post the output of samtools depth tomorrow. Thank you very much .

            Comment


            • #7
              I found the perl script on that page incredibly useful.

              Code:
              ./samtools mpileup in.bam | awk '{print $4}' | perl ~/coverage.pl
              I am trying to modify the below to calculate the average coverage of a bed file, is that possible?

              Code:
              ./samtools view -b in.bam <genomic region> | ./samtools mpileup - | awk '{print $4}' | perl ~/coverage.pl
              Thank you .

              Comment

              Latest Articles

              Collapse

              • seqadmin
                Essential Discoveries and Tools in Epitranscriptomics
                by seqadmin




                The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
                04-22-2024, 07:01 AM
              • seqadmin
                Current Approaches to Protein Sequencing
                by seqadmin


                Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
                04-04-2024, 04:25 PM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, Today, 08:47 AM
              0 responses
              12 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-11-2024, 12:08 PM
              0 responses
              60 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-10-2024, 10:19 PM
              0 responses
              59 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-10-2024, 09:21 AM
              0 responses
              54 views
              0 likes
              Last Post seqadmin  
              Working...
              X