开发者

making a single script wrapping 3 python codes

开发者 https://www.devze.com 2023-03-04 04:14 出处:网络
I have 3 python codes which I want to call one after another automaticallyso that they result in the final in s single call.

I have 3 python codes which I want to call one after another automatically so that they result in the final in s single call. How do I wrap these codes into single script? codes are model-multiple.py, align2d.py, model-single.py.

model-multiple.py is

from modeller import *              # Load s开发者_JS百科tandard Modeller classes
from modeller.automodel import *    # Load the automodel class

log.verbose()    # request verbose output
env = environ()  # create a new MODELLER environment to build this model in


env.io.atom_files_directory = ['.', '../atom_files']

a = automodel(env,
alnfile  = '3NTD_align.ali', # alignment filename
knowns   = ('3NTDA'),    
sequence = 'target',        # code of the target
assess_methods=(assess.DOPE, assess.GA341,assess.normalized_dope))
a.starting_model= 1                 # index of the first model
a.ending_model  = 1              # index of the last model
                                    # (determines how many models to calculate)
a.make()                            # do the actual homology modeling


You have two options:

  1. The quick-and-dirty way: just call them one after another in a shell script or in a Python script (using system or subprocess.Popen)
  2. Make them do their work in some function, import them into a single script and invoke each module's "do work" function


If all three scripts are similar to your example, you can use the follow Python script to run them one after the other:

__import__('model-multiple')
import align2d
__import__('model-single')

__import__ is required because hyphens(-) are illegal in import names. If you're willing to rename the scripts:

import model_multiple
import align2d
import model_single


You should probably consider organizing your scripts in a way that is convenient for calling both from other scrips and directly. The general pattern is:

def main():
    # do all the work
if __name__ = '__main__':
    import sys
    sys.exit(main())
0

精彩评论

暂无评论...
验证码 换一张
取 消