[BioPython] how to using python to multiply call a program for caculation

Leighton Pritchard lpritc at scri.ac.uk
Wed Jul 30 08:00:50 UTC 2008


Hi Shulin,

I can't see in your code with the while condition where you are specifying
the residue on the command-line string: the variable 'abc' appears to be
undefined in your code:

calc = '/home/shulin/program/rescP/resc 1PGA.pdb  ' + abc

So the above should throw an error.

>From your code, the variable containing the residue number you want to use
in the command line appears to be 'i', and there are a number of ways you
can get your variable 'i' into the command-line string from there,
including:

calc = '/home/shulin/program/rescP/resc 1PGA.pdb  ' + str(i)
calc = '/home/shulin/program/rescP/resc 1PGA.pdb %d' % i
calc = ' '.join(['/home/shulin/program/rescP/resc 1PGA.pdb', str(i)])


I've not tested the following code, but it may be the sort of thing you're
looking for:

# For this code you only need to import os
import os
# Define the command-line string components once
cmdexe = "/home/shulkin/program/rescP/resc"    # executable location
cmdstructure = "1PGA.pdb"                      # structure for analysis
# Then loop over the residue numbers, building a new command line
# and calling each time
for residue in range(1, 101):
    cmdstr = "%s %s %d > %d.txt" % (cmdexe, cmdstructure, residue, residue)
    #print cmdstr                 # does the command-line look right?
    os.system(cmdstr)             # make the system call
    
Sections of the Python documentation you might find useful here are:

string formatting
http://docs.python.org/lib/typesseq-strings.html

subprocess (which is favoured over os.system):
http://docs.python.org/lib/module-subprocess.html

And you may also be interested in the Python Tutor mailing list:
http://mail.python.org/mailman/listinfo/tutor

I hope this is useful,

L.

On 30/07/2008 01:34, "Shulin Zhuang" <shulin.zhuang at gmail.com> wrote:

> Dear All,
> 
> Here just disturb you a question.
> 
> I make a simple script to execute one program, the script content:
> 
> import string, re, sys, os, time, math
> calc = '/usr/local/bin/resc 1bmp.pdb 8 A > 8.txt '
> os.system(calc)
> 
> I can sucessfully execute this script and get the result file"8.txt.
> 
> 
> In the calc column,  8 is a residue number,  resc is a program. The aim is
> to use resc to calculate residue 8 and get the output 8.txt.
> 
> 
>  I want to calculate the whole residues from 1, 2, 3, ..... to 100, if I use
> above simple script, I should execute 100 times. Therefore, I want to write
> a script to let the python do all the calculations at one time.
> 
> Then I write the script as following:
> 
> import string, re, sys, os, time, math
> i = 1
> while i <=100:
>        calc = '/home/shulin/program/rescP/resc 1PGA.pdb  ' + abc
>        i = i +1
> os.system(calc)
> 
> 
> However, when I execute the script and get an error:"The first argument
> should bu numerical"
> 
> Would you like to tell me how to write a good script to tackle this problem.
> great thanks
> 
> Best regards
> _______________________________________________
> BioPython mailing list  -  BioPython at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biopython

-- 
Dr Leighton Pritchard MRSC
D131, Plant Pathology Programme, SCRI
Errol Road, Invergowrie, Perth and Kinross, Scotland, DD2 5DA
e:lpritc at scri.ac.uk       w:http://www.scri.ac.uk/staff/leightonpritchard
gpg/pgp: 0xFEFC205C       tel:+44(0)1382 562731 x2405

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

SCRI, Invergowrie, Dundee, DD2 5DA.  
The Scottish Crop Research Institute is a charitable company limited by guarantee. 
Registered in Scotland No: SC 29367.
Recognised by the Inland Revenue as a Scottish Charity No: SC 006662.


DISCLAIMER:

This email is from the Scottish Crop Research Institute, but the views 
expressed by the sender are not necessarily the views of SCRI and its 
subsidiaries.  This email and any files transmitted with it are confidential 
to the intended recipient at the e-mail address to which it has been 
addressed.  It may not be disclosed or used by any other than that addressee.
If you are not the intended recipient you are requested to preserve this 
confidentiality and you must not use, disclose, copy, print or rely on this 
e-mail in any way. Please notify postmaster at scri.ac.uk quoting the 
name of the sender and delete the email from your system.

Although SCRI has taken reasonable precautions to ensure no viruses are 
present in this email, neither the Institute nor the sender accepts any 
responsibility for any viruses, and it is your responsibility to scan the email 
and the attachments (if any).




More information about the Biopython mailing list