3

I am using the Tracer software package (https://github.com/Teichlab/tracer). The program is invoked as followed:

tracer assemble [options] <file_1> [<file_2>] <cell_name> <output_directory>

The program runs on a single dataset and the output goes to /<output_directory>/<cell_name>

What I want to do now is run this program on multiple files. To do so this is what I do:

for filename in /home/tobias/tracer/datasets/test/*.fastq
do
echo "Processing $filename file..."
python tracer assemble --single_end --fragment_length 62 --fragment_sd 1 $filename Tcell_test output; 
done

This works in priciple, but as cell_name is static, every iteration overwrites the output from the previous iteration. How do I need to change my script in order to give the output folder the name of the input file?

For example: Input filename is tcell1.fastq. For this cell_name should be tcell1. Next file is tcell2.fastq and cell_name should be tcell2, and so on...

2 Answers 2

1

I think this will do it, in bash, if I understand correctly -

for filename in /home/tobias/tracer/datasets/test/*.fastq
do
  echo "Processing $filename file..."
  basefilename="${filename##*/}"   #<--- 
  python tracer assemble --single_end --fragment_length 62 --fragment_sd 1 "$filename" "${basefilename%.fastq}" output;
  #                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^
done

${filename##*/} removes the part up to the last /, and ${basefilename%.fastq} removes the .fastq at the end.

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

1 Comment

@baracus37 Glad to hear it, and welcome to the site!
0

From what I understood the library you use writes output to predefined (non configurable) directory

Let's call it output_dir. At each iteration you should rename the output directory.

So your code should be something like this (pseudo code)

for filename in /home/tobias/tracer/datasets/test/*.fastq
   do
     echo "Processing $filename file..."
     python tracer assemble --single_end --fragment_length 62 --fragment_sd 1 $filename Tcell_test output; 
     rename  output_dir , each_file + "_output_dir"
   done

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.