-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_vcf_2_bed
executable file
·76 lines (56 loc) · 1.13 KB
/
convert_vcf_2_bed
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
#!/usr/bin/perl
use warnings;
use strict;
use POSIX qw(ceil floor);
use File::Basename;
use File::Path;
use Getopt::Long;
use Pod::Usage;
=head1 NAME
convert_vcf_2_bed
=head1 SYNOPSIS
convert_vcf_2_bed [options] <filename>
-v verbose
-d debug
-o output contig directory.
usage: convert_vcf_2_bed input.vcf
Converts a VCF file into a corresponding bed file.
=head1 DESCRIPTION
=cut
#option variables
my $help;
my $outputBEDFile;
#initialize options
Getopt::Long::Configure ('bundling');
if(!GetOptions ('h'=>\$help,
'o:s'=>\$outputBEDFile)
|| scalar(@ARGV)!=1)
{
if ($help)
{
pod2usage(-verbose => 2);
}
else
{
pod2usage(1);
}
}
if ($outputBEDFile =~ /bed.gz$/)
{
open(OUT, "| bgzip -c > $outputBEDFile");
}
else
{
open(OUT, ">$outputBEDFile");
}
my $inputVCFFile = $ARGV[0];
open(IN, "vt view $inputVCFFile |") || die "Cannot open $inputVCFFile";
while (<IN>)
{
chomp;
my ($chrom, $pos, $id, $ref, $alt, $others) = split("\t");
--$pos;
print OUT "$chrom\t$pos\t" . (length($ref)+$pos) . "\n";
}
close(IN);
close(OUT);