美文网首页
探针寻找之旅(6)——AWK胜任统计比对结果

探针寻找之旅(6)——AWK胜任统计比对结果

作者: 嗒嘀嗒嗒嘀嗒嘀嘀 | 来源:发表于2020-03-24 23:46 被阅读0次

    研究了一番Linux的awk工具,感觉发现了个宝贝。“听说你厉害,但没想到你这么厉害!”
    Shell脚本奉上

    awk 'BEGIN{i=1} {
    if ($1=="CsCen1-"i) {
      if ($3==100 && $4==15) {
        print $0 >> "cscen1s.id1.0co15bp"}; 
    }
    else if ($1=="#")
      next;
    else {
      ++i;
      if ($3==100 && $4==15) {
        print $0 >> "cscen1s.id1.0co15bp"}; 
    }
    }' cscen1s.out7
    
    awk 'BEGIN{print "CsCen1-i" FS "chr1" FS "chr2" FS "chr3" FS "chr4" FS "chr5" FS "chr6" FS "chr7" FS "chr8" FS "chr9" FS "chrUn" FS "total" >> "cscen1s.id1.0co15bp.stat"; 
    i=1;chrUn=0; chr1=0; chr2=0; chr3=0; chr4=0; chr5=0; chr6=0; chr7=0; chr8=0; chr9=0; total=0} 
    {
    if ($1=="CsCen1-"i) {
      ++total; 
      if ($2=="chrUn") ++chrUn; 
      else if ($2=="chr1") ++chr1; 
      else if ($2=="chr2") ++chr2; 
      else if ($2=="chr3") ++chr3; 
      else if ($2=="chr4") ++chr4; 
      else if ($2=="chr5") ++chr5; 
      else if ($2=="chr6") ++chr6; 
      else if ($2=="chr7") ++chr7; 
      else if ($2=="chr8") ++chr8; 
      else if ($2=="chr9") ++chr9; 
    } 
    else{
      print i FS chr1 FS chr2 FS chr3 FS chr4 FS chr5 FS chr6 FS chr7 FS chr8 FS chr9 FS chrUn FS total >> "cscen1s.id1.0co15bp.stat"; 
      ++i; chrUn=0; chr1=0; chr2=0; chr3=0; chr4=0; chr5=0; chr6=0; chr7=0; chr8=0; chr9=0; total=0; 
      ++total; 
      if ($2=="chrUn") ++chrUn; 
      else if ($2=="chr1") ++chr1; 
      else if ($2=="chr2") ++chr2; 
      else if ($2=="chr3") ++chr3; 
      else if ($2=="chr4") ++chr4; 
      else if ($2=="chr5") ++chr5; 
      else if ($2=="chr6") ++chr6; 
      else if ($2=="chr7") ++chr7; 
      else if ($2=="chr8") ++chr8; 
      else if ($2=="chr9") ++chr9; 
    } 
    } 
    END {print i FS chr1 FS chr2 FS chr3 FS chr4 FS chr5 FS chr6 FS chr7 FS chr8 FS chr9 FS chrUn FS total >> "cscen1s.id1.0co15bp.stat"} ' cscen1s.id1.0co15bp
    
    • 经验教训
      ① “{}”后不加分号“;”
      ② 注意“{}”前后匹配
      ③ awk ' 后面不一定是{}, 结构应该为 awk 'BEGIN{ } { } END{ }'
      ④ 是BEGIN 不是 BEGAIN

    • 参考文章

    相关文章

      网友评论

          本文标题:探针寻找之旅(6)——AWK胜任统计比对结果

          本文链接:https://www.haomeiwen.com/subject/rqzoyhtx.html