Average score


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Average score
# 1  
Old 10-22-2014
Average score

Code:
 awk '{if(len==0){last=$4;total=$6;len=1;getline}if($4!=last){printf("%s\t%f\n", last, total/len);last=$4;total=$6;len=1}else{total+=$6;len+=1}}END{printf("%s\t%f\n", last, total/len)}' exon.txt > output.txt

In the attached file I am just trying to group all the same names in column $4 and then average them using the scores in $5, then output a file with text. Thanks Smilie.

So in the file if CHD6 only appeared 2 times:
Code:
 chr20	40079730	40079774	A_16_P34711167	CHD6	0.5198
chr20	40079588	40079638	A_16_P34711162	CHD6	0.5806

then the output.txt would be
Code:
 CHD6 occurs 2 times with an average of 0.5529

# 2  
Old 10-22-2014
I do not get the same average you do. I get 0.5502. What function are you using to calculate average?

Otherwise:

Code:
awk '{ N[$5]++ ; T[$5]+=$6 } END { for(X in N) printf("%s occurs %d times with an average of %f\n", X, N[X], T[X]/N[X]); }' inputfile

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 10-22-2014
I copied the numbers incorrectly. The script works great and I got the same # as you. Thank you Smilie.
This User Gave Thanks to cmccabe For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Mean score value by ID over a defined genomic region

Hi, I would like to know how can I get a mean score value by ID over a defined genomic region. Here it is an example: file1 12 100 103 id1 12 110 112 id1 12 200 203 id2 file2 12 100 101 1 12 101 102 0.8 12 102 103 0.7 12 110 111 2.5 12 111 112 2.8 12 200 201 10.1 12 201 202... (7 Replies)
Discussion started by: fadista
7 Replies

2. Shell Programming and Scripting

Split a file in more files based on score content

Dear All, I have the following file tabulated: ID distanceTSS score 8434 571269 10 10122 393912 9 7652 6 10 4863 1451 9 8419 39 2 9363 564 21 9333 7714 22 9638 8334 9 1638 1231 11 10701 918 1000 6587 32056 111 What I would like to do is the following, create 100 new files based... (5 Replies)
Discussion started by: paolo.kunder
5 Replies

3. Shell Programming and Scripting

Loop for average

I am trying to write a loop script in bash thru umbuntu for the following: ask for a password if wrong show a message if wright then asks for 3 numbers from you then calculates the average of them at the end it saves the average and the date of the calculation in a text file and then zips it.... (1 Reply)
Discussion started by: redmond1212
1 Replies

4. UNIX for Dummies Questions & Answers

Calculating average

Hi, i have 12 float variables in a bash file and i want to calculate the average of them. Can any body help? (6 Replies)
Discussion started by: limadario
6 Replies

5. Shell Programming and Scripting

Grade Score Script Project

What I thought would be an extremely simple project has proven more difficult for me than I thought. Here are the parameters: Thus far, I've been able to sort the final grades, but I'm having a lot of trouble with appending the correlating letter grade to the end of each line. Any help would be... (3 Replies)
Discussion started by: lazypeterson
3 Replies

6. Shell Programming and Scripting

remove lines based on score criteria

Hi guys, Please guide for Solution. PART-I INPUT FILE (has 2 columns ID and score) TC5584_1 93.9 DV161411_2 79.5 BP132435_5 46.8 EB682112_1 34.7 BP132435_4 29.5 TC13860_2 10.1 OUTPUT FILE (It shudn't contain the line ' BP132435_4 29.5 ' as BP132435 is repeated... (2 Replies)
Discussion started by: smriti_shridhar
2 Replies

7. Post Here to Contact Site Administrators and Moderators

I cant updated the score on space invaders

Hello The same thing happen to me yesterday I canīt record my score on invaders game. (0 Replies)
Discussion started by: lo-lp-kl
0 Replies

8. Shell Programming and Scripting

how to average in awk

Hi, I have the data like this $1 $2 1 12 2 13 3 14 4 12 5 12 6 12 7 13 8 14 9 12 10 12 i want to compute average of $1 and $2 every 5th line (1-5 and 6-10) Please help me with awk Thank you (4 Replies)
Discussion started by: saint2006
4 Replies

9. Shell Programming and Scripting

count average

Hi Friends, Can any one help me with count average of student marks in this file (i can not change structure of the input file): input file: 1 - student ID 2 - student name 3 - group ID 4 - teacher ID 5 - marks (numbers of marks are different) 1:John Smith:2:3:2 3 4 5 2:Mark... (1 Reply)
Discussion started by: mleplawy
1 Replies

10. UNIX for Dummies Questions & Answers

average value

If I have a file like this, could anyone please guide me how to find the average value in each metrix. The file has got about 130,000 metrixs. Grid-ref= 142, 235 178 182 203 240 273 295 289 293 283 262 201 176 167 187 187 246 260 282 299 312 293 276 230 191 169 ... (2 Replies)
Discussion started by: su_in99
2 Replies
Login or Register to Ask a Question