#!/usr/bin/perl
use strict;
use warnings;
my ($clnv, $ofold)= @ARGV;

####$clnv : variant_summary.txt : downloaded from: ftp://ftp.ncbi.nlm.nih.gov/pub/clinvar/tab_delimited/######
####$ofold : Output folder##########

my $outfile = $ofold."hg19_Clinical_significant_variant_subcat_02122019.txt";
open (OUT,">$outfile")or die "Can't open $!";

my $stats = $ofold."hg19_Clinical_significant_variant_stats.txt";
open (ST,">>$stats")or die "Can't open $!";

my $count = 0;

my $c = 0;
print OUT "SNPID\tChromosome\tStart\tStop\tRef Allele\tAlt Allele\tGene\tclin Significance\tPhenotype List\tNumberSubmitters\tSubmitterCategories\n";
open (F, "$clnv") or die "Can't open $!";
while (my $ip1 = <F>){
chomp ($ip1);
my @a = split(/\t/,$ip1);

if ($a[16] eq "GRCh37"){
$a[9]= "rs".$a[9];
print OUT $a[9]."\t".$a[18]."\t".$a[19]."\t".$a[20]."\t".$a[21]."\t".$a[22]."\t".$a[4]."\t".$a[6]."\t".$a[13]."\t".$a[25]."\t".$a[29]."\n";
$c++;
}
$count++;
}

print ST "The number of GRCh37 variants :".$c."\n";
print ST "Total number of variants in CLINVAR :".$count."\n";
