在非标签行上重复先前的标签和递增计数

Repeat previous label and increment count on non-label lines

我有以下包含基因名称和外显子位置的字符串。

gene1
250405..250551
251490..251884
195620..195641
154254..155469
156319..156548
gene2
171224..171481
403914..403970
147436..147627
149077..149157
11635..12021
gene3
107657..107844
105642..106214
103531..103691
407044..407435
405691..405843

我想编写一个脚本来列出所有基因名称和输出位置 那:

gene1_exon1 250405..250551
gene1_exon2 251490..251884
geneN_exonN X..Y 

有什么办法可以做到吗?

我试过以下脚本

grep [a-z] temp3 > names
cat names |
while read line; do
  cat temp3 |
  while read position; do
    if [ "$line" != "$position" ] ; then
      echo "$line" ${position} >> names_and_positions
    else
      break
    fi
  done
done

拉出基因名,在每个外显子行前重复。

awk '!/^[0-9]+\.\.[0-9]+$/ { gene=; i=1; next }
    { print gene "_exon" i++, [=10=] }' input >output

在看起来不像外显子行的行上,捕获第一个标记作为基因名称,并从 1 开始计算外显子行。在其他行(即外显子行)上打印包含捕获字符串的行和外显子行号前置,并增加数字。

这显然取决于正确使用正则表达式。如果您的外显子信息周围可能包含空格或其他变体,则您需要相应地调整正则表达式。