330 likes | 1.02k Views
Object Oriented Perl. Object Oriented Perl. Object Oriented Programming is a common method for encapsulation of code Object Oriented Programming allows you to use very complex methods without ever having to write them or even understand them
E N D
Object Oriented Perl • Object Oriented Programming is a common method for encapsulation of code • Object Oriented Programming allows you to use very complex methods without ever having to write them or even understand them • We will cover Object Oriented Perl because BioPerl is written as Object Oriented
Object Oriented Perl Vocabulary: • Object: a collection of data that logically belongs together • Method: a subroutine that is associated with an object • Class: object definition and the collection of methods available to an object define a class
Object Oriented Perl • For Example: a Genbank object would be a collection of data that logically belong together • sequence • accession • description • features • journal reference • Objects are often implemented as hashes
Object Oriented Perl • Class methods are the subroutines that are associated with an object • Class methods are the only methods that may be used • This makes sure that objects behave as they are intended • You don't have to understand the internal workings of a method in order to use it
Object Oriented Perl • BioPerl is a collection of Classes that are useful for bioinformatics • use perldoc to get information about the classes and their methods • perldoc Bio::Perl • perldoc Bio::Seq • perldoc Bio::SeqIO
Object Oriented Perl • In order to use an Object and its associated methods, you must include a 'use' statement use Bio::Perl; go to biotest1.pl
Object Oriented Perl • Bio::Perl can read sequence files in multiple different formats and interchange them easily • For instance: take a GenBank file and convert it to a fasta file go to biotest2.pl
Object Oriented Perl go to biotest2_1.pl
Object Oriented Perl perldoc Bio::Perl
Object Oriented Perl • Advantages to reading a library of fasta files with Bio::Perl • Don't have to write subs to open files and parse individual entries • Don't have to write subs to extract sequence, accession or features
Object Oriented Perl • Methods are called by invoking the method through the object using the -> operator object->method(argument); $acc = $seq_object->accession_number(); • accession_number is a method defined in the class Bio::Perl and invoked with the -> operator
Object Oriented Perl • Note the difference between substring and subseq • substr is a perl function that can be called on any string • subseq is a Bio::Perl method that can only be called on a Bio::Perl object • substr index starts at 0 << typical computer science • subseq index starts at 1 << typical for DNA sequences
Object Oriented Perl • Accessor methods: give the user access to data in an object • Get information (call method with no argument) $acc = $seq_object->accession_number(); • Set information (call method with argument) $seq_object->accession_number("New_number");
Object Oriented Perl • Bio::Perl uses LWP to access databases and programs over the web • You can get sequences from standard databases like GenBank, EMBL, Swissprot, etc • You can run blast searches using Bio::Perl
Object Oriented Perl go to biotest3.pl
Object Oriented Perl • Bio::Perl Methods Read one or more sequences from a file $seq_object = read_sequence($filename); @seq_object_array = read_all_sequences($filename,'fasta'); Get Information about a sequence $id = $seq_object->display_id(); $acc = $seq_object->accession_number(); $seq = $seq_object->subseq(1,5); $seq = $seq_object->seq();
Object Oriented Perl • Bio::Perl Methods Write a Sequence to a file write_sequence(">$filename",'genbank',$seq_object); write_sequence(">$filename",'genbank',@seq_object_array); Get a Sequence from a Database $seq_object = get_sequence('swissprot',"ROA1_HUMAN"); $seq_object = get_sequence('embl',"AI129902"); $seq_object = get_sequence('genbank',"AI129902");
Object Oriented Perl • Bio::Perl Methods BLAST a sequence $blast_report = blast_sequence($seq_object); write_blast(">blast.out",$blast_report); Sequence mainpulations $seqobj = translate($seq_or_string_scalar); $seqstring = translate_as_string($seq_or_string_scalar); $seqobj = reverse_complement($seq_or_string_scalar); $string = reverse_complement_as_string($seq_or_string_scalar);
Object Oriented Perl • The Bio::Perl package is written for "people who don't know objects" • Syntax and usage are not typical for OO programs • Easy to use without much knowledge • But limited. • Better to learn some OO syntax and use the more sophisticated objects
Object Oriented Perl • Bio::Seq and Bio::SeqIO are Classes of sequence objects that have many excellent methods • To use these classes you also need to include a "use" statement • You also need to "instantiate" an object (create an instance of an object)
Object Oriented Perl • Most objects contain a method called the "constructor". • The constructor is used to create new instances of an object • Usually the method name for the constructor is "new"
Object Oriented Perl • Create a sequence object from a file go to biotest4.pl
Object Oriented Perl • Create a sequence object from a file
Object Oriented Perl • The Bio::SeqIO package lets you set up a stream of sequence objects using library files go to biotest5.pl