Bio::AlignIO(3pm)

πŸ“¦
version 1.7.8 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– Bio::AlignIO β€” the manual, but make it make sense πŸ’–

Bio::AlignIO β€” the handler for AlignIO formats. This is Bio::AlignIO(3pm), the User Contributed Perl Documentation version, and bestie, we are getting through this together.


✨ NAME ✨

Bio::AlignIO β€” the Handler for AlignIO Formats. That's it, that's the name, she's a handler and she handles. πŸ‘‘


🌈 SYNOPSIS 🌈

Okay so here's the vibe. You want in, you want out, you want it converted:

use Bio::AlignIO;

$inputfilename = "testaln.fasta";
$in  = Bio::AlignIO->new(-file   => $inputfilename ,
                         -format => 'fasta');
$out = Bio::AlignIO->new(-file   => ">out.aln.pfam" ,
                         -format => 'pfam');

while ( my $aln = $in->next_aln() ) {
    $out->write_aln($aln);
}

OR β€” because there's always an OR, she's flexible like that β€” you can do the filehandle thing:

use Bio::AlignIO;

open MYIN, '<', 'testaln.fasta' or die "Could not read file 'testaln.fasta': $!\n";
$in  = Bio::AlignIO->newFh(-fh     => \*MYIN,
                           -format => 'fasta');
open my $MYOUT, '>', 'testaln.pfam' or die "Could not write file 'testaln.pfam': $!\n";
$out = Bio::AlignIO->newFh(-fh     =>  $MYOUT,
                           -format => 'pfam');

# World's smallest Fasta<->pfam format converter:
print $out $_ while <$in>;

Not me showing you the world's smallest Fasta<->pfam format converter like it's nothing. She ate and left no crumbs. πŸ”₯


πŸ¦‹ DESCRIPTION πŸ¦‹

Bio::AlignIO is a handler module for the formats in the AlignIO set β€” like, for example, Bio::AlignIO::fasta. It is the officially sanctioned way of getting at the alignment objects. And the resulting alignment? It's a Bio::Align::AlignI-compliant object. Periodt. πŸ’…

The idea is simple, bestie: you request an object for a particular format. All the objects have a notion of an internal file that is read from or written to. A particular AlignIO object instance is configured for either input or output β€” think of it as a stream object, because that's literally what it is.

Each object has functions:

$stream->next_aln();

And:

$stream->write_aln($aln);

Also:

$stream->type() # returns 'INPUT' or 'OUTPUT'

As an added bonus 🎁 β€” you can recover a filehandle that is tied to the AlignIO object, which means you get to use the standard <> and print operations to read and write alignment objects:

use Bio::AlignIO;

# read from standard input
$stream = Bio::AlignIO->newFh(-format => 'Fasta');

while ( $aln = <$stream> ) {
         # do something with $aln
}

And:

print $stream $aln; # when stream is in output mode

Bio::AlignIO is patterned on the Bio::SeqIO module and shares most of its features. But there's one significant difference, and it's kind of the whole personality: Bio::AlignIO usually handles IO for only a single alignment at a time, whereas Bio::SeqIO handles IO for multiple sequences in a single stream. Why? Because simultaneously handling multiple sequences is a common requirement, and simultaneous handling of multiple alignments is... not. It's giving "I'm not doing all that."

The only current exception is the format "bl2seq", which parses results of the BLAST "bl2seq" program and which may produce several alignment pairs. This set of alignment pairs can be read using multiple calls to next_aln. She's got range, okay? ✨


πŸŽ€ CONSTRUCTORS πŸŽ€

πŸ’œ Bio::AlignIO->new()

$seqIO = Bio::AlignIO->new(-file => 'filename',   -format=>$format);
$seqIO = Bio::AlignIO->new(-fh   => \*FILEHANDLE, -format=>$format);
$seqIO = Bio::AlignIO->new(-format => $format);
$seqIO = Bio::AlignIO->new(-fh => \*STDOUT, -format => $format);

The new class method constructs a new Bio::AlignIO object. The returned object can be used to retrieve or print alignment objects. new accepts the following parameters:

  • -file β€” a file path to be opened for reading or writing. The usual Perl conventions apply, so know your prefixes, bestie:
'file'       # open file for reading
'>file'      # open file for writing
'>>file'     # open file for appending
'+<file'     # open file read/write
'command |'  # open a pipe from the command
'| command'  # open a pipe to the command
  • -fh β€” you may provide new() with a previously-opened filehandle. For example, to read from STDIN:
$seqIO = Bio::AlignIO->new(-fh => \*STDIN);
Heads up, bestie: you must pass filehandles as references to globs. No exceptions, no shortcuts. πŸ™ˆ

If neither a filehandle nor a filename is specified, then the module will read from the @ARGV array or STDIN, using the familiar <> semantics. Main character energy: if you don't tell her where to go, she'll figure it out. πŸ’…

  • -format β€” specify the format of the file. Supported formats include:
bl2seq      Bl2seq Blast output
clustalw    clustalw (.aln) format
emboss      EMBOSS water and needle format
fasta       FASTA format
maf         Multiple Alignment Format
mase        mase (seaview) format
mega        MEGA format
meme        MEME format
msf         msf (GCG) format
nexus       Swofford et al NEXUS format
pfam        Pfam sequence alignment format
phylip      Felsenstein PHYLIP format
prodom      prodom (protein domain) format
psi         PSI-BLAST format
selex       selex (hmmer) format
stockholm   stockholm format

Currently only those formats which were implemented in Bio::SimpleAlign have been incorporated into Bio::AlignIO. Specifically, "mase", "stockholm" and "prodom" have only been implemented for input. See the specific module (e.g. Bio::AlignIO::prodom) for notes on supported versions. πŸ‘€

If no format is specified and a filename is given, then the module will attempt to deduce it from the filename suffix. If this is unsuccessful, "fasta" format is assumed. She's got a default and she's sticking to it.

The format name is case insensitive β€” "FASTA", "Fasta" and "fasta" are all treated equivalently. Slay, no gatekeeping on capitalization. ✨

🌸 Bio::AlignIO->newFh()

$fh = Bio::AlignIO->newFh(-fh   => \*FILEHANDLE, -format=>$format);
# read from STDIN or use @ARGV:
$fh = Bio::AlignIO->newFh(-format => $format);

This constructor behaves like new, but returns a tied filehandle rather than a Bio::AlignIO object. You can read sequences from this object using the familiar <> operator, and write to it using print. The usual array and $_ semantics work. For example, you can read all sequence objects into an array like this:

@sequences = <$fh>;
Other operations, such as read(), sysread(), write(), close(), and printf() are not supported. Don't ask her to do those, she will simply not. πŸ’€
  • -flush β€” by default, all files (or filehandles) opened for writing alignments will be flushed after each write_aln(), 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:
my $clustal = Bio::AlignIO->new( -file   => "<prot.aln",
                                 -format => "clustalw" );
my $msf = Bio::AlignIO->new(-file   => ">prot.msf",
                            -format => "msf",
                            -flush  => 0 ); # go as fast as we can!
while($seq = $clustal->next_aln) { $msf->write_aln($seq) }

Look at that # go as fast as we can! comment. She's speed. 🏎️✨


πŸ‘‘ OBJECT METHODS πŸ‘‘

See below for more detailed summaries. The main methods are:

  • $alignment = $AlignIO->next_aln() β€” fetch an alignment from a formatted file. Get in, get your alignment, get out. πŸ¦‹
  • $AlignIO->write_aln($aln) β€” write the specified alignment to a file.. (yes, two periods, we keep it exactly as it is, no notes πŸ’…)
  • TIEHANDLE(), READLINE(), PRINT() β€” these provide the tie interface. See perltie for more details.

πŸ’Œ FEEDBACK πŸ’Œ

πŸ“¬ 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. Your participation is much appreciated. Fr fr, they want to hear from you. 🫢

bioperl-l@bioperl.org                  - General discussion
http://bioperl.org/wiki/Mailing_lists  - About the mailing lists

πŸ†˜ Support

Please direct usage questions or support issues to the mailing list:

bioperl-l@bioperl.org

rather than to the module maintainer directly. Many experienced and reponsive 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. The more context you give, the faster the glow-up on that bug fix. ✨

πŸ› 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:

https://github.com/bioperl/bioperl-live/issues

🌟 AUTHOR - Peter Schattner 🌟

Email: schattner@alum.mit.edu


πŸ’ CONTRIBUTORS πŸ’

Jason Stajich, jason@bioperl.org


πŸ¦‹ APPENDIX πŸ¦‹

okay bestie, this is the deep lore section. every single object method gets its own little spotlight here. the internal ones (the ones with a _ in front) are like, the backstage crew β€” you're not really supposed to talk to them directly, but they're slaying back there keeping everything running πŸ’…


✨ new ✨

  • Title β€” new
  • Usage β€”
$stream = Bio::AlignIO->new(-file => $filename,
                            -format => 'Format')
  • Function β€” hands you back a brand new seqstream, fresh out of the box πŸŽ€
  • Returns β€” a Bio::AlignIO::Handler all set up with the right format, like it already knows the vibe
  • Args β€”
    • -file => $filename
    • -format => format
    • -fh => filehandle to attach to
    • -displayname_flat => 1 [optional] β€” use this if you want to force the displayname to not show start/end information. no start/end, just the name, clean and minimal, it's giving minimalism ✨

πŸ’– newFh πŸ’–

  • Title β€” newFh
  • Usage β€”
$fh = Bio::AlignIO->newFh(-file=>$filename,-format=>'Format')
  • Function β€” does a new() and then an fh() right after, two-for-one combo deal 🫢
  • Example β€”
$fh = Bio::AlignIO->newFh(-file=>$filename,-format=>'Format')
$sequence = <$fh>;   # read a sequence object
print $fh $sequence; # write a sequence object
  • Returns β€” a filehandle tied to the Bio::AlignIO::Fh class
  • Args β€” (nothing, bestie, it's empty)

🌸 fh 🌸

  • Title β€” fh
  • Usage β€” $obj->fh
  • Function β€” (the original leaves this one blank, so like... same energy, no notes πŸ™ˆ)
  • Example β€”
$fh = $obj->fh;      # make a tied filehandle
$sequence = <$fh>;   # read a sequence object
print $fh $sequence; # write a sequence object
  • Returns β€” a filehandle tied to the Bio::AlignIO::Fh class
  • Args β€” (also empty, it's a mystery on purpose iykyk)

πŸŽ€ format πŸŽ€

  • Title β€” format
  • Usage β€” $format = $stream->format()
  • Function β€” gets you the alignment format
  • Returns β€” the alignment format
  • Args β€” none

🧚 _load_format_module 🧚

  • Title β€” _load_format_module
  • Usage β€” *INTERNAL AlignIO stuff*
  • Function β€” loads up (like use) a module at run time on demand. lazy loading but make it fashion πŸ’…
  • Example β€” (blank)
  • Returns β€” (blank)
  • Args β€” (blank)

⭐ next_aln ⭐

  • Title β€” next_aln
  • Usage β€” $aln = stream->next_aln
  • Function β€” reads the next $aln object off the stream, one at a time, no greediness
  • Returns β€” a Bio::Align::AlignI compliant object
  • Args β€” (nope, nothing)

πŸ”₯ write_aln πŸ”₯

  • Title β€” write_aln
  • Usage β€” $stream->write_aln($aln)
  • Function β€” writes that $aln object straight into the stream
  • Returns β€” 1 for success and 0 for error (binary queen πŸ‘‘)
  • Args β€” Bio::Seq object

🌈 _guess_format 🌈

  • Title β€” _guess_format
  • Usage β€” $obj->_guess_format($filename)
  • Function β€” (blank in the original, she's mysterious)
  • Example β€” (blank)
  • Returns β€” guessed format of filename (lower case)
  • Args β€” (blank)

πŸ’œ force_displayname_flat πŸ’œ

  • Title β€” force_displayname_flat
  • Usage β€” $obj->force_displayname_flat($newval)
  • Function β€” (blank)
  • Example β€” (blank)
  • Returns β€” value of force_displayname_flat (a scalar)
  • Args β€” on set, new value (a scalar or undef, optional)

πŸ“ alphabet πŸ“

  • Title β€” alphabet
  • Usage β€” $obj->alphabet($newval)
  • Function β€” get/set the alphabet, for the purpose of passing it to Bio::LocatableSeq creation
  • Example β€” $obj->alphabet('dna');
  • Returns β€” value of alphabet (a scalar)
  • Args β€” on set, new value (a scalar or undef, optional)

and that's the whole page bestie!! πŸ˜­πŸ’– you made it all the way through, I'm so proud. this one's from the perl v5.32.1 era, dated 2021-08-15, and it lives at Bio::AlignIO(3pm). go forth and align your sequences, you absolute icon πŸ§¬βœ¨πŸ¦‹

πŸ“¦ where this page comes from