Commit ee5a9e74 authored by flothoni's avatar flothoni

fuse.py; Allow to add option for preprocess script execution

Now, preprocess can have more option by this modification
BUT preprocess script should also take -i/-o args for execution
parent 8270d149
Pipeline #169486 passed with stage
in 19 seconds
......@@ -1466,13 +1466,17 @@ def exec_command(command, directory, input_file):
Returns the output filename (a .vidjil).
'''
# split command
soft = command.split()[0]
args = command[len(soft):]
assert (not os.path.sep in command), "No {} allowed in the command name".format(os.path.sep)
ff = tempfile.NamedTemporaryFile(suffix='.vidjil', delete=False)
basedir = os.path.dirname(os.path.abspath(sys.argv[0]))
command_fullpath = basedir+os.path.sep+directory+os.path.sep+command
com = '%s %s %s' % (quote(command_fullpath), quote(os.path.abspath(input_file)), ff.name)
print(com)
command_fullpath = basedir+os.path.sep+directory+os.path.sep+soft
com = '%s %s -i %s -o %s' % (quote(command_fullpath), args, quote(os.path.abspath(input_file)), ff.name)
print("Preprocess command: \n%s" % com)
os.system(com)
print()
return ff.name
......@@ -1506,7 +1510,8 @@ def main():
group_options.add_argument('--first', '-f', type=int, default=0, help='take only into account the first FIRST files (0 for all) (%(default)s)')
group_options.add_argument('--pre', type=str,help='pre-process program (launched on each input .vidjil file) (needs defs.PRE_PROCESS_DIR)')
group_options.add_argument('--pre', type=str,help='pre-process program (launched on each input .vidjil file) (needs defs.PRE_PROCESS_DIR). \
Program should take arguments -i/-o for input of vidjil file and output of temporary modified vidjil file.')
group_options.add_argument("--distribution", "-d", action='append', type=str, help='compute the given distribution; callable multiple times')
group_options.add_argument('--distributions-all', '-D', action='store_true', default=False, help='compute a preset of distributions')
......
#!/bin/bash
INPUT=$1
OUTPUT=$2
sed 's/IGH/TRG/g' < "$INPUT" > "$OUTPUT"
LOCUS=TRG
while getopts ":i:o:l:" arg; do
case $arg in
i) INPUT=$OPTARG;;
o) OUTPUT=$OPTARG;;
l) LOCUS=$OPTARG;;
esac
done
# echo "s/IGH/$LOCUS/g < $INPUT > $OUTPUT"
sed "s/IGH/$LOCUS/g" < "$INPUT" > "$OUTPUT"
exit 0;
\ No newline at end of file
......@@ -4,11 +4,33 @@
cp ../../defs.py defs.py.tmp
echo "PRE_PROCESS_DIR='tests/data/pre_process'" >> ../../defs.py
python3 ../../fuse.py $FUSE_OPTIONS --pre igh-to-trg.sh ../../../algo/tests/data/results-two-clones-1-2.vidjil ../../../algo/tests/data/results-two-clones-1-2.vidjil; cat fused.vidjil
### Use a script to verify that an external script can be triggered
mv defs.py.tmp ../../defs.py
# First, verify init state
cat ../../../algo/tests/data/results-two-clones-1-2.vidjil
$ Init, correct number of IGH and TRG
0:TRG
6:IGH
# Apply a simple 'sed' script; IGH --> TRG
python3 ../../fuse.py $FUSE_OPTIONS --pre igh-to-trg.sh ../../../algo/tests/data/results-two-clones-1-2.vidjil ../../../algo/tests/data/results-two-clones-1-2.vidjil -o fused_preprocess_igh-to-trg.vidjil; cat fused_preprocess_igh-to-trg.vidjil
$ IGH should become TRG (-3 that come from "custom" field; not replicate after fuse)
3:TRG
0:IGH
python3 ../../fuse.py $FUSE_OPTIONS --pre "igh-to-trg.sh -l IGK" ../../../algo/tests/data/results-two-clones-1-2.vidjil ../../../algo/tests/data/results-two-clones-1-2.vidjil -o fused_preprocess_with_param.vidjil; cat fused_preprocess_with_param.vidjil
cat fused.vidjil
6:TRG
$ IGH should become IGK (-3 that come from "custom" field; not replicate after fuse; +3 from preprocess command print)
0:TRG
0:IGH
6:IGK
### Restore inital defs.py file
mv defs.py.tmp ../../defs.py
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment