mirrored from https://gitlab.com/LPCDRP/biodiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
udiff2vcf
executable file
·91 lines (84 loc) · 1.89 KB
/
udiff2vcf
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename;
my $ref_id;
while (<>) {
my $line = $_;
chomp($line);
HEADER:
if ($line =~ /^(\-{3}|\+{3}) (\S+)/) {
$ref_id = basename($2);
next;
} elsif ($line =~ /^\@{2}/) {
my (
undef,
$ref_coords,
$qry_coords,
undef
) = split(' ',$line);
# Remove the minus/plus signs from the front
$ref_coords = substr($ref_coords,1);
$qry_coords = substr($qry_coords,1);
my ($ref_pos, $ref_ind) = split(",",$ref_coords);
$ref_ind = 1 if not defined($ref_ind);
my ($new_pos, $qry_ind) = split(",",$qry_coords);
$qry_ind = 1 if not defined($qry_ind);
my ($del, $ins) = ('', '');
my ($context_a, $context_b);
my ($i,$j) = (1,1);
while ($i <= $ref_ind && $j <= $qry_ind) {
$line = <>;
chomp($line);
if ($line =~ /^\-{1}/) {
$del = $del . substr($line,1);
$i++;
} elsif ($line =~ /^\+{1}/) {
$ins = $ins . substr($line,1);
$j++;
} elsif ($line =~ /^\s{1}/) {
if ($i==$ref_ind && $j==$qry_ind) {
$context_b = substr($line,1);
$context_a = '' if not defined($context_a);
} elsif ( $i==1 && $j==1 ) {
$context_a = substr($line,1);
} else {
# insert and delete the same base
# This is part of the same "hunk" and so is probably
# part of the same event
$ins = $ins . substr($line,1);
$del = $del . substr($line,1);
}
$i++;
$j++;
}
}
# SNP - we don't need context for them
if (length($ins) == length($del)) {
$ref_pos = $ref_pos + length($context_a);
$context_a = '';
$context_b = '';
}
VCFPRINT:
print(
join("\t",(
$ref_id,
$ref_pos,
".",
$context_a . $del . $context_b,
$context_a . $ins . $context_b,
".",
"PASS",
"."
)
)."\n"
);
}
elsif ($line =~ /^Only in/ || $line =~ /^diff/) {
next;
}
else {
print $_;
die;
}
}