Sponsored Content
Top Forums Shell Programming and Scripting Taking largest (negative) number from column of coordinates and adding positive form to every other Post 302561885 by crunchgargoyle on Wednesday 5th of October 2011 12:39:45 PM
Old 10-05-2011
Taking largest (negative) number from column of coordinates and adding positive form to every other

Hello all,

I'm new to the forums and hope to be able to contribute something useful in the future; however I must admit that what has prompted me to join is the fact that currently I need help with something that has me at the end of my tether.

I have a PDB (Protein Data Bank) file which I have condensed to the following for ease of modification:

Code:
HETATM    1  C   UNK     0     -25.639   7.865   8.470  0.00  0.00           C+0
HETATM    2  C   UNK     0     -24.868   8.448   7.265  0.00  0.00           C+0
HETATM    3  C   UNK     0     -23.332   8.257   7.385  0.00  0.00           C+0
HETATM    4  C   UNK     0     -22.562   8.844   6.174  0.00  0.00           C+0
HETATM    5  C   UNK     0     -21.028   8.648   6.301  0.00  0.00           C+0
HETATM    6  C   UNK     0     -20.246   9.232   5.094  0.00  0.00           C+0
HETATM    7  C   UNK     0     -18.714   9.031   5.231  0.00  0.00           C+0
HETATM    8  C   UNK     0     -17.931   9.614   4.026  0.00  0.00           C+0
HETATM    9  C   UNK     0     -16.400   9.414   4.163  0.00  0.00           C+0
HETATM   10  C   UNK     0     -15.609   9.993   2.963  0.00  0.00           C+0
HETATM   11  C   UNK     0     -14.078   9.783   3.118  0.00  0.00           C+0
HETATM   12  C   UNK     0     -13.276  10.358   1.924  0.00  0.00           C+0
HETATM   13  C   UNK     0     -11.741  10.165   2.048  0.00  0.00           C+0
HETATM   14  C   UNK     0     -10.997  10.761   0.823  0.00  0.00           C+0
HETATM   15  C   UNK     0      -9.453  10.598   0.887  0.00  0.00           C+0
HETATM   16  C   UNK     0      -8.744  11.204  -0.349  0.00  0.00           C+0
HETATM   17  O   UNK     0      -7.420  11.028  -0.226  0.00  0.00           O+0
HETATM   18  P   UNK     0      -6.354  11.451  -1.177  0.00  0.00           P+0
HETATM   19  O   UNK     0      -5.034  11.048  -0.629  0.00  0.00           O+0
HETATM   20  O   UNK     0      -6.380  12.923  -1.348  0.00  0.00           O+0
HETATM   21  O   UNK     0      -6.556  10.795  -2.491  0.00  0.00           O+0
HETATM   22  H   UNK     0      -9.116  10.704  -1.250  0.00  0.00           H+0
HETATM   23  H   UNK     0      -8.986  12.271  -0.408  0.00  0.00           H+0
HETATM   24  H   UNK     0      -9.199   9.536   0.949  0.00  0.00           H+0
HETATM   25  H   UNK     0      -9.070  11.093   1.785  0.00  0.00           H+0
HETATM   26  H   UNK     0     -11.237  11.827   0.752  0.00  0.00           H+0
HETATM   27  H   UNK     0     -11.366  10.270  -0.084  0.00  0.00           H+0
HETATM   28  H   UNK     0     -11.381  10.656   2.956  0.00  0.00           H+0
HETATM   29  H   UNK     0     -11.510   9.098   2.119  0.00  0.00           H+0
HETATM   30  H   UNK     0     -13.488  11.427   1.843  0.00  0.00           H+0
HETATM   31  H   UNK     0     -13.616   9.871   1.007  0.00  0.00           H+0
HETATM   32  H   UNK     0     -13.745  10.270   4.038  0.00  0.00           H+0
HETATM   33  H   UNK     0     -13.874   8.713   3.202  0.00  0.00           H+0
HETATM   34  H   UNK     0     -15.820  11.063   2.880  0.00  0.00           H+0
HETATM   35  H   UNK     0     -15.949   9.507   2.044  0.00  0.00           H+0
HETATM   36  H   UNK     0     -16.190   8.344   4.245  0.00  0.00           H+0
HETATM   37  H   UNK     0     -16.061   9.901   5.082  0.00  0.00           H+0
HETATM   38  H   UNK     0     -18.146  10.684   3.947  0.00  0.00           H+0
HETATM   39  H   UNK     0     -18.275   9.125   3.110  0.00  0.00           H+0
HETATM   40  H   UNK     0     -18.372   9.519   6.150  0.00  0.00           H+0
HETATM   41  H   UNK     0     -18.501   7.961   5.313  0.00  0.00           H+0
HETATM   42  H   UNK     0     -20.460  10.302   5.014  0.00  0.00           H+0
HETATM   43  H   UNK     0     -20.589   8.743   4.177  0.00  0.00           H+0
HETATM   44  H   UNK     0     -20.681   9.137   7.216  0.00  0.00           H+0
HETATM   45  H   UNK     0     -20.810   7.579   6.379  0.00  0.00           H+0
HETATM   46  H   UNK     0     -22.909   8.355   5.259  0.00  0.00           H+0
HETATM   47  H   UNK     0     -22.780   9.912   6.096  0.00  0.00           H+0
HETATM   48  H   UNK     0     -23.110   7.188   7.462  0.00  0.00           H+0
HETATM   49  H   UNK     0     -22.982   8.746   8.299  0.00  0.00           H+0
HETATM   50  H   UNK     0     -25.095   9.516   7.190  0.00  0.00           H+0
HETATM   51  H   UNK     0     -25.224   7.959   6.354  0.00  0.00           H+0
HETATM   52  H   UNK     0     -26.712   8.024   8.339  0.00  0.00           H+0
HETATM   53  H   UNK     0     -25.456   6.791   8.555  0.00  0.00           H+0
HETATM   54  H   UNK     0     -25.326   8.355   9.395  0.00  0.00           H+0

What I want to do is take the largest negative number from each of the three columns after the column containing nothing but '0' values (-26.712 in the first column, for example), and add the positive value of those single numbers to every single value in their respective columns. This is because I require that there be no negative numbers in the output.

I've tried all sorts of combinations of (g)awk, sed, grep in Bash, and various Python scripts (which I think is probably a more suitable language for this sort of task) but nothing has done it.

I'm still a relative newbie so am probably being ignorant about something obvious; please bear with me. Any help would be greatly appreciated.
This User Gave Thanks to crunchgargoyle For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help in adding positive & negative values in a column

Hi Gurus, In my file I have an amount field from position 74 to 87, which contains values starting with '+' as well as '-'. I want to add all positive values in a varible called "CREDIT" and all negative values in a variable "DEBIT". I know, we can use grep to identify values with positive and... (4 Replies)
Discussion started by: berlin_germany
4 Replies

2. Programming

Adding 2 difft int to form a number

got 1 problem.. can someone help me wit the logic? Money Money ::operator+(const Money &rhs)const { Money temp; temp.a = a+rhs.a; temp.b = b+rhs.b; return temp; }//end i got 2 number e.g 6.2 and 3.8 (1 Reply)
Discussion started by: xiaojesus
1 Replies

3. Shell Programming and Scripting

Perl output with negative and positive numbers

Hello, For my weather station I have made a little perl script to put the data into cacti. The next problem I have. I can only get positive numbers or negative numbers. What do I do: Though a shell scrip I call the perl script. Shell script: #!/bin/sh cat data.txt | stats.pl Perl... (4 Replies)
Discussion started by: rbl-blacklight
4 Replies

4. Shell Programming and Scripting

Finding the most positive and negative value and defining its position

Hi, I have a file that looks like this: Jake 2 3 4 6 4 3 -2 -1 Jerry 1 2 3 2 1 7 -6 -1 Timmy -1 -4 -5 -8 9 3 1 I want to find the most positive and negative value for each row and also define its position (based on column #) So the output would look... (7 Replies)
Discussion started by: gisele_l
7 Replies

5. Shell Programming and Scripting

Sorting positive and negative values

Hello, I have a list like this : 1 2 -4 0 -3 -7 5 6 etc. Is there a way to remove all the positive values and print only the negative values, without using grep, sed or awk? Thanks, Prasanna (4 Replies)
Discussion started by: prasanna1157
4 Replies

6. Shell Programming and Scripting

addition of both positive and negative numbers

Let, I have three numbers +00123.25 -00256.54 +00489.23 I need to sum up all those three numbers, after storing them in three variables (say var1, var2, var3). I used both expr and BC, but they didn't work for me. But, I am not able to sum up them, as I don't have any idea how to... (13 Replies)
Discussion started by: mady135
13 Replies

7. Shell Programming and Scripting

Splitting a file based on positive and negative numbers

Dear All, I have to split a tab delimited file in two files based on the presence of a positive or negative in column number 9 , for example file: A 1 5 erg + 6766 0.9889 0.9817 9.01882 erg inside upstream B 1 8 erg2 + 6766 0.9889 0.9817 -9.22 erg2 inside... (3 Replies)
Discussion started by: paolo.kunder
3 Replies

8. Shell Programming and Scripting

Print smallest negative number with corresponding index from a column

considering the following table: ID col1 col2 col3 col4 1 -16.06801249 13.49785832 -56.57087607 -27.00500526 2 -1.53315720 0.71731735 -42.03602078 -39.78554623 3 -1.53315190 0.71731587 -42.03601548 ... (3 Replies)
Discussion started by: Birda
3 Replies

9. UNIX for Beginners Questions & Answers

Converting negative number to positive in a file

Hi ALL, I am having semi column separated file as below. I am having negative values for the records starting with 11095. How can I convert that positive number I tried this below seems not working sed 's/ \(*\)$/ -\1/;t;s/\(.*\)-/\1/ myfile myfile... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies

10. UNIX for Beginners Questions & Answers

Splitting a file based on negative and positive numbers

I have a file that is pipe delimited and in Column F they have number values, both positive and negative. I need to take the one file I am starting with and split it into two separate files based on negative and positive numbers. What is the command to do so? And then I need to also transfer... (4 Replies)
Discussion started by: cckaiser15
4 Replies
All times are GMT -4. The time now is 11:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy