【发布时间】:2019-12-04 00:05:49
【问题描述】:
我正在运行以下代码来操作 vcf 表中的数字数据。
cat inputfile | while read row; do
echo $row > tmp
originalProb= `awk '{print $1}' tmp`
probabilityHom1=`awk '{print $2}' tmp`
probabilityHom2=`awk '{print $4}' tmp`
numCols=`awk '{print NF}' tmp`
if [ $numCols -gt 4 ]; then
echo "${originalProb}" >> currentRowGenotypes
elif [ "$probabilityHom1" -gt "$probabilityHom2" ]; then
echo "1/1" >> currentRowGenotypes
elif [ "$probabilityHom1" -lt "$probabilityHom2" ]; then
echo "0/0" >> currentRowGenotypes
elif [ "$probabilityHom1" -eq "$probabilityHom2" ] && [ "$probabilityHom1" -eq 0 ]; then
echo "${originalProb}" >> currentRowGenotypes
else
echo "het" >> currentRowGenotypes
fi
done
cat tmpHeaders currentRowGenotypes > currentFullCol
输入文件如下所示
1/1 255 231 0
0/1 255 0 152
0/1 255 0 82
0/1 255 0 151
0/1 239 0 31
0/1 255 0 255
由于某种原因,awk 命令无法识别第一列。有什么建议吗?
【问题讨论】:
-
"originalProb= `awk '{print $1}' tmp`" - bash 可以识别空格,
=后面有一个空格。请使用$(...)而不是反引号` -
同上,但所有这些都可以是一个 awk 脚本。见grymoire.com/Unix/Awk.html。祝你好运。
标签: bash unix bioinformatics vcf-variant-call-format