#!perl -w use strict; # documentation written in pod, perldoc perlpod =head1 NAME Seq.pm =head1 DESCRIPTION Seq Object definition and methods for sequences. =head1 SYNOPSIS use Seq; my $seq = new Seq("CATTAGGCTAATAATAAAAA"); =head1 USAGE my $dna = $seq->concatenate("CATGCCTAAAATA"); my $rna = $seq->dna2rna( ); my $seq = $seq->revcom( ); print $seq->print_dna( ); =head1 NOTES Sequences can be nucleotides and proteins. They may manipulate with various utilities. =head1 AUTHOR David Scott =head1 METHODS Method documentation follows: =over 4 =cut package Seq; use SeqFun qw/slurp/; # constructors =item my $seq = Seq->new("CATG"); =item my $seq = new Seq("CATG"); =item my $seq = Seq->new($dna); =item my $seq = new Seq($dna); =item my $seq2 = $seq->new($dna); Creates a sequence from the 1st argument. DEFAULT is "". =cut sub new { my ($self) = shift; # force a valid classname for objects my $class = ref($self) || $self; $self = { seq => shift || "", filename => "" }; return bless($self, $class); } =item my $seq = Seq->read("hox.dna"); =item my $seq = Seq::read Seq("hox.dna"); =item my $seq = Seq->read($filename); =item my $seq = Seq::read Seq($filename); =item my $seq2 = $seq->read($filename); Creates a sequence from the $filename. DEFAULT is "". =cut sub read { my ($self) = shift; my $class = ref($self) || $self; $self = { seq => "", filename => shift || "" }; my $ref = slurp($self->{filename}); $self->{seq} = $$ref; # copy data in return bless($self, $class); } # object methods =item my $mySeq = $seq->concatenate($dna1, $dna2, ... ); Return a Seq object which concatenates any dna sequences passed in to this Seq object. =cut sub concatenate { my ($self, @dna) = @_; my $result = $self->{seq}; foreach (@dna) { $result .= $_; } return Seq->new($result); } =item my $rna = $dna->dna2rna(); Return a Seq object that is rna, transcribe the DNA to RNA by substituting all T's with U's. =cut sub dna2rna { my $self = shift; my $rna = $self->{seq}; $rna =~ s/T/U/g; return Seq->new($rna); } =item my $text = $seq->print_dna(); return text of dna. =cut sub print_dna { my $self = shift; return $self->{seq} . "\n"; } =item my $seq = $dna->revcom() Return a Seq object that is the reverse complement of the $dna sequence. =cut sub revcom { my $self = shift; my $revcom = reverse $self->{seq}; $revcom =~ tr/ACGTacgt/TGCAtgca/; return new Seq->new($revcom); } 1; # successful -- library loaded