我正在使用 Red Hat Linux 服務器。我的最終目標是在多個 fasta 檔案上運行 CRB-BLAST,并從不同目錄中的檔案中獲取結果。
我的方法是使用 wget 下載 fasta 檔案,然后運行 ??CRB-BLAST。我有多個檔案,希望能夠將它們分別下載到自己的目錄(名稱可能來自 URL 串列檔案),然后運行 ??CRB-BLAST。
示例網址:
http://assemblies/Genomes/final_assemblies/10x_assemblies_v0.1/TC_3370_chr.v0.1.liftover.CDS.fasta.gz
http://assemblies/Genomes/final_assemblies/10x_assemblies_v0.1/TC_CB_chr.v0.1.liftover.CDS.fasta.gz
http://assemblies/Genomes/final_assemblies/10x_assemblies_v0.1/TC_13_chr.v0.1.liftover.CDS.fasta.gz
http://assemblies/Genomes/final_assemblies/10x_assemblies_v0.1/TC_37_chr.v0.1.liftover.CDS.fasta.gz
http://assemblies/Genomes/final_assemblies/10x_assemblies_v0.1/TC_123_chr.v0.1.liftover.CDS.fasta.gz
http://assemblies/Genomes/final_assemblies/10x_assemblies_v0.1/TC_195_chr.v0.1.liftover.CDS.fasta.gz
http://assemblies/Genomes/final_assemblies/10x_assemblies_v0.1/TC_31_chr.v0.1.liftover.CDS.fasta.gz
理想情況下,檔案名決定目錄名,例如TC_3370/.
我認為可能有一個解決方案cat URL.txt | mkdir | cd | wget | crb-blast
目前我只是在行中運行命令:
mkdir TC_3370
cd TC_3370/
wget url
http://assemblies/Genomes/final_assemblies/10x_meta_assemblies_v1.0/TC_3370_chr.v1.0.maker.CDS.fasta.gz
crb-blast -q TC_3370_chr.v1.0.maker.CDS.fasta.gz -t TCV2_annot_cds.fna -e 1e-20 -h 4 -o rbbh_TC
uj5u.com熱心網友回復:
試試這個Shellcheck -clean 程式:
#! /bin/bash -p
while read -r url; do
file=${url##*/}
dir=${file%%_chr.*}
mkdir -v -- "$dir"
(
cd "./$dir" || exit 1
wget -- "$url"
crb-blast -q "$file" -t TCV2_annot_cds.fna -e 1e-20 -h 4 -o rbbh_TC
)
done <URL.txt
- 請參閱洗掉部分字串(BashFAQ/100(如何在 bash 中進行字串操作?))以了解
${url##*/}等。 - 子shell (
( ... )) 用于確保cd不影響主程式。
uj5u.com熱心網友回復:
另一種實作
#!/bin/sh
# Read lines as url as long as it can
while read -r url
do
# Get file name by stripping-out anything up to the last / from the url
file_name=${url##*/}
# Get the destination dir name by stripping anything from the first __chr
dest_dir=${file_name%%_chr*}
# Compose the wget output path
fasta_path="$dest_dir/$file_name"
if
# Successfully created the destination directory AND
mkdir -p -- "$dest_dir" &&
# Successfully downloaded the file
wget --output-file="$fasta_path" --quiet -- "$url"
then
# Process the fasta file into fna
fna_path="$dest_dir/TCV2_annot_cds.fna"
crb-blast -q "$fasta_path" -t "$fna_path" -e 1e-20 -h 4 -o rbbh_TC
else
# Cleanup remove destination directory if any of mkdir or wget failed
rm -fr -- "$dest_dir"
fi
# reading from the URL.txt file for the whole while loop
done < URL.txt
uj5u.com熱心網友回復:
從串列中下載檔案是-i file選項的任務,如果您有一個名為 say 的檔案urls.txt,每行有一個 URL,您可以簡單地做
wget -i urls.txt
請注意,這會將所有檔案放在當前作業目錄中,因此如果您希望將它們放在單獨的目錄中,則需要在wget完成后移動它們。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/483468.html
