<commit_before>#!/usr/bin/env perl
# $Source: /tmp/ENSCOPY-ENSEMBL-ANALYSIS/scripts/genebuild/copy_genes.pl,v $
# $Revision: 1.28 $

=head1 NAME

  copy_genes.pl

=head1 DESCRIPTION

 This script takes database options and a file of gene ids or stable_ids
 and copies them between two databases.  It can, if asked, split
 multi-transcript genes into single genes.

 The source database (from which you copy genes FROM) must contain
 DNA, or else the script will throw.  If your source database does not
 contain DNA, then provide details of a DNA database using the options
 --dnauser, --dnahost, --dnadbname etc.

 When using the in and out_config_name options it reads the equivalent
 database from the Bio::EnsEMBL::Analysis::Config::GeneBuild::Databases
 file.

=head1 OPTIONS

  --all                 This option will copy all genes from
                        $sourcedbname to the output database.

  --split               This option will split multi-transcript genes
                        into single-transcript genes.

  --logic               This option will change the analysis of the
                        genes being written to the output database to an
                        analysis with the specified logic_name.

  --remove_xrefs        Using this flag will remove xrefs from genes,
                        transcripts, and from translations.

  --remove_stable_ids   Using this flag will remove stable IDs from
                        genes, transcripts, translations, and from
                        exons.

  --transform_to        Transforms the genes from one coordinate system
                        to the given one.  The value must be on the
                        format "coord_system_name:version".

  --stable_id           Flag for indicating that input file contains
                        stable IDs and not gene IDs.

  --file                Read gene dbIDs out of a supplied file and only
                        copy these genes.

=head1 EXAMPLE

  perl copy_genes.pl \
    --source_config_name=CONSENSUS_DB \
    --target_config_name=UTR_DB \
    --file=gene_ids_to_copy

  or

  perl copy_genes.pl \
    --sourcehost=srchost --sourceuser=ensro \
    --sourcedbname=est_db \
    --targethost=trghost --targetuser=user --targetpass=<PASSWORD> \
    --targetdbname=utr_db \
    --file=gene_ids_to_copy --stable_id


  In the options, 'source' is synonymous with 'in' (--in_config_name
  is the same option as --source_config_name etc.) and 'target' is
  synonymous with 'out' (--targetdbname is the same as --outdbname).

=cut

use strict;
use warnings;
use Carp;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Utils::Exception qw ( throw warning ) ;
use Bio::EnsEMBL::Analysis::Tools::GeneBuildUtils;
use Bio::EnsEMBL::Analysis::Tools::GeneBuildUtils::GeneUtils;
use Bio::EnsEMBL::Analysis::Tools::GeneBuildUtils::TranscriptUtils;
use Getopt::Long;
use Bio::EnsEMBL::Analysis::Tools::Utilities;

my $sourcehost      = '';
my $sourceuser      = 'ensro';
my $sourcedbname    = '';
my $sourceport      = 3306;

my $outhost   = '';
my $outuser   = '';
my $outpass   = '';
my $outdbname = undef;
my $outport   = 3306;

my $dnahost   = '';
my $dnauser   = 'ensro';
my $dnapass   = '';
my $dnadbname = undef;
my $dnaport   = 3306;

my $in_config_name;
my $out_config_name;

my $logic;
my $split = 0;
my $infile;
my $all;
my $remove_xrefs;
my $remove_stable_ids;
my $transform_to;
my $stable_id;
my $verbose; 

GetOptions( 'inhost|sourcehost:s'                  => \$sourcehost,
            'inuser|sourceuser:s'                  => \$sourceuser,
            'indbname|sourcedbname:s'              => \$sourcedbname,
            'inport|sourceport:n'                  => \$sourceport,
            'in_config_name|source_config_name:s'  => \$in_config_name,
            'out_config_name|target_config_name:s' => \$out_config_name,
            'outhost|targethost:s'                 => \$outhost,
            'outuser|targetuser:s'                 => \$outuser,
            'outpass|targetpass:s'                 => \$outpass,
            'outdbname|targetdbname:s'             => \$outdbname,
            'outport|targetport:n'                 => \$outport,
            'dnahost:s'                            => \$dnahost,
            'dnauser:s'                            => \$dnauser,
            'dnadbname:s'                          => \$dnadbname,
            'dnaport:n'                            => \$dnaport,
            'logic:s'                              => \$logic,
            'split!'                               => \$split,
            'all!'                                 => \$all,
            'remove_xrefs!'                        => \$remove_xrefs,
            'remove_stable_ids!'                   => \$remove_stable_ids,
            'transform_to:s'                       => \$transform_to,
            'verbose!'                             => \$verbose,
            'stable_id!'                           => \$stable_id,
            'file:s'                               => \$infile );

my $transform_to_version;
my $do_not_attach_dna_db = 1;
if($transform_to){ 
    $do_not_attach_dna_db = 0;
  if ( $transform_to=~m/:/) { 
    ( $transform_to,  $transform_to_version ) = split /:/,$transform_to ; 
  }
}

if ($all && $infile) {
  throw("Specify either -all or -file");
} elsif (!$all && !$infile) {
  throw("Specify -all (to copy all genes from $sourcedbname) or -file (to copy a list of gene_ids)");
}

#print "Connecting to ".$sourcedbname." at ".$sourcehost." ".$sourceuser."\n";<commit_msg>Set verbosity to EXCEPTION by default. If you want the XXXXXX lines about not having dna sequence, use the flag -verbosity<commit_after>#!/usr/bin/env perl
# $Source: /tmp/ENSCOPY-ENSEMBL-ANALYSIS/scripts/genebuild/copy_genes.pl,v $
# $Revision: 1.29 $

=head1 NAME

  copy_genes.pl

=head1 DESCRIPTION

 This script takes database options and a file of gene ids or stable_ids
 and copies them between two databases.  It can, if asked, split
 multi-transcript genes into single genes.

 The source database (from which you copy genes FROM) must contain
 DNA, or else the script will throw.  If your source database does not
 contain DNA, then provide details of a DNA database using the options
 --dnauser, --dnahost, --dnadbname etc.

 When using the in and out_config_name options it reads the equivalent
 database from the Bio::EnsEMBL::Analysis::Config::GeneBuild::Databases
 file.

=head1 OPTIONS

  --all                 This option will copy all genes from
                        $sourcedbname to the output database.

  --split               This option will split multi-transcript genes
                        into single-transcript genes.

  --logic               This option will change the analysis of the
                        genes being written to the output database to an
                        analysis with the specified logic_name.

  --remove_xrefs        Using this flag will remove xrefs from genes,
                        transcripts, and from translations.

  --remove_stable_ids   Using this flag will remove stable IDs from
                        genes, transcripts, translations, and from
                        exons.

  --transform_to        Transforms the genes from one coordinate system
                        to the given one.  The value must be on the
                        format "coord_system_name:version".

  --stable_id           Flag for indicating that input file contains
                        stable IDs and not gene IDs.

  --file                Read gene dbIDs out of a supplied file and only
                        copy these genes.

=head1 EXAMPLE

  perl copy_genes.pl \
    --source_config_name=CONSENSUS_DB \
    --target_config_name=UTR_DB \
    --file=gene_ids_to_copy

  or

  perl copy_genes.pl \
    --sourcehost=srchost --sourceuser=ensro \
    --sourcedbname=est_db \
    --targethost=trghost --targetuser=user --targetpass=XXX \
    --targetdbname=utr_db \
    --file=gene_ids_to_copy --stable_id


  In the options, 'source' is synonymous with 'in' (--in_config_name
  is the same option as --source_config_name etc.) and 'target' is
  synonymous with 'out' (--targetdbname is the same as --outdbname).

=cut

use strict;
use warnings;
use Carp;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Utils::Exception qw( throw warning verbose) ;
use Bio::EnsEMBL::Analysis::Tools::GeneBuildUtils;
use Bio::EnsEMBL::Analysis::Tools::GeneBuildUtils::GeneUtils;
use Bio::EnsEMBL::Analysis::Tools::GeneBuildUtils::TranscriptUtils;
use Getopt::Long;
use Bio::EnsEMBL::Analysis::Tools::Utilities;

my $sourcehost      = '';
my $sourceuser      = 'ensro';
my $sourcedbname    = '';
my $sourceport      = 3306;

my $outhost   = '';
my $outuser   = '';
my $outpass   = '';
my $outdbname = undef;
my $outport   = 3306;

my $dnahost   = '';
my $dnauser   = 'ensro';
my $dnapass   = '';
my $dnadbname = undef;
my $dnaport   = 3306;

my $in_config_name;
my $out_config_name;

my $logic;
my $split = 0;
my $infile;
my $all;
my $remove_xrefs;
my $remove_stable_ids;
my $transform_to;
my $stable_id;
my $verbose; 

verbose('EXCEPTION');

GetOptions( 'inhost|sourcehost:s'                  => \$sourcehost,
            'inuser|sourceuser:s'                  => \$sourceuser,
            'indbname|sourcedbname:s'              => \$sourcedbname,
            'inport|sourceport:n'                  => \$sourceport,
            'in_config_name|source_config_name:s'  => \$in_config_name,
            'out_config_name|target_config_name:s' => \$out_config_name,
            'outhost|targethost:s'                 => \$outhost,
            'outuser|targetuser:s'                 => \$outuser,
            'outpass|targetpass:s'                 => \$outpass,
            'outdbname|targetdbname:s'             => \$outdbname,
            'outport|targetport:n'                 => \$outport,
            'dnahost:s'                            => \$dnahost,
            'dnauser:s'                            => \$dnauser,
            'dnadbname:s'                          => \$dnadbname,
            'dnaport:n'                            => \$dnaport,
            'logic:s'                              => \$logic,
            'split!'                               => \$split,
            'all!'                                 => \$all,
            'remove_xrefs!'                        => \$remove_xrefs,
            'remove_stable_ids!'                   => \$remove_stable_ids,
            'transform_to:s'                       => \$transform_to,
            'verbose!'                             => \$verbose,
            'stable_id!'                           => \$stable_id,
            'file:s'                               => \$infile );

verbose('WARNING') if ($verbose);

my $transform_to_version;
my $do_not_attach_dna_db = 1;
if($transform_to){ 
    $do_not_attach_dna_db = 0;
  if ( $transform_to=~m/:/) { 
    ( $transform_to,  $transform_to_version ) = split /:/,$transform_to ; 
  }
}

if ($all && $infile) {
  throw("Specify either -all or -file");
} elsif (!$all && !$infile) {
  throw("Specify -all (to copy all genes from $sourcedbname) or -file (to copy a list of gene_ids)");
}

#print "Connecting to ".$sourcedbname." at ".$sourcehost." ".$sourceuser."\n";
{'fraction_non_alphanumeric': 0.10912628227803325, 'fraction_numerical': 0.0038910505836575876, 'mean_word_length': 1.90869341563786, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7565860', 'n_tokens_mistral': 3565, 'n_tokens_neox': 3305, 'n_words': 916}