【发布时间】:2023-04-09 03:49:01
【问题描述】:
我正在尝试解析一个输入文件(我的测试文件是 4 行),然后查询一个在线生物数据库。但是,在返回第一个结果后,我的循环似乎停止了。
#!/bin/bash
if [ "$1" = "" ]; then
echo "No input file to parse given. Give me a BLAST output file"
else
file=$1
#Extracts GI from each result and stores it on temp file.
rm -rf /home/chris/TEMP/tempfile.txt
awk -F '|' '{printf("%s\n",$2);}' "$file" >> /home/chris/TEMP/tempfile.txt
#gets the species from each gi.
input="/home/chris/TEMP/tempfile.txt"
while read -r i
do
echo GI:"$i"
/home/chris/EntrezDirect/edirect/esearch -db protein -query "$i" | /home/chris/EntrezDirect/edirect/efetch -format gpc | /home/chris/EntrezDirect/edirect/xtract -insd source o
rganism | cut -f2
done < "$input"
rm -rf /home/chris/TEMP/tempfile.txt
fi
例如,我唯一的输出是
GI:751637161
Pseudomonas stutzeri group
而我应该有 4 个结果。任何帮助表示赞赏并提前感谢。
这是示例输入的格式:
TARA042SRF022_1 gi|751637161|ref|WP_041104882.1| 40.4 151 82 2 999 547 1 143 2.8e-21 110.9
TARA042SRF022_2 gi|1057355277|ref|WP_068715547.1| 62.7 263 96 1 915 133 80 342 7.1e-96 358.6
TARA042SRF022_3 gi|950462516|ref|WP_057369049.1| 38.3 47 29 0 184 44 152 198 5.1e+01 36.2
TARA042SRF022_4 gi|918428433|ref|WP_052479609.1| 37.5 48 29 1 525 668 192 238 6.1e+01 37.0
【问题讨论】:
-
你可以尝试从
/dev/null重定向esearch的标准输入;在read -r i再次运行之前,它似乎正在读取输入文件的其余部分。esearch -db protein -query "$i" < /dev/null | .... -
你可以像这样简化你的 awk:
awk -F '|' '{print $2}'. -
@chepner 是的,这似乎是唯一的选择(除了理论上可以像
bash -e -o pipefail script.sh这样的脚本运行)。 -
@chepner 添加
< /dev/null工作,非常感谢! -
请注意,像 Biopython 这样的一些生物信息学库提供了一些方便的接口来解析 Blast 结果。
标签: bash loops bioinformatics