<commit_before>#!/software/bin/perl

=head1 NAME

transfer_annotation_zfish.pl - transfer gene annotations from one set of zfish assemblies to another, step 4

=head1 SYNOPSIS

transfer_annotation_zfish.pl [arguments]

Required arguments:

  --dbname, db_name=NAME              database name NAME
  --host, --dbhost, --db_host=HOST    database host HOST
  --port, --dbport, --db_port=PORT    database port PORT
  --user, --dbuser, --db_user=USER    database username USER
  --pass, --dbpass, --db_pass=PASS    database passwort PASS
  --from_assembly                     old assembly date
  --to_assembly                       new assembly date
  --author                            author login used to lock the assemblies

Optional arguments:


  --dry=0|1                           don't write results to database (default: false)

  --assembly=ASSEMBLY                 assembly version ASSEMBLY (default: Otter)
  --altassembly=ASSEMBLY              alternative assembly version ASSEMBLY (default: assembly)
  --email                             email used to lock the assemblies (default: author)
  --conffile, --conf=FILE             read parameters from FILE
                                      (default: conf/Conversion.ini)

  --logfile, --log=FILE               log to FILE (default: *STDOUT)
  --logpath=PATH                      write logfile to PATH (default: .)
  --logappend, --log_append           append to logfile (default: truncate)

  -v, --verbose=0|1                   verbose logging (default: true)
  -i, --interactive=0|1               run script interactively (default: false)
  -h, --help, -?                      print help (this message)

=head1 DESCRIPTION


=head1 RELATED FILES

The whole process of creating a whole genome alignment between two sets of zfish assemblies
is done by a series of scripts. Please see scripts in

  ensembl-pipeline/scripts/Finished/assembly/

for a high-level description of this process, and POD in the individual scripts
for the details.

=head1 AUTHOR

<NAME> <<EMAIL>>, Ensembl core API team

modified by Must<NAME> <<EMAIL>>

=head1 CONTACT

Please post comments/questions to Anacode
<<EMAIL>>

=cut

use strict;
use warnings;
no warnings 'uninitialized';

use FindBin qw($Bin);
use vars qw($SERVERROOT);
BEGIN {
    $SERVERROOT = "$Bin/../../../..";
    unshift(@INC, "$Bin");
    unshift(@INC, "$SERVERROOT/ensembl/modules");
    unshift(@INC, "/software/anacode/otter/otter_production_main/ensembl-otter/modules/");
    unshift(@INC, "$SERVERROOT/bioperl-0.7.2");
    unshift(@INC, "$SERVERROOT/bioperl-1.2.3-patched");
}

use Getopt::Long;
use Pod::Usage;
use Sys::Hostname;
use Bio::EnsEMBL::Utils::ConversionSupport;
use Bio::EnsEMBL::Attribute;
use Bio::Vega::DBSQL::DBAdaptor;
use Bio::Vega::ContigLockBroker;
use Bio::Vega::Author;
use Bio::EnsEMBL::Utils::Exception qw(verbose throw warning);

$| = 1;

my $support = new Bio::EnsEMBL::Utils::ConversionSupport($SERVERROOT);

# parse options
$support->parse_common_options(@_);
$support->parse_extra_options(
	'from_assembly=s', 'to_assembly=s',	'assembly=s', 'altassembly=s',
	'author=s', 'email=s'
);
$support->allowed_params( $support->get_common_params, 'from_assembly=s', 'to_assembly=s', 'assembly=s','altassembly=s' );

if ( $support->param('help') or $support->error ) {
	print STDOUT $support->error if $support->error;
	pod2usage(1);
}

$support->param('verbose', 1);
$support->param('interactive', 0);

# get log filehandle and print heading and parameters to logfile
$support->init_log;


# database connection
my $vega_db = $support->get_database('ensembl');
bless $vega_db, "Bio::Vega::DBSQL::DBAdaptor";
my $dbh = $vega_db->dbc->db_handle;

my $from_assembly = $support->param('from_assembly');
my $to_assembly = $support->param('to_assembly');

my $assembly    = $support->param('assembly') || 'Otter';
my $altassembly = $support->param('altassembly') || $assembly;

my $write_db      = not $support->param('dry_run');
my $author 		= $support->param('author');
my $email 		= $support->param('email') || $author;


throw("must set author name to lock the assemblies") if (!$author);


my $geneAd   = $vega_db->get_GeneAdaptor;
my $sliceAd  = $vega_db->get_SliceAdaptor;
my $sfeat_Ad = $vega_db->get_SimpleFeatureAdaptor();

# make sure that the coordinate system versions are different
# if they are the same (i.e. both Otter) create a temporary cs version MAPPING
my $sql_meta_insert = qq{
	insert ignore into meta (meta_key, meta_value) values
	('assembly.mapping', 'chromosome:MAPPING|contig'),
	('assembly.mapping', 'chromosome:MAPPING|contig|clone'),
	('assembly.mapping', 'chromosome:Otter#chromosome:MAPPING')};

my $sql_meta_delete = qq{
	delete from meta where meta_value like 'chromosome%MAPPING%'};

my $sql_cs_insert = qq{
	insert ignore into coord_system (coord_system_id, name, version, rank, attrib) values (100, 'chromosome', 'MAPPING', 100, '')};
my $sql_cs_delete = qq{
	delete from coord_system where version = 'MAPPING'};

my $sql_mc_insert = qq{
	insert ignore into meta_coord (table_name, coord_system_id, max_length)
	values ('exon', 100, 1), ('gene', 100, 1), ('simple_feature', 100, 1), ('transcript', 100, 1)};
my $sql_mc_delete = qq{
	delete from meta_coord where coord_system_id = 100};

my $sql_sr_update = qq{
	update seq_region s, coord_system cs
	set s.coord_system_id = cs.coord_system_id
	where s.name = ?
	and cs.name = 'chromosome'
	and cs.version = ?};

# 1 and 2 below must be specifically set in order to
# fetch the features on a particular seq_region and disable
# the use of the mapping mechanism (used to test duplicates)

# 1. sql queries to enable gene/simple_feature build
my $sql_meta_bl_insert = qq{
	insert ignore into meta (meta_key, meta_value) values
	('simple_featurebuild.level', '1'),
	('genebuild.level', '1')};
my $sql_meta_bl_delete =
qq{delete from meta where meta_key in ('simple_featurebuild.level','genebuild.level')};

# 2. attrib_type_id 6 is a Top Level Non-Redundant Sequence Region
my $sql_attrib_type_select =
qq{SELECT COUNT(*) FROM seq_region_attrib WHERE seq_region_id = ? AND attrib_type_id = 6;};
my $sql_attrib_type_insert =
qq{insert into seq_region_attrib (seq_region_id, attrib_type_id, value) values (?, 6, 1)};
my $sql_attrib_type_delete =
qq{delete from seq_region_attrib where seq_region_id = ? and attrib_type_id = 6};

my $sth_attrib_type_select = $dbh->prepare($sql_attrib_type_select);
my $sth_attrib_type_insert = $dbh->prepare($sql_attrib_type_insert);
my $sth_attrib_type_delete = $dbh->prepare($sql_attrib_type_delete);

my $cs_change = 0;

if ( $assembly eq $altassembly ) {
	$cs_change   = 1;
	$altassembly = 'MAPPING';

	$dbh->do($sql_meta_insert);
	$dbh->do($sql_cs_insert);
	$dbh->do($sql_mc_insert);
	$dbh->do($sql_meta_bl_insert);
}
<commit_msg>change "chromosome:MAPPING" coord_system_id to 1000 (100 is OtterArchive)<commit_after>#!/software/bin/perl

=head1 NAME

transfer_annotation_zfish.pl - transfer gene annotations from one set of zfish assemblies to another, step 4

=head1 SYNOPSIS

transfer_annotation_zfish.pl [arguments]

Required arguments:

  --dbname, db_name=NAME              database name NAME
  --host, --dbhost, --db_host=HOST    database host HOST
  --port, --dbport, --db_port=PORT    database port PORT
  --user, --dbuser, --db_user=USER    database username USER
  --pass, --dbpass, --db_pass=PASS    database passwort PASS
  --from_assembly                     old assembly date
  --to_assembly                       new assembly date
  --author                            author login used to lock the assemblies

Optional arguments:


  --dry=0|1                           don't write results to database (default: false)

  --assembly=ASSEMBLY                 assembly version ASSEMBLY (default: Otter)
  --altassembly=ASSEMBLY              alternative assembly version ASSEMBLY (default: assembly)
  --email                             email used to lock the assemblies (default: author)
  --conffile, --conf=FILE             read parameters from FILE
                                      (default: conf/Conversion.ini)

  --logfile, --log=FILE               log to FILE (default: *STDOUT)
  --logpath=PATH                      write logfile to PATH (default: .)
  --logappend, --log_append           append to logfile (default: truncate)

  -v, --verbose=0|1                   verbose logging (default: true)
  -i, --interactive=0|1               run script interactively (default: false)
  -h, --help, -?                      print help (this message)

=head1 DESCRIPTION


=head1 RELATED FILES

The whole process of creating a whole genome alignment between two sets of zfish assemblies
is done by a series of scripts. Please see scripts in

  ensembl-pipeline/scripts/Finished/assembly/

for a high-level description of this process, and POD in the individual scripts
for the details.

=head1 AUTHOR

<NAME> <<EMAIL>>, Ensembl core API team

modified by <NAME> <<EMAIL>>

=head1 CONTACT

Please post comments/questions to Anacode
<<EMAIL>>

=cut

use strict;
use warnings;
no warnings 'uninitialized';

use FindBin qw($Bin);
use vars qw($SERVERROOT);
BEGIN {
    $SERVERROOT = "$Bin/../../../..";
    unshift(@INC, "$Bin");
    unshift(@INC, "$SERVERROOT/ensembl/modules");
    unshift(@INC, "/software/anacode/otter/otter_production_main/ensembl-otter/modules/");
    unshift(@INC, "$SERVERROOT/bioperl-0.7.2");
    unshift(@INC, "$SERVERROOT/bioperl-1.2.3-patched");
}

use Getopt::Long;
use Pod::Usage;
use Sys::Hostname;
use Bio::EnsEMBL::Utils::ConversionSupport;
use Bio::EnsEMBL::Attribute;
use Bio::Vega::DBSQL::DBAdaptor;
use Bio::Vega::ContigLockBroker;
use Bio::Vega::Author;
use Bio::EnsEMBL::Utils::Exception qw(verbose throw warning);

$| = 1;

my $support = new Bio::EnsEMBL::Utils::ConversionSupport($SERVERROOT);

# parse options
$support->parse_common_options(@_);
$support->parse_extra_options(
	'from_assembly=s', 'to_assembly=s',	'assembly=s', 'altassembly=s',
	'author=s', 'email=s'
);
$support->allowed_params( $support->get_common_params, 'from_assembly=s', 'to_assembly=s', 'assembly=s','altassembly=s' );

if ( $support->param('help') or $support->error ) {
	print STDOUT $support->error if $support->error;
	pod2usage(1);
}

$support->param('verbose', 1);
$support->param('interactive', 0);

# get log filehandle and print heading and parameters to logfile
$support->init_log;


# database connection
my $vega_db = $support->get_database('ensembl');
bless $vega_db, "Bio::Vega::DBSQL::DBAdaptor";
my $dbh = $vega_db->dbc->db_handle;

my $from_assembly = $support->param('from_assembly');
my $to_assembly = $support->param('to_assembly');

my $assembly    = $support->param('assembly') || 'Otter';
my $altassembly = $support->param('altassembly') || $assembly;

my $write_db      = not $support->param('dry_run');
my $author 		= $support->param('author');
my $email 		= $support->param('email') || $author;


throw("must set author name to lock the assemblies") if (!$author);


my $geneAd   = $vega_db->get_GeneAdaptor;
my $sliceAd  = $vega_db->get_SliceAdaptor;
my $sfeat_Ad = $vega_db->get_SimpleFeatureAdaptor();

# make sure that the coordinate system versions are different
# if they are the same (i.e. both Otter) create a temporary cs version MAPPING
my $sql_meta_insert = qq{
	insert ignore into meta (meta_key, meta_value) values
	('assembly.mapping', 'chromosome:MAPPING|contig'),
	('assembly.mapping', 'chromosome:MAPPING|contig|clone'),
	('assembly.mapping', 'chromosome:Otter#chromosome:MAPPING')};

my $sql_meta_delete = qq{
	delete from meta where meta_value like 'chromosome%MAPPING%'};

my $sql_cs_insert = qq{
	insert ignore into coord_system (coord_system_id, name, version, rank, attrib) values (1000, 'chromosome', 'MAPPING', 1000, '')};
my $sql_cs_delete = qq{
	delete from coord_system where version = 'MAPPING'};

my $sql_mc_insert = qq{
	insert ignore into meta_coord (table_name, coord_system_id, max_length)
	values ('exon', 1000, 1), ('gene', 1000, 1), ('simple_feature', 1000, 1), ('transcript', 1000, 1)};
my $sql_mc_delete = qq{
	delete from meta_coord where coord_system_id = 1000};

my $sql_sr_update = qq{
	update seq_region s, coord_system cs
	set s.coord_system_id = cs.coord_system_id
	where s.name = ?
	and cs.name = 'chromosome'
	and cs.version = ?};

# 1 and 2 below must be specifically set in order to
# fetch the features on a particular seq_region and disable
# the use of the mapping mechanism (used to test duplicates)

# 1. sql queries to enable gene/simple_feature build
my $sql_meta_bl_insert = qq{
	insert ignore into meta (meta_key, meta_value) values
	('simple_featurebuild.level', '1'),
	('genebuild.level', '1')};
my $sql_meta_bl_delete =
qq{delete from meta where meta_key in ('simple_featurebuild.level','genebuild.level')};

# 2. attrib_type_id 6 is a Top Level Non-Redundant Sequence Region
my $sql_attrib_type_select =
qq{SELECT COUNT(*) FROM seq_region_attrib WHERE seq_region_id = ? AND attrib_type_id = 6;};
my $sql_attrib_type_insert =
qq{insert into seq_region_attrib (seq_region_id, attrib_type_id, value) values (?, 6, 1)};
my $sql_attrib_type_delete =
qq{delete from seq_region_attrib where seq_region_id = ? and attrib_type_id = 6};

my $sth_attrib_type_select = $dbh->prepare($sql_attrib_type_select);
my $sth_attrib_type_insert = $dbh->prepare($sql_attrib_type_insert);
my $sth_attrib_type_delete = $dbh->prepare($sql_attrib_type_delete);

my $cs_change = 0;

if ( $assembly eq $altassembly ) {
	$cs_change   = 1;
	$altassembly = 'MAPPING';

	$dbh->do($sql_cs_insert);
	$dbh->do($sql_meta_insert);
	$dbh->do($sql_mc_insert);
	$dbh->do($sql_meta_bl_insert);
}

{'fraction_non_alphanumeric': 0.131098231971242, 'fraction_numerical': 0.010123982099625853, 'mean_word_length': 4.063893016344725, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1367266', 'n_tokens_mistral': 4772, 'n_tokens_neox': 4539, 'n_words': 1235}