.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Bio::SeqIO 3pm" .TH Bio::SeqIO 3pm "2020-10-28" "perl v5.30.3" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Bio::SeqIO \- Handler for SeqIO Formats .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Bio::SeqIO; \& \& $in = Bio::SeqIO\->new(\-file => "inputfilename" , \& \-format => \*(AqFasta\*(Aq); \& $out = Bio::SeqIO\->new(\-file => ">outputfilename" , \& \-format => \*(AqEMBL\*(Aq); \& \& while ( my $seq = $in\->next_seq() ) { \& $out\->write_seq($seq); \& } \& \& # Now, to actually get at the sequence object, use the standard Bio::Seq \& # methods (look at Bio::Seq if you don\*(Aqt know what they are) \& \& use Bio::SeqIO; \& \& $in = Bio::SeqIO\->new(\-file => "inputfilename" , \& \-format => \*(Aqgenbank\*(Aq); \& \& while ( my $seq = $in\->next_seq() ) { \& print "Sequence ",$seq\->id, " first 10 bases ", \& $seq\->subseq(1,10), "\en"; \& } \& \& \& # The SeqIO system does have a filehandle binding. Most people find this \& # a little confusing, but it does mean you can write the world\*(Aqs \& # smallest reformatter \& \& use Bio::SeqIO; \& \& $in = Bio::SeqIO\->newFh(\-file => "inputfilename" , \& \-format => \*(AqFasta\*(Aq); \& $out = Bio::SeqIO\->newFh(\-format => \*(AqEMBL\*(Aq); \& \& # World\*(Aqs shortest Fasta<\->EMBL format converter: \& print $out $_ while <$in>; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Bio::SeqIO is a handler module for the formats in the SeqIO set (eg, Bio::SeqIO::fasta). It is the officially sanctioned way of getting at the format objects, which most people should use. .PP The Bio::SeqIO system can be thought of like biological file handles. They are attached to filehandles with smart formatting rules (eg, genbank format, or \s-1EMBL\s0 format, or binary trace file format) and can either read or write sequence objects (Bio::Seq objects, or more correctly, Bio::SeqI implementing objects, of which Bio::Seq is one such object). If you want to know what to do with a Bio::Seq object, read Bio::Seq. .PP The idea is that you request a stream object for a particular format. All the stream objects have a notion of an internal file that is read from or written to. A particular SeqIO object instance is configured for either input or output. A specific example of a stream object is the Bio::SeqIO::fasta object. .PP Each stream object has functions .PP .Vb 1 \& $stream\->next_seq(); .Ve .PP and .PP .Vb 1 \& $stream\->write_seq($seq); .Ve .PP As an added bonus, you can recover a filehandle that is tied to the SeqIO object, allowing you to use the standard <> and print operations to read and write sequence objects: .PP .Vb 1 \& use Bio::SeqIO; \& \& $stream = Bio::SeqIO\->newFh(\-format => \*(AqFasta\*(Aq, \& \-fh => \e*ARGV); \& # read from standard input or the input filenames \& \& while ( $seq = <$stream> ) { \& # do something with $seq \& } .Ve .PP and .PP .Vb 1 \& print $stream $seq; # when stream is in output mode .Ve .PP This makes the simplest ever reformatter .PP .Vb 5 \& #!/usr/bin/perl \& use strict; \& my $format1 = shift; \& my $format2 = shift || die \& "Usage: reformat format1 format2 < input > output"; \& \& use Bio::SeqIO; \& \& my $in = Bio::SeqIO\->newFh(\-format => $format1, \-fh => \e*ARGV ); \& my $out = Bio::SeqIO\->newFh(\-format => $format2 ); \& # Note: you might want to quote \-format to keep older \& # perl\*(Aqs from complaining. \& \& print $out $_ while <$in>; .Ve .SH "CONSTRUCTORS" .IX Header "CONSTRUCTORS" .SS "Bio::SeqIO\->\fBnew()\fP" .IX Subsection "Bio::SeqIO->new()" .Vb 4 \& $seqIO = Bio::SeqIO\->new(\-file => \*(Aqseqs.fasta\*(Aq, \-format => $format); \& $seqIO = Bio::SeqIO\->new(\-fh => \e*FILEHANDLE, \-format => $format); \& $seqIO = Bio::SeqIO\->new(\-string => $string , \-format => $format); \& $seqIO = Bio::SeqIO\->new(\-format => $format); .Ve .PP The \fBnew()\fR class method constructs a new Bio::SeqIO object. The returned object can be used to retrieve or print Seq objects. \fBnew()\fR accepts the following parameters: .IP "\-file" 5 .IX Item "-file" A file path to be opened for reading or writing. The usual Perl conventions apply: .Sp .Vb 4 \& \*(Aqfile\*(Aq # open file for reading \& \*(Aq>file\*(Aq # open file for writing \& \*(Aq>>file\*(Aq # open file for appending \& \*(Aq+new(\-fh => \e*STDIN); .Ve .Sp A string filehandle is handy if you want to modify the output in the memory, before printing it out. The following program reads in \s-1EMBL\s0 formatted entries from a file and prints them out in fasta format with some \s-1HTML\s0 tags: .Sp .Vb 10 \& use Bio::SeqIO; \& use IO::String; \& my $in = Bio::SeqIO\->new(\-file => "emblfile", \& \-format => \*(AqEMBL\*(Aq); \& while ( my $seq = $in\->next_seq() ) { \& # the output handle is reset for every file \& my $stringio = IO::String\->new($string); \& my $out = Bio::SeqIO\->new(\-fh => $stringio, \& \-format => \*(Aqfasta\*(Aq); \& # output goes into $string \& $out\->write_seq($seq); \& # modify $string \& $string =~ s|(>)(\ew+)|$1$2|g; \& # print into STDOUT \& print $string; \& } .Ve .Sp Filehandles can also be used to read from or write to a piped command: .Sp .Vb 10 \& use Bio::SeqIO; \& #convert .fastq.gz to .fasta \& open my $zcat, \*(Aqzcat seq.fastq.gz |\*(Aq or die $!; \& my $in=Bio::SeqIO\->new(\-fh=>$zcat, \& \-format=>\*(Aqfastq\*(Aq); \& my $out=Bio::SeqIO\->new(\-file=>\*(Aq>seq.fasta\*(Aq, \& \-format=>\*(Aqfasta\*(Aq); \& while (my $seq=$in\->next_seq) { \& $out\->write_seq($seq) \& } .Ve .IP "\-string" 5 .IX Item "-string" A string to read the sequences from. For example: .Sp .Vb 2 \& my $string = ">seq1\enACGCTAGCTAGC\en"; \& my $seqIO = Bio::SeqIO\->new(\-string => $string); .Ve .IP "\-format" 5 .IX Item "-format" Specify the format of the file. Supported formats include fasta, genbank, embl, swiss (SwissProt), Entrez Gene and tracefile formats such as abi (\s-1ABI\s0) and scf. There are many more, for a complete listing see the SeqIO \s-1HOWTO\s0 (). .Sp If no format is specified and a filename is given then the module will attempt to deduce the format from the filename suffix. If there is no suffix that Bioperl understands then it will attempt to guess the format based on file content. If this is unsuccessful then SeqIO will throw a fatal error. .Sp The format name is case-insensitive: '\s-1FASTA\s0', 'Fasta' and 'fasta' are all valid. .IP "\-alphabet" 5 .IX Item "-alphabet" Sets the alphabet ('dna', 'rna', or 'protein'). When the alphabet is set then Bioperl will not attempt to guess what the alphabet is. This may be important because Bioperl does not always guess correctly. .IP "\-flush" 5 .IX Item "-flush" By default, all files (or filehandles) opened for writing sequences will be flushed after each \fBwrite_seq()\fR (making the file immediately usable). If you do not need this facility and would like to marginally improve the efficiency of writing multiple sequences to the same file (or filehandle), pass the \-flush option '0' or any other value that evaluates as defined but false: .Sp .Vb 6 \& my $gb = Bio::SeqIO\->new(\-file => " "gb"); \& my $fa = Bio::SeqIO\->new(\-file => ">gball.fa", \& \-format => "fasta", \& \-flush => 0); # go as fast as we can! \& while($seq = $gb\->next_seq) { $fa\->write_seq($seq) } .Ve .IP "\-seqfactory" 5 .IX Item "-seqfactory" Provide a Bio::Factory::SequenceFactoryI object. See the \fBsequence_factory()\fR method. .IP "\-locfactory" 5 .IX Item "-locfactory" Provide a Bio::Factory::LocationFactoryI object. See the \fBlocation_factory()\fR method. .IP "\-objbuilder" 5 .IX Item "-objbuilder" Provide a Bio::Factory::ObjectBuilderI object. See the \fBobject_builder()\fR method. .SS "Bio::SeqIO\->\fBnewFh()\fP" .IX Subsection "Bio::SeqIO->newFh()" .Vb 3 \& $fh = Bio::SeqIO\->newFh(\-fh => \e*FILEHANDLE, \-format=>$format); \& $fh = Bio::SeqIO\->newFh(\-format => $format); \& # etc. .Ve .PP This constructor behaves like \fBnew()\fR, but returns a tied filehandle rather than a Bio::SeqIO object. You can read sequences from this object using the familiar <> operator, and write to it using \&\fBprint()\fR. The usual array and \f(CW$_\fR semantics work. For example, you can read all sequence objects into an array like this: .PP .Vb 1 \& @sequences = <$fh>; .Ve .PP Other operations, such as \fBread()\fR, \fBsysread()\fR, \fBwrite()\fR, \fBclose()\fR, and \&\fBprintf()\fR are not supported. .SH "OBJECT METHODS" .IX Header "OBJECT METHODS" See below for more detailed summaries. The main methods are: .ie n .SS "$sequence = $seqIO\->\fBnext_seq()\fP" .el .SS "\f(CW$sequence\fP = \f(CW$seqIO\fP\->\fBnext_seq()\fP" .IX Subsection "$sequence = $seqIO->next_seq()" Fetch the next sequence from the stream, or nothing if no more. .ie n .SS "$seqIO\->write_seq($sequence [,$another_sequence,...])" .el .SS "\f(CW$seqIO\fP\->write_seq($sequence [,$another_sequence,...])" .IX Subsection "$seqIO->write_seq($sequence [,$another_sequence,...])" Write the specified sequence(s) to the stream. .SS "\s-1\fBTIEHANDLE\s0()\fP, \s-1\fBREADLINE\s0()\fP, \s-1\fBPRINT\s0()\fP" .IX Subsection "TIEHANDLE(), READLINE(), PRINT()" These provide the tie interface. See perltie for more details. .SH "FEEDBACK" .IX Header "FEEDBACK" .SS "Mailing Lists" .IX Subsection "Mailing Lists" User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to one of the Bioperl mailing lists. .PP Your participation is much appreciated. .PP .Vb 2 \& bioperl\-l@bioperl.org \- General discussion \& http://bioperl.org/wiki/Mailing_lists \- About the mailing lists .Ve .SS "Support" .IX Subsection "Support" Please direct usage questions or support issues to the mailing list: .PP .Vb 1 \& bioperl\-l@bioperl.org .Ve .PP rather than to the module maintainer directly. Many experienced and responsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. .SS "Reporting Bugs" .IX Subsection "Reporting Bugs" Report bugs to the Bioperl bug tracking system to help us keep track the bugs and their resolution. Bug reports can be submitted via the web: .PP .Vb 1 \& https://github.com/bioperl/bioperl\-live/issues .Ve .SH "AUTHOR \- Ewan Birney, Lincoln Stein" .IX Header "AUTHOR - Ewan Birney, Lincoln Stein" Email birney@ebi.ac.uk lstein@cshl.org .SH "APPENDIX" .IX Header "APPENDIX" The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ .SS "new" .IX Subsection "new" .Vb 10 \& Title : new \& Usage : $stream = Bio::SeqIO\->new(\-file => \*(Aqsequences.fasta\*(Aq, \& \-format => \*(Aqfasta\*(Aq); \& Function: Returns a new sequence stream \& Returns : A Bio::SeqIO stream initialised with the appropriate format \& Args : Named parameters indicating where to read the sequences from or to \& write them to: \& \-file => filename, OR \& \-fh => filehandle to attach to, OR \& \-string => string \& \& Additional arguments, all with reasonable defaults: \& \-format => format of the sequences, usually auto\-detected \& \-alphabet => \*(Aqdna\*(Aq, \*(Aqrna\*(Aq, or \*(Aqprotein\*(Aq \& \-flush => 0 or 1 (default: flush filehandles after each write) \& \-seqfactory => sequence factory \& \-locfactory => location factory \& \-objbuilder => object builder .Ve .PP See Bio::SeqIO::Handler .SS "newFh" .IX Subsection "newFh" .Vb 8 \& Title : newFh \& Usage : $fh = Bio::SeqIO\->newFh(\-file=>$filename,\-format=>\*(AqFormat\*(Aq) \& Function: Does a new() followed by an fh() \& Example : $fh = Bio::SeqIO\->newFh(\-file=>$filename,\-format=>\*(AqFormat\*(Aq) \& $sequence = <$fh>; # read a sequence object \& print $fh $sequence; # write a sequence object \& Returns : filehandle tied to the Bio::SeqIO::Fh class \& Args : .Ve .PP See Bio::SeqIO::Fh .SS "fh" .IX Subsection "fh" .Vb 8 \& Title : fh \& Usage : $obj\->fh \& Function: Get or set the IO filehandle \& Example : $fh = $obj\->fh; # make a tied filehandle \& $sequence = <$fh>; # read a sequence object \& print $fh $sequence; # write a sequence object \& Returns : filehandle tied to Bio::SeqIO class \& Args : none .Ve .SS "next_seq" .IX Subsection "next_seq" .Vb 3 \& Title : next_seq \& Usage : $seq = stream\->next_seq \& Function: Reads the next sequence object from the stream and returns it. \& \& Certain driver modules may encounter entries in the stream \& that are either misformatted or that use syntax not yet \& understood by the driver. If such an incident is \& recoverable, e.g., by dismissing a feature of a feature \& table or some other non\-mandatory part of an entry, the \& driver will issue a warning. In the case of a \& non\-recoverable situation an exception will be thrown. Do \& not assume that you can resume parsing the same stream \& after catching the exception. Note that you can always turn \& recoverable errors into exceptions by calling \& $stream\->verbose(2). \& \& Returns : a Bio::Seq sequence object, or nothing if no more sequences \& are available \& \& Args : none .Ve .PP See Bio::Root::RootI, Bio::Factory::SeqStreamI, Bio::Seq .SS "write_seq" .IX Subsection "write_seq" .Vb 5 \& Title : write_seq \& Usage : $stream\->write_seq($seq) \& Function: writes the $seq object into the stream \& Returns : 1 for success and 0 for error \& Args : Bio::Seq object .Ve .SS "format" .IX Subsection "format" .Vb 5 \& Title : format \& Usage : $format = $stream\->format() \& Function: Get the sequence format \& Returns : sequence format, e.g. fasta, fastq \& Args : none .Ve .SS "alphabet" .IX Subsection "alphabet" .Vb 7 \& Title : alphabet \& Usage : $self\->alphabet($newval) \& Function: Set/get the molecule type for the Seq objects to be created. \& Example : $seqio\->alphabet(\*(Aqprotein\*(Aq) \& Returns : value of alphabet: \*(Aqdna\*(Aq, \*(Aqrna\*(Aq, or \*(Aqprotein\*(Aq \& Args : newvalue (optional) \& Throws : Exception if the argument is not one of \*(Aqdna\*(Aq, \*(Aqrna\*(Aq, or \*(Aqprotein\*(Aq .Ve .SS "_load_format_module" .IX Subsection "_load_format_module" .Vb 6 \& Title : _load_format_module \& Usage : *INTERNAL SeqIO stuff* \& Function: Loads up (like use) a module at run time on demand \& Example : \& Returns : \& Args : .Ve .SS "_concatenate_lines" .IX Subsection "_concatenate_lines" .Vb 5 \& Title : _concatenate_lines \& Usage : $s = _concatenate_lines($line, $continuation_line) \& Function: Private. Concatenates two strings assuming that the second stems \& from a continuation line of the first. Adds a space between both \& unless the first ends with a dash. \& \& Takes care of either arg being empty. \& Example : \& Returns : A string. \& Args : .Ve .SS "_filehandle" .IX Subsection "_filehandle" .Vb 6 \& Title : _filehandle \& Usage : $obj\->_filehandle($newval) \& Function: This method is deprecated. Call _fh() instead. \& Example : \& Returns : value of _filehandle \& Args : newvalue (optional) .Ve .SS "_guess_format" .IX Subsection "_guess_format" .Vb 9 \& Title : _guess_format \& Usage : $obj\->_guess_format($filename) \& Function: guess format based on file suffix \& Example : \& Returns : guessed format of filename (lower case) \& Args : \& Notes : formats that _filehandle() will guess include fasta, \& genbank, scf, pir, embl, raw, gcg, ace, bsml, swissprot, \& fastq and phd/phred .Ve .SS "sequence_factory" .IX Subsection "sequence_factory" .Vb 5 \& Title : sequence_factory \& Usage : $seqio\->sequence_factory($seqfactory) \& Function: Get/Set the Bio::Factory::SequenceFactoryI \& Returns : Bio::Factory::SequenceFactoryI \& Args : [optional] Bio::Factory::SequenceFactoryI .Ve .SS "object_factory" .IX Subsection "object_factory" .Vb 6 \& Title : object_factory \& Usage : $obj\->object_factory($newval) \& Function: This is an alias to sequence_factory with a more generic name. \& Example : \& Returns : value of object_factory (a scalar) \& Args : on set, new value (a scalar or undef, optional) .Ve .SS "sequence_builder" .IX Subsection "sequence_builder" .Vb 5 \& Title : sequence_builder \& Usage : $seqio\->sequence_builder($seqfactory) \& Function: Get/Set the Bio::Factory::ObjectBuilderI used to build sequence \& objects. This applies to rich sequence formats only, e.g. genbank \& but not fasta. \& \& If you do not set the sequence object builder yourself, it \& will in fact be an instance of L, and \& you may use all methods documented there to configure it. \& \& Returns : a Bio::Factory::ObjectBuilderI compliant object \& Args : [optional] a Bio::Factory::ObjectBuilderI compliant object .Ve .SS "location_factory" .IX Subsection "location_factory" .Vb 7 \& Title : location_factory \& Usage : $seqio\->location_factory($locfactory) \& Function: Get/Set the Bio::Factory::LocationFactoryI object to be used for \& location string parsing \& Returns : a Bio::Factory::LocationFactoryI implementing object \& Args : [optional] on set, a Bio::Factory::LocationFactoryI implementing \& object. .Ve