| 1 | =head1 LICENSE | ||
| 2 | |||
| 3 | See the NOTICE file distributed with this work for additional information | ||
| 4 | regarding copyright ownership. | ||
| 5 | |||
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 7 | you may not use this file except in compliance with the License. | ||
| 8 | You may obtain a copy of the License at | ||
| 9 | |||
| 10 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 11 | |||
| 12 | Unless required by applicable law or agreed to in writing, software | ||
| 13 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 15 | See the License for the specific language governing permissions and | ||
| 16 | limitations under the License. | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | |||
| 21 | =head1 CONTACT | ||
| 22 | |||
| 23 | Please email comments or questions to the public Ensembl | ||
| 24 | developers list at <http://lists.ensembl.org/mailman/listinfo/dev>. | ||
| 25 | |||
| 26 | Questions may also be sent to the Ensembl help desk at | ||
| 27 | <http://www.ensembl.org/Help/Contact>. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | Bio::EnsEMBL::Utils::Sequence - Utility functions for sequences | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | use Bio::EnsEMBL::Utils::Sequence qw(reverse_comp expand); | ||
| 38 | |||
| 39 | my $seq = 'ACTTTAAAGGCTATCCCAATATG'; | ||
| 40 | |||
| 41 | print "my sequence = $seq\n"; | ||
| 42 | |||
| 43 | reverse_comp( \$seq ); | ||
| 44 | |||
| 45 | print "my reverse comp = $seq\n"; | ||
| 46 | |||
| 47 | my $compressed_seq = '(AC)3'; | ||
| 48 | |||
| 49 | print "my expanded seq is = expand($compressed_seq)"; | ||
| 50 | |||
| 51 | =head1 METHODS | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | |||
| 56 | package Bio::EnsEMBL::Utils::Sequence; | ||
| 57 | $Bio::EnsEMBL::Utils::Sequence::VERSION = '114.0.0'; | ||
| 58 | use strict; | ||
| 59 | use warnings; | ||
| 60 | |||
| 61 | use Exporter; | ||
| 62 | |||
| 63 | use vars qw(@ISA @EXPORT_OK); | ||
| 64 | |||
| 65 | @ISA = qw(Exporter); | ||
| 66 | |||
| 67 | @EXPORT_OK = qw(&reverse_comp &expand); | ||
| 68 | |||
| 69 | |||
| 70 | =head2 reverse_comp | ||
| 71 | |||
| 72 | Arg [1] : reference to a string $seqref | ||
| 73 | Example : use Bio::EnsEMBL::Utils::Sequence qw(reverse_comp); | ||
| 74 | |||
| 75 | $seq = 'ACCTGAA'; | ||
| 76 | reverse_comp(\$seq); | ||
| 77 | print $seq; | ||
| 78 | |||
| 79 | Description: Does an in place reverse compliment of a passed in string | ||
| 80 | reference. The string is passed by reference | ||
| 81 | rather than by value for memory efficiency. | ||
| 82 | Returntype : none | ||
| 83 | Exceptions : none | ||
| 84 | Caller : SequenceAdaptor, SliceAdaptor | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | sub reverse_comp { | ||
| 89 | my $seqref = shift; | ||
| 90 | |||
| 91 | $$seqref = reverse( $$seqref ); | ||
| 92 | $$seqref =~ | ||
| 93 | tr/acgtrymkswhbvdnxACGTRYMKSWHBVDNX/tgcayrkmswdvbhnxTGCAYRKMSWDVBHNX/; | ||
| 94 | |||
| 95 | return; | ||
| 96 | } | ||
| 97 | |||
| 98 | =head2 expand | ||
| 99 | |||
| 100 | Arg [1] : reference to a string $seqref | ||
| 101 | Example : use Bio::EnsEMBL::Utils::Sequence qw(expand); | ||
| 102 | |||
| 103 | $seq = '(AC)3'; | ||
| 104 | expand(\$seq); | ||
| 105 | print $seq; | ||
| 106 | |||
| 107 | |||
| 108 | Description: Expands a genomic sequence. The string is passed by reference | ||
| 109 | rather than by value for memory efficiency. | ||
| 110 | Returntype : none | ||
| 111 | Exceptions : none | ||
| 112 | Caller : SequenceAdaptor, SliceAdaptor | ||
| 113 | |||
| 114 | =cut | ||
| 115 | |||
| 116 | sub expand { | ||
| 117 | my $seq_ref = shift; | ||
| 118 | $$seq_ref =~ s/(\w*)\((\w+)\)(\d+)/$1.$2 x $3/eg if ($$seq_ref =~ /\(/);#expressions with parenthesis, expand the alleles | ||
| 119 | return; | ||
| 120 | } | ||
| 121 | |||
| 122 | |||
| 123 | 1; |