I'm trying to run a bash for loop in a cell of my Jupyter notebook. I can re-write the command on one line and prefix it with !
and it runs fine, but I like the format for readability (teaching notebook). Using the %%bash
magic command doesn't seem to work.
%%bash
for sample in $(cat samples)
do
echo "On sample: $sample"
cutadapt
-g ^GTGYCAGCMGCCGCGGTAA
-G ^CCGYCAATTYMTTTRAGTTT
-m 209 -M 255
--too-short-output untrimmed_fastq/${sample}_R1_too-short.fastq.gz
--too-long-output untrimmed_fastq/${sample}_R1_too-long.fastq.gz
--untrimmed-output untrimmed_fastq/${sample}_R1_untrimmed.fastq.gz
--too-short-paired-output untrimmed_fastq/${sample}_R2_too-short.fastq.gz
--too-long-paired-output untrimmed_fastq/${sample}_R2_too-long.fastq.gz
--untrimmed-paired-output untrimmed_fastq/${sample}_R2_untrimmed.fastq.gz
-o trimmed_fastq/${sample}_R1_001.fastq.gz -p trimmed_fastq/${sample}_R2_001.fastq.gz
fastqfiles/${sample}_R1_001.fastq.gz fastqfiles/${sample}_R2_001.fastq.gz
>> cutadapt_stats.txt 2>&1
done
Yields the syntax error:
File "<ipython-input-3-592002da22aa>", line 3
for sample in $(cat samples)
^
SyntaxError: invalid syntax
I'm fairly new to using magic commands and subprocesses. Thank you for any tips or insight
question from:
https://stackoverflow.com/questions/65894547/executing-bash-for-loop-in-a-python-jupyter-notebook-cell 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…