The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Stuck on a matching, copying type problem derek3131 Shell Programming and Scripting 4 04-14-2008 06:18 PM
getting type of variable aladdin Shell Programming and Scripting 2 07-16-2007 08:52 AM
Human readable type vs MIME type detection using file spauldingsmails Shell Programming and Scripting 0 03-22-2007 12:43 AM
how to get type of variable in perl umen Shell Programming and Scripting 2 07-26-2006 10:29 PM
terminal type problem with cygwin on aix rein UNIX for Advanced & Expert Users 1 05-12-2005 05:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-06-2003
siavoush siavoush is offline
Registered User
  
 

Join Date: May 2002
Posts: 6
Question Problem with variable type

Dear All,

I am trying to write an script to calculate geometric centre of selected residues of a protein structure. Say I have a PDB file (a text containing the x, y, and z coordinates of atoms of a protein). I want to extract the X coordinates of the atoms belonging to the interested residues and get the Max and Min values for X coordinates and then calculate the X coordinate for the geometric centre as followings: X(cent) = (X(max) - X(min))/2. The same will go for Y(cent) and Z(cent). To do this it is better to have something to read in the X coordinates for the interested atoms from the X coordinate column in the PDB file and find the X(max) and X(min). The way that I do this is to read these values and put them in a file (say temp.dat). Then I sort the file ascending and descending based on different columns (i.e., x, y, and z colunms) and extract the max and min for X, Y and Z as you can see below:

****************************************************

#/bin/csh
echo -n "name of file (full path; incl. extension):"
set INFILE = $<
echo -n "name of output file (full path):"
set OUTFILE = $<
echo -n "Specify the starting residue number:"
set START = $<
echo -n "Specify the last residue number:"
set END = $<
@ END ++
@ START --
#
#
#
#
awk ' ($1 == "ATOM" && ( $5 > '$START' ) && ( $5 < '$END' )){{printf("%10.3f%10.3f%10.3f\n", $6, $7, $8)}};' $INFILE >>! $OUTFILE
#
sort $OUTFILE | set Xmin = `head -1 | awk '{printf("%10.3f\n", $1)};'`

sort -n +1 $OUTFILE | set Ymin = `head -1 | awk '{printf("%10.3f\n", $2)};'`

sort -n +2 $OUTFILE | set Zmin = `head -1 | awk '{printf("%10.3f\n", $3)};'`

sort -r $OUTFILE | set Xmax = `head -1 | awk '{printf("%10.3f\n", $1)};'`

sort -rn +1 $OUTFILE | set Ymax = `head -1 | awk '{printf("%10.3f\n", $2)};'`

sort -rn +2 $OUTFILE | set Zmax = `head -1 | awk '{printf("%10.3f\n", $3)};'`

echo $Xmin $Xmax $Ymin $Ymax $Zmin $Zmax
exit 1
**************************************************

The problem is that I can't use the Xmin, Xmax, Ymin, ... to calculate X(cent), Y(cent), and Z(cent), using "expr" command. E.g., for the following command, I get the following error:

>expr $Xmin - $Xmin

non-numeric argument

I guess there is something wrong with these variables and they are character strings and not numbers. I will appreciate it if you give me some input.

Cheers, Siavoush
  #2 (permalink)  
Old 09-06-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,123
For starters, expr only works with integers.

I'm not a csh expert, but your syntax looks wrong. I would have expected that you need to do something like:

set Xmin = `sort $OUTFILE | head -1 | awk '{printf("%10.3f\n", $1)};'`

Your algorithm is extremely inefficient. You should not sort the file at all. Initialize things by setting your min to a very large number and your max to a very small number (negative, but with a large absolute value). Then loop reading each value. If the value is less than the current min, it becomes the new min. If the value is larger than the current max, it becomes the new max. You should be able to get all 6 extrema with one pass of the unsorted file.

I would definately switch languages, probably to C. You really want a language with built in floating point support.

But you can do floating arithmetic by using bc. You need to echo in expressions and read the result. Try this command:
echo 1.5 + .5 | bc
to see what I mean.
  #3 (permalink)  
Old 09-07-2003
siavoush siavoush is offline
Registered User
  
 

Join Date: May 2002
Posts: 6
Dear Perderabo

Many thanks for your help. The bc command worked for me and script running ok. If I have some free time will work on it according to your suggestions in the C programming environment.

Cheers, Siavoush
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0