0

Here is my code in shell and I include python command:

for file in `ls $FOLDER`
do
    echo "$file"
    var=`python -c "from Bio import SeqIO, SeqUtils; import os; rec = SeqIO.read("**$FOLDER/$file**", 'fasta'); SeqUtils.xGC_skew(rec.seq, 220000)" `
done

And I do not know how to make python recognize my file name

Itamar Mushkin
  • 2,803
  • 2
  • 16
  • 32
Ran AJ
  • 1
  • 3
  • Are you getting any error? If yes, please add the error output in the question. – Shipra Oct 29 '19 at 11:09
  • Here is the error: Traceback (most recent call last): File "", line 1, in File "/home/criuser/anaconda2/lib/python2.7/site-packages/Bio/SeqIO/__init__.py", line 671, in read raise ValueError("More than one record found – Ran AJ Oct 29 '19 at 11:12
  • It is like it does not see my file and I do not know how to tell it '$FOLDER/$file' in a python way – Ran AJ Oct 29 '19 at 11:13

2 Answers2

1

You need to escape the double quotes in the python code:

for file in `ls $FOLDER`
do
    echo "$file"
    var=`python -c "from Bio import SeqIO, SeqUtils; import os; rec = SeqIO.read(\"$FOLDER/$file\", 'fasta'); SeqUtils.xGC_skew(rec.seq, 220000)" `
done
Shipra
  • 1,259
  • 2
  • 14
  • 26
0

I see some common shell mistakes:

  • Don't parse ls. Use
    for file in "$FOLDER"/*; ...
    
  • Use $(...) instead of `...` -- easier to read, easier to nest. Reference
  • Get out of the habit of using ALLCAPS variable names, leave those as reserved by the shell. One day you'll write PATH=something and then wonder why your script is broken.
glenn jackman
  • 238,783
  • 38
  • 220
  • 352