我正在使用一个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当前的输出如下所示:
Size of Data Set:
387 Mb
Name of Assembler:
Velvet
Genome Size:
1745690
Time:我希望它看起来像这样:

提前感谢!
发布于 2015-02-27 08:21:18
#!/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解释
此脚本假定:
参数输入文件称为“
大部分代码只是解析您的输入数据格式。实际的列格式设置是由column工具完成的。
如果您想将此表导出到excel中,只需将sep变量更改为',',并将结果输出保存到.csv文件。该文件可以方便地导入到excel应用程序中。
示例
输入文件:
Size
387
Name
Velvet
Time
13
Size
31415
Name
Minia
Time
18
Size
31337
Name
ABCDEF
Time
42脚本输出:
Size Name Time
387 Velvet 13
31415 Minia 18
31337 ABCDEF 42发布于 2015-02-27 23:30:48
Sam的回答完全符合您的要求,但您也可以考虑使其更精简,避免将指标文件转换为表的需要,只需立即编写表即可。例如,像这样编写一个脚本,user_input.bash:
echo "Enter the size (Mb or Gb) of your data set:" > /dev/stderr
read SIZEOFDATASET
echo "The size of your data set is $SIZEOFDATASET" > /dev/stderr
echo "Enter the name of your assembler" > /dev/stderr
read NAMEOFASSEMBLER
echo "You are using $NAMEOFASSEMBLER as your assembler" > /dev/stderr
echo "Enter Time:" > /dev/stderr
read TIME
echo "You entered Time:" $TIME > /dev/stderr
echo "Name Size Time"
echo $NAMEOFASSEMBLER $SIZEOFDATASET $TIME要使用program:
./user_input.bash > metrics.file.1.txt
./user_input.bash > metrics.file.2.txt
./user_input.bash > metrics.file.3.txt
...collect all results:
head -n 1 metrics.file.1.txt > allmetrics.txt
tail -n +2 -q metrics.file.*.txt > allmetrics.txtHTH
https://stackoverflow.com/questions/28727449
复制相似问题