在Linux中运行管道

在Linux中运行管道

我有这个脚本

#!/bin/bash
module load bedtools/2.21.0
bamfiles=(
/temp/hgig/fi1d18/1672_WTSI-COLO_023_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_023_1pre.dupmarked.bam
/temp/hgig/fi1d18/1672_WTSI-OESO_005_w3/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-OESO_005_w3.dupmarked.bam
/temp/hgig/fi1d18/1672_WTSI-OESO_036_2post/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-OESO_036_2post.dupmarked.bam
/temp/hgig/fi1d18/1672_WTSI-COLO_021_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_021_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_027_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_027_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_011_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_011_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_176_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_176_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_170_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_170_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_141_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_141_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLIVM_005_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLIVM_005_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_099_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_099_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_085_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_085_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_075_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_075_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_027_a_RNA/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_027_a_RNA.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_021_a_RNA/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_021_a_RNA.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-OESO_036_a_RNA/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-OESO_036_a_RNA.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_005_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_005_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_023_a_RNA/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_023_a_RNA.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-OESO_121_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-OESO_121_1pre.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-OESO_013_a_RNA/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-OESO_013_a_RNA.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-OESO_005_a_RNA/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-OESO_005_a_RNA.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_011_a_RNA/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_011_a_RNA.dupmarked.bam 
/temp/hgig/fi1d18/1672_WTSI-COLO_019_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_019_1pre.dupmarked.bam
)

for file in "${bamfiles[@]}"; do
    fname=$(basename "$file")
    fdir=$(dirname "$file")
    bamtofastq -i "$file" -fq "${fdir}/${fname%.bam}.fq"
done

我运行这个

[fi1d18@cyan01 ~]$ chmod +x run.sh

[fi1d18@cyan01 ~]$ run.sh
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
basename: invalid option -- 's'
Try `basename --help' for more information.
./run.sh: line 30: bamtofastq: command not found
[fi1d18@cyan01 ~]$


[fi1d18@cyan01 ~]$ run.sh
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
./run.sh: line 32: bamtofastq: command not found
[fi1d18@cyan01 ~]$

答案1

鉴于您的问题中的信息有限,并假设您的bamtofastq命令是这个从 bedtools 包中,我提出了以下内容:

#!/bin/bash

bamfiles=(
    /path/to/file1.bam
    /path/to/file2.bam
    /path/to/file3.bam
)

for file in "${bamfiles[@]}"; do
    fname=$(basename "$file")
    fdir=$(dirname "$file")
    bedtools bamtofastq -i "$file" -fq "${fdir}/${fname%.bam}.fq"
done

这假设您想要手动将所有 bam 文件塞入脚本中,并希望 .fq 文件与其相应的 bam 文件位于同一目录中。如果情况并非如此,请提供更多信息,以帮助我们更有效地回答您的问题。

相关内容