<commit_before>#!/usr/local/ensembl/bin/perl

# Generation of input ids for WGA2Genes. Segments the
# genome into regions that (1) contain at least one gene,
# and (2) do not interrupt a chain.

use strict;
use Getopt::Long;

use Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Compara::DBSQL::DBAdaptor;

my (
    $dbname,
    $dbhost,
    $dbuser,
    $dbport,
    $dbpass,
    $query_dbname,
    $query_dbhost,
    $query_dbport,
    $query_dbuser,
    $query_dbpass,
    $target_dbname,
    $target_dbhost,
    $target_dbport,
    $target_dbuser,
    $target_dbpass,
    $compara_dbname,
    $compara_dbhost,
    $compara_dbport,
    $compara_dbuser,
    $compara_dbpass,
    $seq_region_name,
    $source_type,
    $source_align_type,
    $logic_name,
    $write,
    $verbose,
);

$dbuser = 'ensro';
$dbport = 3306;
$query_dbuser = 'ensro';
$query_dbport = 3306;
$target_dbuser = 'ensro';
$target_dbport = 3306;
$compara_dbuser = "ensro";
$compara_dbport = 3306;

$source_type = 'protein_coding';
$source_align_type = 'BLASTZ_NET';

&GetOptions(
            
            'dbname=s' => \$dbname,
            'dbuser=s' => \$dbuser,
            'dbhost=s' => \$dbhost,
            'dbport=s' => \$dbport,
            'dbpass=s' => \$dbpass,
            'querydbname=s' => \$query_dbname,
            'querydbhost=s' => \$query_dbhost,
            'querydbport=s' => \$query_dbport,
            'querydbuser=s' => \$query_dbuser,
            'querybpass=s' => \$query_dbpass,
            'targetdbname=s' => \$target_dbname,
            'targetdbhost=s' => \$target_dbhost,
            'targetdbport=s' => \$target_dbport,
            'targetdbuser=s' => \$target_dbuser,
            'targetbpass=s'  => \$target_dbpass,
            'comparadbname=s' => \$compara_dbname,
            'comparadbhost=s' => \$compara_dbhost,
            'comparadbport=s' => \$compara_dbport,
            'comparadbuser=s' => \$compara_dbuser,
            'comparadbpass=s' => \$compara_dbpass,
            'logic=s' => \$logic_name,
            'aligntype=s'   => \$source_align_type,
            'genetype=s'    => \$source_type,
            'seq_region_name=s' => \$seq_region_name,
            'write' => \$write,
            'verbose' => \$verbose,
            );


my $db = Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor->new(
	'-dbname' => $dbname,
	'-host' => $dbhost,
	'-user' => $dbuser,
	'-port' => $dbport,
);

my $ana = $db->get_AnalysisAdaptor->fetch_by_logic_name($logic_name);
if (not defined $ana) {
  die "Could not find analysis with logic name '$logic_name' in pipe db\n";
}



my ($query_db, $target_db, $compara_db);

$query_db = Bio::EnsEMBL::DBSQL::DBAdaptor->
    new(
	'-dbname' => $query_dbname,
	'-host' => $query_dbhost,
	'-port' => $query_dbport,
	'-user' => $query_dbuser,
        '-pass' => $query_dbpass,
        );

if (not defined $target_dbname) {
  $target_db = $db;
} else {
 $target_db = Bio::EnsEMBL::DBSQL::DBAdaptor->
    new(
	'-dbname' => $target_dbname,
	'-host' => $target_dbhost,
	'-port' => $target_dbport,
	'-user' => $target_dbuser,
        '-pass' => $target_dbpass,
        );

}

if (defined $compara_dbname) {
  $compara_db = Bio::EnsEMBL::Compara::DBSQL::DBAdaptor->
      new(
          '-dbname' => $compara_dbname,
          '-host' => $compara_dbhost,
          '-port' => $compara_dbport,
          '-user' => $compara_dbuser,
          '-pass' => $compara_dbpass,
          );
}

my $q_species =
    $query_db->get_MetaContainerAdaptor->get_Species->binomial;
my $t_species =
    $target_db->get_MetaContainerAdaptor->get_Species->binomial;

my @tl_slices = @{$query_db->get_SliceAdaptor->fetch_all('toplevel')};


my @slices;

if (defined $seq_region_name) {
  my $sl = $query_db->get_SliceAdaptor->fetch_by_name("toplevel::${seq_region_name}:::");
  foreach my $tl_sl (@tl_slices) {
    next if $sl->seq_region_name =~ /^MT$/;

    if ($sl->coord_system->name eq $tl_sl->coord_system->name and
        $sl->seq_region_name eq $tl_sl->seq_region_name) {
      push @slices, $tl_sl
    }
  }
} else {
  @slices = @tl_slices;
}


my ($gdb_adap, $q_gdb, $t_gdb, $mlss, $gaba);

if (defined $compara_db) {
  $gdb_adap = $compara_db->get_GenomeDBAdaptor;
  $q_gdb = $gdb_adap->fetch_by_name_assembly($q_species);
  $t_gdb = $gdb_adap->fetch_by_name_assembly($t_species);

  $mlss = $compara_db->get_MethodLinkSpeciesSetAdaptor
      ->fetch_by_method_link_type_GenomeDBs($source_align_type,
                                          [$q_gdb, $t_gdb]);
  $gaba = $compara_db->get_GenomicAlignBlockAdaptor;
}

foreach my $sl (@slices) { 
  my @genes = @{$sl->get_all_Genes};
  @genes = grep { $_->biotype eq $source_type } @genes;

  my @gene_regions;<commit_msg>Bail out if no genes<commit_after>#!/usr/local/ensembl/bin/perl

# Generation of input ids for WGA2Genes. Segments the
# genome into regions that (1) contain at least one gene,
# and (2) do not interrupt a chain.

use strict;
use Getopt::Long;

use Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Compara::DBSQL::DBAdaptor;

my (
    $dbname,
    $dbhost,
    $dbuser,
    $dbport,
    $dbpass,
    $query_dbname,
    $query_dbhost,
    $query_dbport,
    $query_dbuser,
    $query_dbpass,
    $target_dbname,
    $target_dbhost,
    $target_dbport,
    $target_dbuser,
    $target_dbpass,
    $compara_dbname,
    $compara_dbhost,
    $compara_dbport,
    $compara_dbuser,
    $compara_dbpass,
    $seq_region_name,
    $source_type,
    $source_align_type,
    $logic_name,
    $write,
    $verbose,
);

$dbuser = 'ensro';
$dbport = 3306;
$query_dbuser = 'ensro';
$query_dbport = 3306;
$target_dbuser = 'ensro';
$target_dbport = 3306;
$compara_dbuser = "ensro";
$compara_dbport = 3306;

$source_type = 'protein_coding';
$source_align_type = 'BLASTZ_NET';

&GetOptions(
            
            'dbname=s' => \$dbname,
            'dbuser=s' => \$dbuser,
            'dbhost=s' => \$dbhost,
            'dbport=s' => \$dbport,
            'dbpass=s' => \$dbpass,
            'querydbname=s' => \$query_dbname,
            'querydbhost=s' => \$query_dbhost,
            'querydbport=s' => \$query_dbport,
            'querydbuser=s' => \$query_dbuser,
            'querybpass=s' => \$query_dbpass,
            'targetdbname=s' => \$target_dbname,
            'targetdbhost=s' => \$target_dbhost,
            'targetdbport=s' => \$target_dbport,
            'targetdbuser=s' => \$target_dbuser,
            'targetbpass=s'  => \$target_dbpass,
            'comparadbname=s' => \$compara_dbname,
            'comparadbhost=s' => \$compara_dbhost,
            'comparadbport=s' => \$compara_dbport,
            'comparadbuser=s' => \$compara_dbuser,
            'comparadbpass=s' => \$compara_dbpass,
            'logic=s' => \$logic_name,
            'aligntype=s'   => \$source_align_type,
            'genetype=s'    => \$source_type,
            'seq_region_name=s' => \$seq_region_name,
            'write' => \$write,
            'verbose' => \$verbose,
            );


my $db = Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor->new(
	'-dbname' => $dbname,
	'-host' => $dbhost,
	'-user' => $dbuser,
	'-port' => $dbport,
);

my $ana = $db->get_AnalysisAdaptor->fetch_by_logic_name($logic_name);
if (not defined $ana) {
  die "Could not find analysis with logic name '$logic_name' in pipe db\n";
}



my ($query_db, $target_db, $compara_db);

$query_db = Bio::EnsEMBL::DBSQL::DBAdaptor->
    new(
	'-dbname' => $query_dbname,
	'-host' => $query_dbhost,
	'-port' => $query_dbport,
	'-user' => $query_dbuser,
        '-pass' => $query_dbpass,
        );

if (not defined $target_dbname) {
  $target_db = $db;
} else {
 $target_db = Bio::EnsEMBL::DBSQL::DBAdaptor->
    new(
	'-dbname' => $target_dbname,
	'-host' => $target_dbhost,
	'-port' => $target_dbport,
	'-user' => $target_dbuser,
        '-pass' => $target_<PASSWORD>,
        );

}

if (defined $compara_dbname) {
  $compara_db = Bio::EnsEMBL::Compara::DBSQL::DBAdaptor->
      new(
          '-dbname' => $compara_dbname,
          '-host' => $compara_dbhost,
          '-port' => $compara_dbport,
          '-user' => $compara_dbuser,
          '-pass' => $compara_dbpass,
          );
}

my $q_species =
    $query_db->get_MetaContainerAdaptor->get_Species->binomial;
my $t_species =
    $target_db->get_MetaContainerAdaptor->get_Species->binomial;

my @tl_slices = @{$query_db->get_SliceAdaptor->fetch_all('toplevel')};


my @slices;

if (defined $seq_region_name) {
  my $sl = $query_db->get_SliceAdaptor->fetch_by_name("toplevel::${seq_region_name}:::");
  foreach my $tl_sl (@tl_slices) {
    next if $sl->seq_region_name =~ /^MT$/;

    if ($sl->coord_system->name eq $tl_sl->coord_system->name and
        $sl->seq_region_name eq $tl_sl->seq_region_name) {
      push @slices, $tl_sl
    }
  }
} else {
  @slices = @tl_slices;
}


my ($gdb_adap, $q_gdb, $t_gdb, $mlss, $gaba);

if (defined $compara_db) {
  $gdb_adap = $compara_db->get_GenomeDBAdaptor;
  $q_gdb = $gdb_adap->fetch_by_name_assembly($q_species);
  $t_gdb = $gdb_adap->fetch_by_name_assembly($t_species);

  $mlss = $compara_db->get_MethodLinkSpeciesSetAdaptor
      ->fetch_by_method_link_type_GenomeDBs($source_align_type,
                                          [$q_gdb, $t_gdb]);
  $gaba = $compara_db->get_GenomicAlignBlockAdaptor;
}

foreach my $sl (@slices) { 
  my @genes = @{$sl->get_all_Genes};
  @genes = grep { $_->biotype eq $source_type } @genes;

  next if not @genes;
  
  my @gene_regions;
{'fraction_non_alphanumeric': 0.165890816758358, 'fraction_numerical': 0.004020313161235718, 'mean_word_length': 2.9453255425709517, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 156, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4998815', 'n_tokens_mistral': 3886, 'n_tokens_neox': 3737, 'n_words': 593}