Main Program Parsing Annotations
10.4.3 Main Program
Lets test these subroutines with Example 10-5 , which has some subroutine definitions that will be added to the BeginPerlBioinfo.pm module: Example 10-5. GenBank library subroutines usrbinperl - test program of GenBank library subroutines use strict; use warnings; Dont use BeginPerlBioinfo Since all subroutines defined in this file use BeginPerlBioinfo; see Chapter 6 about this module Declare and initialize variables my fh; variable to store filehandle my record; my dna; my annotation; my offset; my library = library.gb; Perform some standard subroutines for test fh = open_filelibrary; offset = tellfh; while record = get_next_recordfh { annotation, dna = get_annotation_and_dnarecord; if search_sequencedna, AAA[CG]. { print Sequence found in record at offset offset\n; } if search_annotationannotation, homo sapiens { print Annotation found in record at offset offset\n; } offset = tellfh; IT-SC 247 } exit; Subroutines open_file - given filename, set filehandle sub open_file { myfilename = _; my fh; unlessopenfh, filename { print Cannot open file filename\n; exit; } return fh; } get_next_record - given GenBank record, get annotation and DNA sub get_next_record { myfh = _; myoffset; myrecord = ; mysave_input_separator = ; = \n; record = fh; = save_input_separator; return record; } IT-SC 248 get_annotation_and_dna - given GenBank record, get annotation and DNA sub get_annotation_and_dna { myrecord = _; myannotation = ; mydna = ; Now separate the annotation from the sequence data annotation, dna = record =~ LOCUS.ORIGIN\s\n.\\\ns; clean the sequence of any whitespace or characters the has to be written \ in the character class, because is a metacharacter, so it must be escaped with \ dna =~ s[\s\]g; returnannotation, dna } search_sequence - search sequence with regular expression sub search_sequence { mysequence, regularexpression = _; mylocations = ; while sequence =~ regularexpressionig { push locations, pos ; } return locations; } search_annotation - search annotation with regular expression sub search_annotation { IT-SC 249 myannotation, regularexpression = _; mylocations = ; note the s modifier--. matches any character including newline while annotation =~ regularexpressionisg { push locations, pos ; } return locations; } Example 10-5 generates the following output on our little GenBank library: Sequence found in record at offset 0 Annotation found in record at offset 0 Sequence found in record at offset 6256 Annotation found in record at offset 6256 Sequence found in record at offset 12366 Annotation found in record at offset 12366 Sequence found in record at offset 17730 Annotation found in record at offset 17730 Sequence found in record at offset 22340 Annotation found in record at offset 22340 The tell function reports the byte offset of the file up to the point where its been read; so you want to first call tell and then read the record to get the proper offset associated with the beginning of the record.10.4.4 Parsing Annotations at the Top Level
Parts
» OReilly.Beginning.Perl For Bioinformatics
» The Organization of Proteins
» In Silico Biology and Computer Science
» A Low and Long Learning Curve
» Ease of Programming Rapid Prototyping
» Portability, Speed, and Program Maintenance
» Perl May Already Be Installed No Internet Access?
» Downloading Binary Versus Source Code
» Unix and Linux Macintosh Windows
» Unix or Linux How to Run Perl Programs
» Text Editors Getting Started with Perl
» Finding Help Getting Started with Perl
» Saves and Backups Error Messages
» Individual Approaches to Programming Programming Strategies
» The Design Phase The Programming Process
» Algorithms The Programming Process
» Pseudocode and Code Comments
» Representing Sequence Data Sequences and Strings
» Control Flow Comments Revisited Command Interpretation
» Assignment Print Exit Statements
» Concatenating DNA Fragments Sequences and Strings
» Using the Perl Documentation
» Calculating the Reverse Complement in Perl
» Proteins, Files, and Arrays Reading Proteins in Files
» Arrays Sequences and Strings
» Scalar and List Context Exercises
» Conditional tests and matching braces
» Code Layout Motifs and Loops
» Getting User Input from the Keyboard Turning Arrays into Scalars with join
» Regular expressions and character classes
» Counting Nucleotides Motifs and Loops
» Exploding Strings into Arrays
» Operating on Strings Motifs and Loops
» Writing to Files Motifs and Loops
» Advantages of Subroutines Subroutines
» Arguments Scoping and Subroutines
» Scoping Scoping and Subroutines
» Command-Line Arguments and Arrays
» Subroutines: Pass by Value Subroutines: Pass by Reference
» Modules and Libraries of Subroutines
» use warnings; and use strict; Fixing Bugs with Comments and Print Statements
» How to start and stop the debugger Debugger command summary
» Stepping through statements with the debugger
» Setting breakpoints The Perl Debugger
» Fixing another bug use warnings; and use strict; redux
» Exercises Subroutines and Bugs
» Random Number Generators Mutations and Randomization
» Seeding the Random Number Generator Control Flow
» Making a Sentence Randomly Selecting an Element of an Array
» Formatting A Program Using Randomization
» Select a random position in a string Choose a random nucleotide
» Improving the Design Combining the Subroutines to Simulate Mutation
» Exercises Mutations and Randomization
» A Gene Expression Database Gene Expression Data Using Unsorted Arrays
» Gene Expression Data Using Sorted Arrays and Binary Search
» Gene Expression Data Using Hashes
» Translating Codons to Amino Acids
» The Redundancy of the Genetic Code
» Using Hashes for the Genetic Code
» Translating DNA into Proteins
» FASTA Format Reading DNA from Files in FASTA Format
» A Design to Read FASTA Files
» A Subroutine to Read FASTA Files
» Writing Formatted Sequence Data
» Regular Expressions Restriction Maps and Regular Expressions
» Background Planning the Program
» Restriction Enzyme Data Restriction Maps and Restriction Enzymes
» Logical Operators and the Range Operator
» Finding the Restriction Sites
» Exercises Restriction Maps and Regular Expressions
» Using Arrays Separating Sequence and Annotation
» Pattern modifiers Examples of pattern modifiers
» Separating annotations from sequence
» Using Arrays Parsing Annotations
» When to Use Regular Expressions
» Main Program Parsing Annotations
» Parsing Annotations at the Top Level
» Features Parsing the FEATURES Table
» Parsing Parsing the FEATURES Table
» DBM Essentials Indexing GenBank with DBM
» Overview of PDB Protein Data Bank
» Opening Directories Files and Folders
» Processing Many Files Files and Folders
» Extracting Primary Sequence Parsing PDB Files
» Finding Atomic Coordinates Parsing PDB Files
» The Stride Secondary Structure Predictor
» Parsing Stride Output Controlling Other Programs
» String Matching and Homology
» Extracting Annotation and Alignments
» Parsing BLAST Alignments Parsing BLAST Output
» The printf Function Presenting Data
» here Documents format and write
» Bioperl Tutorial Script Bioperl
» The Art of Program Design Web Programming
» Algorithms and Sequence Alignment Object-Oriented Programming Complex Data Structures
Show more