Ran AJ
Ran AJ

Reputation: 1

Python include shell path filename

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

Upvotes: 0

Views: 49

Answers (2)

glenn jackman
glenn jackman

Reputation: 246744

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.

Upvotes: 0

Shipra
Shipra

Reputation: 1299

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

Upvotes: 1

Related Questions