I have a python script that I want to automate so I created a simple bash script (called mybash.sh).
#!/bin/sh
vars="C:\Users\Jane\Desktop\Work\variables.csv"
while IFS="," read gname gid
do
echo "Gene Name: $gname"
echo "Gene ID: $gid"
python alignment.py work_file $gid > C:\\Users\\Jane\\Desktop\\Work_Done\\$gname.fa
done < "$vars"
read -rn1
It is a huge script but I always get an error saying that the last line of my alignment.py script has a NameError, so after running my bash script from windows cmd prompt as >mybash.sh I get this:
Gene Name: cytb
Gene ID: ENSB0010011
Traceback (most recent call last):
File "alignment.py", line 99, in <module>
for species in geneDict:
NameError: name 'geneDict' is not defined
The geneDict is the very last part of the python script which simply creates a fasta alignment file for a gene for all species in separate folder. When I execute the python script normally in cmd prompt, it works perfectly fine but instead of extracting the gname (gene name) and gid (gene ID) from a variables file, I was typing it manually. I didn't want to do that for 200 genes. I can't understand why it no longer finishes and says that the geneDict is no longer defined?
Also, I tried making the python script run in a bash script alone as follows:
#!/bin/sh
python alignment.py work_file ENSB0010011 > C:\\Users\\Jane\\Desktop\\Work_Done\\cytb.fa
And this worked fine also, the python script did not stop working all of a sudden and my file came out. How do I make the python script execute without error, while pulling the variables from variables.csv separately so that I don't have to type it in manually?
The last bit of the python script is as follows:
for species in geneDict: # this is where it says geneDict is not defined
print '>' + species
print geneDict[species]
geneDict#!/bin/shin bash script file. This shebang means run this script withshin root subdirectorybin. On many Linux distributions fileshin/binis a symbolic link to shell interpreterbash, but can also link toshorkshor ... You might use#!/bin/bashto explicitly require the interpretation of this shell script by shell interpreterbash. But I really don't know how is predefined the Unix environment and which shebang should be used on Windows.alignment.pystored with LF or with CR+LF?