0

I aimed to open multiple files (one by one, using for loop in bash terminal) and modify it using PLINK (a programme) and later on, python function. Following are the codes:

for i in {1..10}; do
  plink --cow --noweb --lfile $i --extract extract1.snp --recode --out 1$i
  python -c 'import file_convert;file_convert.convert_tree_mix("1$i.map","tmp$i")'
done

But, as expected, python could not read and could not open "11.map", it did not replace "$i" with 1. How can i modify the code so that python function, in combination with for loop, open different file each time based on the value of "i"

1
  • try python -c "import file_convert;file_convert.convert_tree_mix(\"1$i.map\",\"tmp$i\")" Commented May 29, 2015 at 13:47

2 Answers 2

3

Have you tried calling python like that:

python -c 'import sys; import file_convert;file_convert.convert_tree_mix(sys.argv[1],sys.argv[2])' "1$i.map" "tmp$i";

?

Sign up to request clarification or add additional context in comments.

1 Comment

In general, this is better than trying to use shell interpolation to build a dynamic string for Python to execute.
0

You need to include the whole python code inside double quotes, so that the $1 inside the python code will expand. $1 in shell refers to the first parameter.

python -c "import file_convert;file_convert.convert_tree_mix(\"1$i.map\",\"tmp$i\")"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.