在使用子流程的python脚本中,将sed与变量一起使用

在使用子流程的python脚本中,将sed与变量一起使用,python,sed,Python,Sed,我想在python脚本中使用sed或tr在fastafile中引入一个ID 我试过了,但上面说syntaxError: subprocess.call(['sed's/>/>'+identifier+'/g\'transcriptome')],shell=True) 其中标识符和路径是变量。它必须是循环的一部分,对于每个ID和引入的路径,它必须更改tipical fasta格式:>isotig123到>IDisotig123。每个都有相应的ID 谢谢。试试这个 subprocess.call([

我想在python脚本中使用sed或tr在fastafile中引入一个ID

我试过了,但上面说syntaxError:

subprocess.call(['sed's/>/>'+identifier+'/g\'transcriptome')],shell=True)

其中标识符和路径是变量。它必须是循环的一部分,对于每个ID和引入的路径,它必须更改tipical fasta格式:>isotig123到>IDisotig123。每个都有相应的ID

谢谢。

试试这个

subprocess.call(['sed -e "s/>/>'+identifier+'/g" '+path+' >transcriptome')],shell=True)
  • 将sed操作周围的
    \'
    替换为

  • 替换
    sed命令及其参数之间缺少空格。请尝试以下操作:

    subprocess.call(['sed \'s/>/>'+identifier+'/g\' <'+path+'>transcriptome')],shell=True)
    
    subprocess.call(['sed's/>/>'+identifier+'/g\'transcriptome'),shell=True)
    
    对不起,问题是我该怎么做。试着打印您输入到
    call
    的字符串,看看它是否与您认为的匹配。另外,您知道Python有一个
    re
    模块,可用于正则表达式匹配和替换吗?