ensembl-hive  2.8.1
synteny_rescore.pl
Go to the documentation of this file.
1 #!/usr/bin/env perl
2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 # Don't change the above line.
18 # Change the PATH in the myRun.ksh script if you want to use another perl.
19 
20 =head1 NAME
21 
22 
23 =head1 SYNOPSIS
24 
25 .pl [arguments]
26 
27 Required arguments:
28 
29  --dbname, db_name=NAME database name NAME
30  --host, --dbhost, --db_host=HOST database host HOST
31  --port, --dbport, --db_port=PORT database port PORT
32  --user, --dbuser, --db_user=USER database username USER
33  --pass, --dbpass, --db_pass=PASS database passwort PASS
34 
35 Optional arguments:
36 
37  --conffile, --conf=FILE read parameters from FILE
38  (default: conf/Conversion.ini)
39 
40  --logfile, --log=FILE log to FILE (default: *STDOUT)
41  --logpath=PATH write logfile to PATH (default: .)
42  --logappend, --log_append append to logfile (default: truncate)
43  --loglevel=LEVEL define log level (default: INFO)
44 
45  -i, --interactive=0|1 run script interactively (default: true)
46  -n, --dry_run, --dry=0|1 don't write results to database
47  -h, --help, -? print help (this message)
48 
49 =head1 DESCRIPTION
50 
51 
52 
53 =head1 AUTHOR
54 
55 Patrick Meidl <meidl@ebi.ac.uk>, Ensembl core API team
56 
57 =head1 CONTACT
58 
59 Please post comments/questions to the Ensembl development list
60 <http://lists.ensembl.org/mailman/listinfo/dev>
61 
62 =cut
63 
64 use strict;
65 use warnings;
66 no warnings 'uninitialized';
67 
68 use FindBin qw($Bin);
69 use Bio::EnsEMBL::Utils::ConfParser;
70 use Bio::EnsEMBL::Utils::Logger;
71 use Bio::EnsEMBL::Utils::ScriptUtils qw(path_append);
72 use Bio::EnsEMBL::IdMapping::Cache;
73 use Bio::EnsEMBL::IdMapping::SyntenyFramework;
74 use Bio::EnsEMBL::IdMapping::ScoredMappingMatrix;
75 
76 # parse configuration and commandline arguments
77 my $conf = new Bio::EnsEMBL::Utils::ConfParser(
78  -SERVERROOT => "$Bin/../../..",
79  -DEFAULT_CONF => "$Bin/default.conf"
80 );
81 
82 $conf->parse_options(
83  'basedir|basedir=s' => 1,
84  'index|i=n' => 1,
85  'chromosomes|chr=s@' => 0,
86  'region=s' => 0,
87 );
88 
89 # append job index to logfile name
90 my $index = $conf->param('index');
91 my $logautobase = $conf->param('logautobase') || 'synteny_rescore';
92 
93 # get log filehandle and print heading and parameters to logfile
94 my $logger = new Bio::EnsEMBL::Utils::Logger(
95  -LOGFILE => $conf->param('logfile'),
96  -LOGAUTO => $conf->param('logauto'),
97  -LOGAUTOBASE => $logautobase,
98  -LOGAUTOID => $conf->param('logautoid'),
99  -LOGPATH => $conf->param('logpath'),
100  -LOGAPPEND => $conf->param('logappend'),
101  -LOGLEVEL => $conf->param('loglevel'),
102  -IS_COMPONENT => 1,
103 );
104 
105 # loading cache from file
106 my $cache = Bio::EnsEMBL::IdMapping::Cache->new(
107  -LOGGER => $logger,
108  -CONF => $conf,
109  -LOAD_INSTANCE => 1,
110 );
111 
112 # load SyntenyFramework and gene ScoredMappingMatrix from files
113 my $basedir = $conf->param('basedir');
114 
115 my $sf = Bio::EnsEMBL::IdMapping::SyntenyFramework->new(
116  -DUMP_PATH => path_append($basedir, 'mapping'),
117  -CACHE_FILE => 'synteny_framework.ser',
118  -LOGGER => $logger,
119  -CONF => $conf,
120  -CACHE => $cache,
121 );
122 $sf->read_from_file;
123 
124 my $gene_scores = Bio::EnsEMBL::IdMapping::ScoredMappingMatrix->new(
125  -DUMP_PATH => path_append($basedir, 'matrix/synteny_rescore'),
126  -CACHE_FILE => "gene_matrix_synteny$index.ser",
127  -AUTO_LOAD => 1,
128 );
129 
130 # synteny rescore and serialise results to file
131 $gene_scores = $sf->rescore_gene_matrix($gene_scores);
132 $gene_scores->write_to_file;
133 
134 # set flag to indicate everything went fine
135 my $success_file = $conf->param('logpath')."/synteny_rescore.$index.success";
136 open(TMPFILE, '>', $success_file) and close TMPFILE
137  or die "Can't open $success_file for writing: $!";
138 
139 # log success
140 $logger->finish_log;
141 
run
public run()