forked from gringer/bioinfscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
align2csv.pl
executable file
·47 lines (44 loc) · 1 KB
/
align2csv.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
use warnings;
use strict;
print("SeqID,RefID,Pos,Ref,Alt\n");
while(<>){
if(/^#/){
next;
}
chomp;
my ($nameR, $nameQ, $score, $seqRef, $seqDiff, $seqQry) = split(/\t/, $_);
my $refPos = 0;
my $ins = ""; # false
my $del = ""; # false
my $indelPos = -1;
for(my $i = 0; $i < length($seqRef); $i++){
my $r = substr($seqRef, $i, 1);
my $d = substr($seqDiff, $i, 1);
my $q = substr($seqQry, $i, 1);
if($r ne "-"){
$refPos++;
if(($q ne "-") && ($ins || $del)){
printf("%s,%s,%05d,%s,%s\n", $nameQ, $nameR, $indelPos, $del, $ins);
$ins = ""; # false
$del = ""; # false
$indelPos = -1;
}
}
if($r eq "-"){
$ins .= $q;
if($indelPos == -1){
$indelPos = $refPos+1;
}
}
if($q eq "-"){
$del .= $r;
if($indelPos == -1){
$indelPos = $refPos;
}
}
if(!($ins || $del) && ($r ne $q)){
printf("%s,%s,%05d,%s,%s\n", $nameQ, $nameR, $refPos, $r, $q);
}
}
}