Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • awk to calculate by target and include gene name

    I am trying to modify the awk below to include the gene name ($5) for each target and can not seem to do so. Also, I'm not sure the calculation is right (average of all targets that are the same is $4 using the values in $7)? Thank you .

    Code:
    awk '{if(len==0){last=$4;total=$7;len=1;getline}if($4!=last){printf("%s\t%f\n", last, total/len);last=$4;total=$7;len=1}else{total+=$7;len+=1}}END{printf("%s\t%f\n", last, total/len)}' output.bam.hist.txt > epilepsy70_average.txt
    output.bam.hist.txt
    Code:
    chr1	40539722	40539865	chr1:40539722-40539865	PPT1	1	159
    chr1	40539722	40539865	chr1:40539722-40539865	PPT1	2	161
    chr1	40539722	40539865	chr1:40539722-40539865	PPT1	3	161
    epilepsy70_average.txt
    Code:
    chr1:40539722-40539865	72.000000
    chr1:40542503-40542595	46.500000
    chr1:40544221-40544340	60.000000
    Desired epilepsy70_average.txt
    Code:
    chr1:40539722-40539865	72.000000      PPT1
    chr1:40542503-40542595	46.500000      PPT1
    chr1:40544221-40544340	60.000000      PPT1
    Last edited by cmccabe; 07-28-2015, 10:30 AM. Reason: made an edit to code to use $7 in the average

  • #2
    awk '{if((NR>1)&&($4!=last)){printf("%s\t%f\t%s\n", last, total/len,pg);total=$7;len=1;}else{total+=$7;len+=1};pg=$5;last=$4;}END{printf("%s\t%f\t%s\n", last, total/len,pg)}'

    Comment


    • #3
      Thank you very much

      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, 11:49 AM
      0 responses
      12 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, Yesterday, 08:47 AM
      0 responses
      16 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 04-11-2024, 12:08 PM
      0 responses
      61 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 04-10-2024, 10:19 PM
      0 responses
      60 views
      0 likes
      Last Post seqadmin  
      Working...
      X