Archive Ensembl HomeArchive Ensembl Home
Sequence.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003   Copyright (c) 1999-2012 The European Bioinformatics Institute and
00004   Genome Research Limited.  All rights reserved.
00005 
00006   This software is distributed under a modified Apache license.
00007   For license details, please see
00008 
00009     http://www.ensembl.org/info/about/code_licence.html
00010 
00011 =head1 CONTACT
00012 
00013   Please email comments or questions to the public Ensembl
00014   developers list at <dev@ensembl.org>.
00015 
00016   Questions may also be sent to the Ensembl help desk at
00017   <helpdesk@ensembl.org>.
00018 
00019 =cut
00020 
00021 =head1 NAME
00022 
00023 Bio::EnsEMBL::Utils::Sequence - Utility functions for sequences
00024 
00025 =head1 SYNOPSIS
00026 
00027   use Bio::EnsEMBL::Utils::Sequence qw(reverse_comp expand);
00028 
00029   my $seq = 'ACTTTAAAGGCTATCCCAATATG';
00030 
00031   print "my sequence = $seq\n";
00032 
00033   reverse_comp( \$seq );
00034 
00035   print "my reverse comp = $seq\n";
00036 
00037   my $compressed_seq = '(AC)3';
00038 
00039   print "my expanded seq is = expand($compressed_seq)";
00040 
00041 =head1 METHODS
00042 
00043 =cut
00044 
00045 
00046 package Bio::EnsEMBL::Utils::Sequence;
00047 
00048 use strict;
00049 use warnings;
00050 
00051 use Exporter;
00052 
00053 use vars qw(@ISA @EXPORT_OK);
00054 
00055 @ISA = qw(Exporter);
00056 
00057 @EXPORT_OK = qw(&reverse_comp &expand);
00058 
00059 
00060 =head2 reverse_comp
00061 
00062   Arg [1]    : reference to a string $seqref
00063   Example    : use Bio::EnsEMBL::Utils::Sequence qw(reverse_comp);
00064 
00065                $seq = 'ACCTGAA';
00066                reverse_comp(\$seq);
00067                print $seq;
00068 
00069   Description: Does an in place reverse compliment of a passed in string
00070                reference.  The string is passed by reference
00071                rather than by value for memory efficiency.
00072   Returntype : none
00073   Exceptions : none
00074   Caller     : SequenceAdaptor, SliceAdaptor
00075 
00076 =cut
00077 
00078 sub reverse_comp {
00079   my $seqref = shift;
00080 
00081   $$seqref = reverse( $$seqref );
00082   $$seqref =~
00083     tr/acgtrymkswhbvdnxACGTRYMKSWHBVDNX/tgcayrkmswdvbhnxTGCAYRKMSWDVBHNX/;
00084 
00085   return;
00086 }
00087 
00088 =head2 expand
00089 
00090   Arg [1]    : reference to a string $seqref
00091   Example    : use Bio::EnsEMBL::Utils::Sequence qw(expand);
00092 
00093                $seq = '(AC)3';
00094                expand(\$seq);
00095                print $seq;
00096               
00097 
00098   Description: Expands a genomic sequence. The string is passed by reference
00099                rather than by value for memory efficiency.
00100   Returntype : none
00101   Exceptions : none
00102   Caller     : SequenceAdaptor, SliceAdaptor
00103 
00104 =cut
00105 
00106 sub expand {
00107   my $seq_ref = shift;
00108      $$seq_ref =~ s/(\w*)\((\w+)\)(\d+)/$1.$2 x $3/eg  if ($$seq_ref =~ /\(/);#expressions with parenthesis, expand the alleles             
00109   return;
00110 }
00111 
00112 
00113 1;