You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何对BLAST HitTable跨行列比较 按登录号分组判断序列区间重叠

可用awk单行解决方案

直接执行以下命令即可得到符合你需求的两个输出文件:

awk 'NR==1 {print > "nonover.txt"; print > "overlap.txt"; next} 
NR>1 && prev_id == $1 { 
    if (prev_end < $3) { 
        print prev_line >> "nonover.txt"
    } else { 
        print prev_line >> "overlap.txt"
        print $0 >> "overlap.txt"
    } 
} 
{ 
    prev_id = $1
    prev_end = $4
    prev_line = $0
} 
END {
    print prev_line >> "nonover.txt"
}' mydata.txt

逻辑说明

  • 表头行默认同时写入两个输出文件
  • 从第二行开始,仅对比同登录号的相邻行:
    • 上一行seqend小于当前行seqstart(无重叠):将上一行写入nonover.txt
    • 上一行seqend大于等于当前行seqstart(有重叠):将相邻两行都写入overlap.txt
  • 最后一行默认追加到nonover.txt,适配你后续自行去重的处理需求

适配空行分隔的优化版本

如果需要在不同登录号的重叠区间之间加空行,匹配你给出的示例输出格式,使用以下命令即可:

awk 'NR==1 {print > "nonover.txt"; print > "overlap.txt"; next} 
NR>1 && prev_id == $1 { 
    if (prev_end < $3) { 
        print prev_line >> "nonover.txt"
    } else { 
        if (overlap_flag[prev_id] != 1) {
            print "" >> "overlap.txt"
            overlap_flag[prev_id] = 1
        }
        print prev_line >> "overlap.txt"
        print $0 >> "overlap.txt"
    } 
} 
{ 
    prev_id = $1
    prev_end = $4
    prev_line = $0
} 
END {
    print prev_line >> "nonover.txt"
}' mydata.txt

内容的提问来源于stack exchange,提问作者Fitzy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 11:06:03