Question: Code for iteratively executing an alignment package (Kallisto) on multiple files in a directory and uniquely creating an output file
0
gravatar for achamess
2.9 years ago by
achamess40
United States
achamess40 wrote:

Hi,

I'm a novice at RNA-Seq data analysis, and I have a little experience using the command line to do things on my computer.

I'm using Kallisto to align fastq files for RNA-Seq. I know that it is possible to just write a shell script to apply Kallisto to all the fastq files I have in a folder, but I'm not exactly sure how to do this.

In pseudocode, I want to do this:

for [each file] in [directory]; do kallisto quant file_x > file_x_aligned; done

Where I'm stuck is in naming each of the output files uniquely. I'm sure there is an easy way to do this, but it's not coming to me. Sorry for the noob question. Any help would be greatly appreciated.

rna-seq • 1.9k views
ADD COMMENTlink modified 2.5 years ago by lazappi0 • written 2.9 years ago by achamess40
1

See this thread for ideas: bash loop for alignment RNA-seq data @Ram's solution explains how you can grab parts of the sample file name and use those for output.

ADD REPLYlink written 2.9 years ago by genomax64k

Thank you. I think I may have made a workable solution.

for file in *.fastq; do kallisto quant -i transcriptome.idx --single -l 300 -s 20 -b 100 -o $file-aligned  "$file"; done
ADD REPLYlink written 2.9 years ago by achamess40

What I find most intuitive (but your solution seems fine): (hypothetical example)

for file in *.fastq
do
outname=$(echo $file | sed 's/.fastq/.kallisto/' ) #various manipulations with sed or tr or cut possible
kallisto quant -i transcriptome.idx --single -l 300 -s 20 -b 100 -o $outname  $file
done
ADD REPLYlink written 2.9 years ago by WouterDeCoster37k
0
gravatar for lazappi
2.5 years ago by
lazappi0
Australia
lazappi0 wrote:

For anyone that doesn't want to build their own solution I have written a Python script to do this: https://github.com/lazappi/binf-scripts/blob/master/kallistoMulti.py.

ADD COMMENTlink written 2.5 years ago by lazappi0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 792 users visited in the last hour