dni*_*693 3 unix shell bioinformatics text-files genome
我正在使用unix shell脚本进行基因组构建,然后创建系统发育。根据您使用的基因组组装器,最终输出(系统发育)可能会发生变化。我希望比较使用各种基因组组装器的效果。我已经制定了一些指标进行比较,但是我需要组织它们的帮助,这样我才能进行有用的分析。我想在列中将数据导入excel。
这是我用来输出数据的脚本:
echo "Enter the size (Mb or Gb) of your data set:"
read SIZEOFDATASET
echo "The size of your data set is $SIZEOFDATASET"
echo "Size of Data Set:" >> metrics_file.txt
echo $SIZEOFDATASET >> metrics_file.txt
echo "Enter the name of your assembler"
read NAMEOFASSEMBLER
echo "You are using $NAMEOFASSEMBLER as your assembler"
echo "Name of Assembler:" >> metrics_file.txt
echo "$NAMEOFASSEMBLER" >> metrics_file.txt
echo "Time:" >> metrics_file.txt
Run Code Online (Sandbox Code Playgroud)
输出结果如下所示:
Size of Data Set:
387 Mb
Name of Assembler:
Velvet
Genome Size:
1745690
Time:
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像这样:

提前致谢!
#!/bin/sh
in_file=in.txt # Input file
params=3 # Parameters count
res_file=$(mktemp) # Temporary file
sep=' ' # Separator character
# Print header
cnt=0
for i in $(cat $in_file | head -$((params*2))); do
if [ $((cnt % 2)) -eq 0 ]; then
echo $i
fi
cnt=$((cnt+1))
done | sed ":a;N;\$!ba;s/\n/$sep/g" >>$res_file
# Parse and print values
cnt=0
for i in $(cat $in_file); do
# Print values, skip param names
if [ $((cnt % 2)) -eq 1 ]; then
echo -n $i >>$res_file
fi
if [ $(((cnt+1) % (params*2))) -eq 0 ]; then
# Values line is finished, print newline
echo >>$res_file
elif [ $((cnt % 2)) -eq 1 ]; then
# More values expected to be printed on this line
echo -n "$sep" >>$res_file
fi
cnt=$((cnt+1))
done
# Make nice table format
cat $res_file | column -t
rm -f $res_file
Run Code Online (Sandbox Code Playgroud)
该脚本假定:
大多数代码只是解析您的输入数据格式。实际的列格式由column工具完成。
如果要将此表导出为excel,只需将sep变量更改为','并将结果输出保存到.csv文件。此文件可以轻松导入excel应用程序。
输入文件:
Size
387
Name
Velvet
Time
13
Size
31415
Name
Minia
Time
18
Size
31337
Name
ABCDEF
Time
42
Run Code Online (Sandbox Code Playgroud)
脚本输出:
Size Name Time
387 Velvet 13
31415 Minia 18
31337 ABCDEF 42
Run Code Online (Sandbox Code Playgroud)