0

I would like to use sed or tr inside a python script to introduce an ID in the fastafile.

I've tried that but it says syntaxError:

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

where identifier and path are variables. It's must be part of a loop where for each ID and introduced path it has to change the tipical fasta format: >isotig123 to >IDisotig123. Each one with their corresponding ID.

Thanks.

emesday
  • 6,078
  • 3
  • 29
  • 46
Aleix Arnau
  • 61
  • 1
  • 3
  • Sorry, the question so is how can I do it. – Aleix Arnau Jun 02 '14 at 11:20
  • Try printing the string you feed to `call` to see if it matches what you think it is. Also, did you know Python has an `re` module that can be used for regular expression match and replace? – Fred Foo Jun 02 '14 at 11:45
  • Python can natively implement both `tr` and any `sed` script, especially a trivial substitution. – tripleee Oct 12 '21 at 10:58

2 Answers2

0

Try this

subprocess.call(['sed -e "s/>/>'+identifier+'/g" '+path+' >transcriptome')],shell=True)
  • replace \' by " around sed action
  • replace the < with direct file reference
  • add -e to use action command

Assuming Identifier does not contain special char &, \, / like in your sample

NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43
0

There is a whitspace missing between the sed command and its arguments. Try this:

subprocess.call(['sed \'s/>/>'+identifier+'/g\' <'+path+'>transcriptome')],shell=True)
miindlek
  • 3,523
  • 14
  • 25