Python在理解如何使用';子流程';关于BLAST+;班内

Python在理解如何使用';子流程';关于BLAST+;班内,python,class,oop,subprocess,bioinformatics,Python,Class,Oop,Subprocess,Bioinformatics,我是一名Python初学者,在理解作业的措辞时遇到困难。它涉及面向对象编程和创建类。我已经在我的Windows 10计算机上安装了BLAST,因此我可以通过命令提示符访问它。为了方便起见,我用粗体输入了我的问题。以下是理解我将要做的事情所需的一般背景信息: “编写一个运行BLAST+的Python脚本,比较两种有机氮和甲烷代谢细菌的基因组,然后用图形表示排列 包括以下内容以执行主逻辑: 脚本执行的所有其他操作都应在类内完成。类外不应存在其他代码。” 从这一点上,我不明白为什么(\uuuu n

我是一名Python初学者,在理解作业的措辞时遇到困难。它涉及面向对象编程和创建类。我已经在我的Windows 10计算机上安装了BLAST,因此我可以通过命令提示符访问它。为了方便起见,我用粗体输入了我的问题。以下是理解我将要做的事情所需的一般背景信息:


“编写一个运行BLAST+的Python脚本,比较两种有机氮和甲烷代谢细菌的基因组,然后用图形表示排列

包括以下内容以执行主逻辑:

脚本执行的所有其他操作都应在类内完成。类外不应存在其他代码。”


从这一点上,我不明白为什么
(\uuuu name\uuu=“\ uuu main\uuuu”)
会出现(我也看到了一个关于这一点的问题,但答案太复杂了,无法理解;我没有足够的编码经验,因此希望对其进行更简单的解释)以及为什么类名为
main()
存在于该代码行下方。我以为应该先上这门课。另外,我知道如何使用BLAST网站,但不是以Python脚本或命令行参数的形式。


我遇到的一个问题是:

编写一个使用“subprocess”库执行“blastn”的方法,使用制表符分隔的输出对齐两个基因组。您需要查看BLAST+手册或程序的使用情况,以确定要使用哪些命令行选项。“subprocess”库有许多运行非python程序的方法。我们建议您使用
subprocess.run()
函数。“subprocess”代码必须使用
shell=False
参数,“blastn”对齐方式必须通过管道传输到Python脚本中,并且不应在磁盘上创建任何新文件

您的脚本应该期望第一个命令行参数是查询FASTA文件的路径,它应该是“file1.FASTA”。您的scrpt应该期望第二个命令行位置参数是subject FASTA,它应该是'file2.FASTA'

使用您的方法,使用三组不同的参数将查询与主题对齐:

一,。默认值

二,。字号为12;最多100000条路线;最大e值为0.001;开缺口罚款7分;差距扩大处罚3;错配罚款5英镑;比赛奖金为1英镑

三,。字号为10;最多1000条路线;最大e值为0.0001;开缺口罚款5英镑;差距扩大处罚为2;错配惩罚为3;比赛奖金2“


我从中了解到,我必须使用
子流程
从终端执行某些操作。这里的问题是我不知道如何使用
子流程
设置3个必需的参数

到目前为止,我掌握的代码如下:

class Main()
    def __init__(self): # we're using self so that we can refer to this function outside of this area # the default __init__ function is being redefined
        parameters = [___,___,___]
        self.alignments = []
        for p in parameters:
            self.alignments.append(self.align(p))

    def align(self,pars): 
        subprocess # I don't know what to add here
        # output is test of alignment objects

if (__name__ =="__main__"):
    Main() # Create an object of the main class
    # we don't need to do this:
    # m.align.seqs()
    # m.color = blue
    m = Main()
    m.align()
    m.parse()
    m.filter()
    m.make_dm()
我被要求使用大部分代码。if语句后面的注释行被给出了,所以我不知道如何解释这些

我试着用我的作业笔记来处理“子流程”,但它只是这样,对我没有帮助:

'''Example to run a shell process via a Python script and capture STDOUT'''

import subprocess

command_list = ['blastn', '-help']
cp = subprocess.run(command_list, shell=False, check=True, stdout=subprocess.PIPE)
output = cp.stdout.decode()

print('number of characters =', len(output))
print('number of lines =', len(output.splitlines()))
print('thread lines:')
for line in output.splitlines():
    if 'threads' in line:
        print(line)
我的问题:我应该如何在一个类中完成这一切,以及如何使用“subprocess”执行“blastn”来对齐两个基因组?说明中列出的3个参数应该放在空参数列表中,我不知道如何包含它们。

如果这很难理解,我深表歉意,但我试着询问了许多比我更了解Python的人,他们也被卡住了。如果我能澄清我提到的任何事情,请告诉我

评论:…我仍然不理解“main”以及在类中包含它的位置

\uuuu main\uuuu
无关
这只是一种习惯用法,用于在模块作为脚本运行时有条件地执行代码。将其视为main的起点。例如,在my_script.py中有以下3行代码。
python my_script.py
将开始执行
main()


阅读:

阅读:


阅读:

Ok,这对类的解释稍微好一点,但我仍然不理解“main”以及在类中包含它的位置,或者在该语句下面的行中编写什么代码。
'''Example to run a shell process via a Python script and capture STDOUT'''

import subprocess

command_list = ['blastn', '-help']
cp = subprocess.run(command_list, shell=False, check=True, stdout=subprocess.PIPE)
output = cp.stdout.decode()

print('number of characters =', len(output))
print('number of lines =', len(output.splitlines()))
print('thread lines:')
for line in output.splitlines():
    if 'threads' in line:
        print(line)
if __name__ == "__main__":
    # execute only if run as a script
    main()