[笔记] sam文件挑取uniq reads

本来呢,samtools本来就可以一句话就能提取,只是没得网络没得下载samtools,只能保留自传脚本。

输入文件为raw.sam

输出为提取uniq reads后的uniq.sam(仍然保留着sam格式)

终端里会打印出简单的报告

 1 use strict;
 2 use warnings;
 3 
 4 my ($in, $out) = @ARGV; 
 5 die <DATA> unless (@ARGV == 2);
 6 open IN, "$in";
 7 open OUT, ">$out";
 8 
 9 my ($sum, $uniq, $xnd, $other) = (0,0,0,0); 
10 my $header;
11 while (<IN>){
12 
13     my ($a, $b) = (0, 0);
14     chomp;
15     if ($_ =~ /^\@/){
16         print OUT "$_\n";
17         $header ++;
18     }
19     else {$sum ++};
20     $a = 1 if (/AS:i/);
21     $b = 1 if (/XS:i/);
22     if ($a ==1 ){
23         if ($b == 0){
24             $uniq ++;
25             print OUT "$_\n";
26         }
27         if ($b == 1){
28             $xnd ++;
29         }
30     }
31     elsif ($a == 0){
32         $other ++;
33         #header number will counted in this list
34     }
35 }
36 print "input sam is : $in\n";
37 print "output uniq sam is : $out\n";
38 print "all reads num: $sum\n";
39 print "uniq reads num: $uniq\n";
40 print "2nd reads num: $xnd\n";
41 print "error reads num: " . ($other-$header) . "\n";
42 my $ratio = $uniq/$sum;
43 printf "uniq percentage: %.1f\n", ($ratio*100); 
44 
45 __DATA__
46 usage: ./sam_uniq_reads.pl <sam_input.sam> <uniq_reads_output.sam>

转载于:https://www.cnblogs.com/puriney/archive/2012/07/16/2593867.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值