I have a very basic problem, but my knowledge about python is very limited. I have a python script that takes several arguments in order to run (https://github.com/raphael-group/hotnet2/blob/master/bin/createPPRMat.py).
I would like to use a file with some filenames (one per line) as the first argument to be passed to the python script.
My first try to do it was creating a bash script (mat.sh) like this:
#!/bin/bash
for net in $(cat /home/hotnet2-1.0.0/iref/iref.list);
do
export
python createPPRMat.py -e `$net` -i /home/jfertaj/hotnet2-1.0.0/iref/iref_index_genes -o /home/jfertaj/Broad_Stay/hotnet2-1.0.0/iref_influence_matrices
done
However I got an error, the python script seems to not parse the $net variable:
createPPRMat_1.py: error: argument -e/--edgelist_file: expected one argument
mat.sh: line 6: /home/jfertaj/Broad_Stay/hotnet2-1.0.0/iref/iref_edgelist_139: No such file or directory
When I double quote the variable net in the bash script ("$net") the error I got is different, pointing out that something is wrong with the filename
Traceback (most recent call last):
File "/home/jfertaj/Broad_Stay/hotnet2-1.0.0/bin/createPPRMat_1.py", line 96, in <module>
run(get_parser().parse_args(sys.argv[1:]))
File "/home/hotnet2-1.0.0/bin/createPPRMat_1.py", line 38, in run
edges = [map(int, l.rstrip().split()[:2]) for l in open(args.edgelist_file)]
IOError: [Errno 2] No such file or directory: '\x1b[01;00m/home/hotnet2-1.0.0/iref/iref_edgelist_164\x1b[0m'
The content of iref.list looks like this:
/home/hotnet2-1.0.0/iref/iref_edgelist_1
/home/hotnet2-1.0.0/iref/iref_edgelist_10
/home/hotnet2-1.0.0/iref/iref_edgelist_100
And the iref.list file was created using cat -1 ... < iref.list
Any help would be very appreciated
Thanks
'\x1b[01;00m/home/hotnet2-1.0.0/iref/iref_edgelist_164\x1b[0m'this in the output looks like the file has color control codes in it. That's not a text file. You'll need to get a clean text file or strip those out before this will work.$netthe error I got is different? Well, maybe it is a really silly question...`$net`takes the value of the$netvariable and tries to run it as a shell command and replaces the backtick string with the output of the command. That's why you get the "no such file or directory" error there and why the-eargument doesn't have an argument (the backtick string evaluates to the empty string).