2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 EXAMPLE.use_mapping.pl - example script
for projecting features from one
25 EXAMPLE.use_mapping.pl [arguments]
29 --host=hOST database host HOST
30 --port=PORT database port PORT
31 --user=USER database username USER
32 --pass=PASS database passwort PASS
33 --dbname=NAME database name NAME
34 --infile=FILE read input data from FILE
35 --old_assembly=NAME old assembly NAME
36 --new_assembly=NAME
new assembly NAME
40 This is an example script illustrating how to use a mapping between two
41 assemblies
for a species, as generated by the scripts in
this directory. At the
42 time of writing,
this mapping was available
for human and mouse.
44 The script assumes that your input data are features in old assembly
45 coordinates which you want to transform into
new assembly coordinates (i.e.
46 project the features onto the
new assembly) and store in an Ensembl database.
47 The input data in
this example is read from a file with the format
49 # NAME:CHROMOSOME:START:END:STRAND
55 The example also includes some sanity check you might want to
do on your
56 projections. It will depend on your use
case whether you want to use them or
57 not (you might need either more or less restrictive conditions).
62 Patrick Meidl <meidl@ebi.ac.uk>, Ensembl core API team
66 Please post comments/questions to the Ensembl development list
73 no warnings
'uninitialized';
82 my ($host, $port, $user, $pass, $dbname, $infile, $old_assembly, $new_assembly);
91 "old_assembly=s", \$old_assembly,
92 "new_assembly=s", \$new_assembly
95 # connect to database and get adaptors
104 my $sa = $db->get_SliceAdaptor();
106 # create an analysis for the type of feature you wish to store
108 -LOGIC_NAME =>
'your_analysis'
111 # read your input data
112 open(FILE,
"<$infile") or die("Can't open $infile for reading: $!");
119 my ($name, $chr, $start, $end, $strand) = split(/:/);
121 # get a slice on the old assembly
122 my $slice_oldasm = $sa->fetch_by_region(
'chromosome', $chr, undef, undef,
123 undef, $old_assembly);
125 if (!$slice_oldasm) {
126 warn
"Can't get $old_assembly slice for $chr:$start:$end\n";
130 # create a new feature on the old assembly
132 -DISPLAY_LABEL => $name,
136 -SLICE => $slice_oldasm,
137 -ANALYSIS => $analysis,
140 # project feature to new assembly
143 # do some sanity checks on the projection results:
144 # discard the projected feature if
145 # 1. it doesn't project at all (no segments returned)
146 # 2. the projection is fragmented (more than one segment)
147 # 3. the projection doesn't have the same length as the original
150 # this tests for (1) and (2)
151 next unless (scalar(@segments) == 1);
154 my $proj_slice = $segments[0]->to_Slice;
155 next unless ($feat->length == $proj_slice->length);
157 next unless ($proj_slice->seq_region_name eq $feat->slice->seq_region_name);
159 # everything looks fine, so adjust the coords of your feature
160 $feat->start($proj_slice->start);
161 $feat->end($proj_slice->end);
162 my $slice_newasm = $sa->fetch_by_region(
'chromosome', $chr, undef, undef,
163 undef, $new_assembly);
164 $feat->slice($slice_newasm);