<commit_before>#! /usr/local/bin/perl
# Modified by Laurent the 01/12/2010

use strict;
#use DBH;
use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Variation::DBSQL::DBAdaptor;
use Bio::EnsEMBL::SimpleFeature;
use Bio::EnsEMBL::Utils::Exception qw(verbose throw warning);
use Bio::EnsEMBL::Utils::Argument qw( rearrange );
use Data::Dumper;
use Bio::SeqIO;
use FindBin qw( $Bin );
use Getopt::Long;
use ImportUtils qw(dumpSQL debug create_and_load load);
use DBI qw(:sql_types);
our ($species, $input_file, $source_name, $TMP_DIR, $TMP_FILE, $mapping, $registry_file);

GetOptions('species=s'     => \$species,
	   	   	 'input_file=s'  => \$input_file,
	   	   	 'source_name=s' => \$source_name,
	   	   	 'tmpdir=s'      => \$ImportUtils::TMP_DIR,
         	 'tmpfile=s'     => \$ImportUtils::TMP_FILE,
					 'mapping!'      => \$mapping,
					 'registry=s'    => \$registry_file
          );

$species ||= 'human';
$input_file ||= '/lustre/scratch103/ensembl/lg10/hgmd/2011.1-hgmd-public.tsv';
$source_name ||= 'HGMD-PUBLIC';

my $header = 'HGMD_PUBLIC';
my $ncbi_version = 'NCBI36';
   $registry_file ||= $Bin . "/ensembl.registry";
my $hgmd_url = 'http://www.hgmd.cf.ac.uk/ac/index.php';
my $insertion_label = 'I';

usage('-species argument is required') if(!$species);

$TMP_DIR  = $ImportUtils::TMP_DIR;
$TMP_FILE = $ImportUtils::TMP_FILE;

Bio::EnsEMBL::Registry->load_all( $registry_file );
my $cdb2 = Bio::EnsEMBL::Registry->get_DBAdaptor($species,'core');
my $vdb2 = Bio::EnsEMBL::Registry->get_DBAdaptor($species,'variation');
my $dbCore2 = $cdb2->dbc->db_handle;
my $dbVar2 = $vdb2->dbc->db_handle;

my $sa2 = $cdb2->get_SliceAdaptor();
my $buffer = {};
my $source_id;
my $source_description = 'Variants from HGMD-PUBLIC data';

my $month_hash = { 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April',
									 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August',
									 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December'
            		 };

my $new_source_ref = $dbVar2->selectall_arrayref(qq{SELECT source_id FROM source WHERE name = "$source_name"});
if ($new_source_ref->[0][0]) {
  $source_id = $new_source_ref->[0][0];
}
else {
	$input_file =~ /\/(\d{4})\.(\d+)-hgmd-public\.tsv$/;
	my $year      = $1;
	my $month_num	= $2;
	my $month     = $month_hash->{$month_num} if ($month_num);
	my $remapped;
	if ($mapping) {
		$remapped = " [remapped from build $ncbi_version]";
	}
	
	
	if ($year and $month) {
		$source_description .= " set $month $year";
		$month_num = '0'.$month_num if ($month_num<10);
  	$dbVar2->do(qq{INSERT INTO source(name,description,url,version)
									 values("$source_name","$source_description$remapped","$hgmd_url",$year$month_num)
									});
	}
	else {
		$dbVar2->do(qq{INSERT INTO source(name,description,url)<commit_msg>Updated the script to update the source in the source table<commit_after>#! /usr/local/bin/perl
# Modified by Laurent the 01/12/2010

use strict;
#use DBH;
use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Variation::DBSQL::DBAdaptor;
use Bio::EnsEMBL::SimpleFeature;
use Bio::EnsEMBL::Utils::Exception qw(verbose throw warning);
use Bio::EnsEMBL::Utils::Argument qw( rearrange );
use Data::Dumper;
use Bio::SeqIO;
use FindBin qw( $Bin );
use Getopt::Long;
use ImportUtils qw(dumpSQL debug create_and_load load);
use DBI qw(:sql_types);
our ($species, $input_file, $source_name, $TMP_DIR, $TMP_FILE, $mapping, $registry_file);

GetOptions('species=s'     => \$species,
	   	   	 'input_file=s'  => \$input_file,
	   	   	 'source_name=s' => \$source_name,
	   	   	 'tmpdir=s'      => \$ImportUtils::TMP_DIR,
         	 'tmpfile=s'     => \$ImportUtils::TMP_FILE,
					 'mapping!'      => \$mapping,
					 'registry=s'    => \$registry_file
          );

$species ||= 'human';
$input_file ||= '/lustre/scratch103/ensembl/lg10/hgmd/2011.1-hgmd-public.tsv';
$source_name ||= 'HGMD-PUBLIC';

my $header = 'HGMD_PUBLIC';
my $ncbi_version = 'NCBI36';
   $registry_file ||= $Bin . "/ensembl.registry";
my $hgmd_url = 'http://www.hgmd.cf.ac.uk/ac/index.php';
my $insertion_label = 'I';

usage('-species argument is required') if(!$species);

$TMP_DIR  = $ImportUtils::TMP_DIR;
$TMP_FILE = $ImportUtils::TMP_FILE;

Bio::EnsEMBL::Registry->load_all( $registry_file );
my $cdb2 = Bio::EnsEMBL::Registry->get_DBAdaptor($species,'core');
my $vdb2 = Bio::EnsEMBL::Registry->get_DBAdaptor($species,'variation');
my $dbCore2 = $cdb2->dbc->db_handle;
my $dbVar2 = $vdb2->dbc->db_handle;

my $sa2 = $cdb2->get_SliceAdaptor();
my $buffer = {};
my $source_id;
my $source_description = 'Variants from HGMD-PUBLIC data';

my $month_hash = { 1 => 'March', 2 => 'June', 3 => 'September', 4 => 'December' };

my $new_source_ref = $dbVar2->selectall_arrayref(qq{SELECT source_id FROM source WHERE name = "$source_name"});

$input_file =~ /\/(\d{4})\.(\d+)-hgmd-public\.tsv$/;
my $year      = $1;
my $month_num	= $2;
my $month     = $month_hash->{$month_num} if ($month_num);
my $remapped;
if ($mapping) {
	$remapped = " [remapped from build $ncbi_version]";
}
$source_description .= " set $month $year" if ($year and $month);

if ($new_source_ref->[0][0]) {
  $source_id = $new_source_ref->[0][0];
	$dbVar2->do(qq{UPDATE source SET description="$source_description$remapped", version=$year$month_num 
	               WHERE source_id=$source_id });
}
else {
	if ($year and $month) {
  	$dbVar2->do(qq{INSERT INTO source(name,description,url,version)
									 values("$source_name","$source_description$remapped","$hgmd_url",$year$month_num)
									});
	}
	else {
		$dbVar2->do(qq{INSERT INTO source(name,description,url)
{'fraction_non_alphanumeric': 0.19045936395759716, 'fraction_numerical': 0.017491166077738516, 'mean_word_length': 4.544564152791381, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4418528', 'n_tokens_mistral': 2403, 'n_tokens_neox': 2188, 'n_words': 416}