Bio::PrimarySeq(3pm)

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

πŸ’– Bio::PrimarySeq πŸ’–

okay bestie, welcome to Bio::PrimarySeq(3pm) β€” the Bioperl lightweight sequence object, and honestly? she's iconic. lowkey the moment you start doing bioinformatics in Perl you're gonna be hanging out with her. let's go 🧚


✨ NAME ✨

Bio::PrimarySeq β€” Bioperl lightweight sequence object. that's it, that's the vibe. πŸ¦‹


🌸 SYNOPSIS 🌸

okay so here's the whole thing in action, no cap:

# Bio::SeqIO for file reading, Bio::DB::GenBank for
# database reading

use Bio::Seq;
use Bio::SeqIO;
use Bio::DB::GenBank;

# make from memory

$seqobj = Bio::PrimarySeq->new (
    -seq              => 'ATGGGGTGGGCGGTGGGTGGTTTG',
    -id               => 'GeneFragment-12',
    -accession_number => 'X78121',
    -alphabet         => 'dna',
    -is_circular      => 1,
);
print "Sequence ", $seqobj->id(), " with accession ",
  $seqobj->accession_number, "\n";

# read from file

$inputstream = Bio::SeqIO->new(
    -file   => "myseq.fa",
    -format => 'Fasta',
);
$seqobj = $inputstream->next_seq();
print "Sequence ", $seqobj->id(), " and desc ", $seqobj->desc, "\n";

# to get out parts of the sequence.

print "Sequence ", $seqobj->id(), " with accession ",
  $seqobj->accession_number, " and desc ", $seqobj->desc, "\n";

$string  = $seqobj->seq();
$string2 = $seqobj->subseq(1,40);

like, look at her go. making sequences from scratch, reading them out of files, grabbing little slices of them β€” all of it. πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

so PrimarySeq is a lightweight sequence object. she stores the sequence, its name, a computer-useful unique name, and other fundamental attributes. and that's it, bestie β€” she does not contain sequence features or other information. if you want a sequence that comes with sequence features, you want the Seq object, which uses this object. 🫢

ngl, even though new users will use Bio::PrimarySeq a lot, in general you'll be using it from the Bio::Seq object. for more info on Bio::Seq go peek at Bio::Seq. and for interest's sake, you might like to know that Bio::Seq has-a Bio::PrimarySeq and forwards most of the function calls to do with sequence to it β€” and the reason for that has-a relationship is genuinely so real: it lets us get out of an otherwise nasty cyclical reference in Perl which would leak memory. πŸ’€ slay.

sequence objects are defined by the Bio::PrimarySeqI interface, and this object is a pure Perl implementation of that interface. if that's gibberish to you, don't worry β€” the take home message is that this object is the bioperl default sequence object, but other people can use their own objects as sequences if they so wish. and if you're interested in wrapping your own objects as compliant Bioperl sequence objects? then you should read the Bio::PrimarySeqI documentation. iykyk. 🌈

also the documentation of this object is a merge of the Bio::PrimarySeq and Bio::PrimarySeqI documentation, which is the whole reason all the methods you can call on sequence objects live right here. one-stop shop, periodt. πŸ‘‘


πŸ’Œ 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. πŸ₯Ή

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. there are so many experienced and responsive experts who will be able to look at the problem and quickly address it. and if at all possible, please include a thorough description of the problem with code and data examples. the more deets the better, bestie. πŸ™ˆ

πŸ› Reporting Bugs

report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. bug reports can be submitted via the web:

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

πŸ‘‘ AUTHOR - Ewan Birney πŸ‘‘

Email birney@ebi.ac.uk


(more coming, bestie β€” don't go anywhere πŸ’–)

πŸ¦‹ APPENDIX πŸ¦‹

okay bestie, this is the deep dive β€” the rest of the docs spill all the tea on every object method. heads up: internal methods usually have a lil _ in front of them, so if you see that underscore you know it's ✨private business✨


πŸ’– new πŸ’–

  • Title: new
  • Usage:
$seqobj = Bio::PrimarySeq->new( -seq => 'ATGGGGGTGGTGGTACCCT',
                                -id  => 'human_id',
                                -accession_number => 'AL000012',
                                );
  • Function: hands you back a brand new primary seq object built from the basics β€” a string for the sequence, and strings for the id and the accession_number.

ngl there's a lil plot twist here: you can pass an empty sequence string, but in that case you MUST tell it what kind of sequence you want by setting the -alphabet parameter. peek at alphabet() for the possible values, iykyk.

  • Returns: a new Bio::PrimarySeq object πŸŽ€
  • Args:
    • -seq => sequence string
    • -ref_to_seq => ... or reference to a sequence string
    • -display_id => display id of the sequence (locus name)
    • -accession_number => accession number
    • -primary_id => primary id (Genbank id)
    • -version => version number
    • -namespace => the namespace for the accession
    • -authority => the authority for the namespace
    • -description => description text
    • -desc => alias for description
    • -alphabet => skip alphabet guess and set it to dna, rna or protein
    • -id => alias for display id
    • -is_circular => boolean to indicate that sequence is circular
    • -direct => boolean to directly set sequences. The next time -seq, seq() or -ref_to_seq is use, the sequence will not be validated. Be careful with this...
    • -nowarnonempty => boolean to avoid warning when sequence is empty

🧬 seq 🧬

  • Title: seq
  • Usage: $string = $seqobj->seq();
  • Function: get or set the sequence as a string of letters. whether the letters come back upper or lowercase is literally up to whoever implemented it. the suggested vibe is upper case for proteins and lower case for DNA sequence (IUPAC standard), but bestie do not rely on that. if the sequence has invalid characters in it, an error gets thrown: see validate_seq().
  • Returns: a scalar
  • Args:
    • Optional new sequence value (a string) to set
    • Optional alphabet (it is guessed by default)

πŸ” validate_seq πŸ”

  • Title: validate_seq
  • Usage:
if(! $seqobj->validate_seq($seq_str) ) {
     print "sequence $seq_str is not valid for an object of
     alphabet ",$seqobj->alphabet, "\n";
}
  • Function: vibe-checks the sequence you hand it, i.e. tests that it contains only valid characters. the allowed characters are all letters (A-Z) plus '-', '.', '*', '?', '=' and '~'. spaces are not valid. heads up tho: this implementation does not take alphabet() into account, and empty sequences count as valid (iconic of them honestly).
  • Returns: 1 if the supplied sequence string is valid, 0 otherwise.
  • Args:
    • Sequence string to be validated
    • Boolean to optionally throw an error if the sequence is invalid

βœ‚οΈ subseq βœ‚οΈ

  • Title: subseq
  • Usage:
$substring = $seqobj->subseq(10,40);
$substring = $seqobj->subseq(10,40,'nogap');
$substring = $seqobj->subseq(-start=>10, -end=>40, -replace_with=>'tga');
$substring = $seqobj->subseq($location_obj);
$substring = $seqobj->subseq($location_obj, -nogap => 1);
  • Function: gives you the subseq from start to end. the first sequence character has coordinate 1 and it's inclusive, so 1-2 are literally the first two characters of the sequence. the start coordinate you pass has to be larger than the end, even if the sequence is circular.
  • Returns: a string
  • Args:
    • integer for start position
    • integer for end position

OR

  • Bio::LocationI location for subseq (strand honored)

Specify -NOGAP=>1 to return subseq with gap characters removed Specify -REPLACE_WITH=>$new_subseq to replace the subseq returned with $new_subseq in the sequence object


πŸ“ length πŸ“

  • Title: length
  • Usage: $len = $seqobj->length();
  • Function: get the stored length of the sequence in number of symbols (bases or amino acids). in some circumstances you can also set this attribute, and the ways are kinda cute actually:
    1. for empty sequences, you can set the length to anything you want:
my $seqobj = Bio::PrimarySeq->new( -length => 123 );
my $len = $seqobj->len; # 123
  1. to save memory when using very long sequences, you can set the length of the sequence to the length of the sequence (and nothing else):
my $seqobj = Bio::PrimarySeq->new( -seq => 'ACGT...' ); # 1 Mbp sequence
# process $seqobj... then after you're done with it
$seqobj->length($seqobj->length);
$seqobj->seq(undef); # free memory!
my $len = $seqobj->len; # 1 Mbp
⚠️ plot twist: if you set seq() to a value other than undef at any time, the length attribute gets reset. no cap.
  • Returns: integer representing the length of the sequence.
  • Args: Optionally, the value on set

🏷️ display_id 🏷️

  • Title: display_id or display_name
  • Usage: $id_string = $seqobj->display_id();
  • Function: get or set the display id, aka the common name of the sequence object.

the semantics here are that this is the most likely string to be used as an identifier of the sequence, and it's likely to have that "human" readability. the id is equivalent to the ID field of the GenBank/EMBL databanks and the id field of the Swissprot/sptrembl database. in fasta format, the >(\S+) is presumed to be the id, though some people overload the id to embed other information. Bioperl does not use any embedded information in the ID field, and people are encouraged to use other mechanisms (the accession field for example, or extending the sequence object) to solve this.

with the new Bio::DescribeableI interface, display_name aliases to this method. slay πŸ’…

  • Returns: A string for the display ID
  • Args: Optional string for the display ID to set

πŸ”‘ accession_number πŸ”‘

  • Title: accession_number or object_id
  • Usage: $unique_key = $seqobj->accession_number;
  • Function: returns the unique biological id for a sequence, commonly called the accession_number. for sequences from established databases, the implementors should try to use the correct accession number. notice that primary_id() provides the unique id for the implementation, allowing multiple objects to have the same accession number in a particular implementation.

for sequences with no accession number, this method should return "unknown".

[Note this method name is likely to change in 1.3]

with the new Bio::IdentifiableI interface, this is aliased to object_id

  • Returns: A string
  • Args: A string (optional) for setting

πŸ†” primary_id πŸ†”

  • Title: primary_id
  • Usage: $unique_key = $seqobj->primary_id;
  • Function: returns the unique id for this object in this implementation. this lets implementations manage their own object ids in a way the implementation can control, and clients can expect one id to map to one object.

for sequences with no natural primary id, this method should return a stringified memory location. iconic.

  • Returns: A string
  • Args: A string (optional, for setting)

πŸ”€ alphabet πŸ”€

  • Title: alphabet
  • Usage: if( $seqobj->alphabet eq 'dna' ) { # Do something }
  • Function: get/set the alphabet of sequence, one of 'dna', 'rna' or 'protein'. this is case sensitive bestie, don't come in here with 'DNA'.

this is not called <type> because that would cause upgrade problems from the 0.5 and earlier Seq objects. ancient lore πŸ—Ώ

  • Returns: a string either 'dna','rna','protein'. NB - the object must make a call of the type - if there is no alphabet specified it has to guess.
  • Args: optional string to set : 'dna' | 'rna' | 'protein'

πŸ“ desc πŸ“

  • Title: desc or description
  • Usage: $seqobj->desc($newval);
  • Function: get/set description of the sequence.

'description' is an alias for this for compliance with the Bio::DescribeableI interface.

  • Returns: value of desc (a string)
  • Args: newvalue (a string or undef, optional)

🧚 can_call_new 🧚

  • Title: can_call_new
  • Usage:
  • Function:
  • Example :
  • Returns: true
  • Args:

πŸŽ€ id πŸŽ€

  • Title: id
  • Usage: $id = $seqobj->id();
  • Function: This is mapped on display_id
  • Example :
  • Returns :
  • Args :

🌈 is_circular 🌈

  • Title: is_circular
  • Usage: if( $seqobj->is_circular) { # Do something }
  • Function: Returns true if the molecule is circular
  • Returns: Boolean value
  • Args: none

πŸ†” Methods for Bio::IdentifiableI compliance

okay so these are the ones that make your object play nice with Bio::IdentifiableI πŸ’– they're all get-or-set, so you can read the value or shove a new one in, bestie.

object_id

  • Title: object_id
  • Usage: $string = $seqobj->object_id();
  • Function: grab or set a string that is the stable primary identifier for this thing inside this namespace. For DNA sequences that's literally its accession_number, and same energy for protein sequences. 🌟
  • Returns: A scalar
  • Args: Optional object ID to set.
heads up: this is aliased to accession_number(), iykyk πŸ’…

version

  • Title: version
  • Usage: $version = $seqobj->version();
  • Function: get or set a number that tells apart different versions of the same object. Bigger numbers = later and more relevant, periodt. but like, one single object described by the same identifier should still represent the same concept, okay? πŸ¦‹
  • Returns: A number
  • Args: Optional version to set.

authority

  • Title: authority
  • Usage: $authority = $seqobj->authority();
  • Function: get or set a string for the organisation that granted the namespace, written as the DNS name of the org (eg, wormbase.org). πŸ‘‘
  • Returns: A scalar
  • Args: Optional authority to set.

namespace

  • Title: namespace
  • Usage: $string = $seqobj->namespace();
  • Function: get or set a string for the name space this identifier is valid in β€” often the database name, or the name that describes the collection. 🌈
  • Returns: A scalar
  • Args: Optional namespace to set.

πŸŽ€ Methods for Bio::DescribableI compliance

this lil bundle is just display_name and description, that's it, that's the whole vibe ✨

display_name

  • Title: display_name
  • Usage: $string = $seqobj->display_name();
  • Function: get or set the string that should actually be shown to the user. ideally it has no spaces (though a cautious user of this interface would not assume that, ngl) and it should be under thirty characters (again, double-checking this is a good idea, fr fr).
  • Returns: A string for the display name
  • Args: Optional string for the display name to set.
also aliased to display_id() 🫢

description

  • Title: description
  • Usage: $string = $seqobj->description();
  • Function: get or set a text string that's suitable for showing a human a description. this one is likely to have spaces, but it should not have any newlines or formatting β€” just plain text, okay? and it should not be greater than 255 characters, and clients are totally justified in truncating strings at 255 characters for display purposes. πŸ’€
  • Returns: A string for the description
  • Args: Optional string for the description to set.
aliased to desc() too πŸŽ€

🧬 Methods Inherited from Bio::PrimarySeqI

so these are all available on Bio::PrimarySeq, bestie, even though they're actually implemented over on Bio::PrimarySeqI. the way that inheritance works 😌

revcom

  • Title: revcom
  • Usage: $rev = $seqobj->revcom();
  • Function: makes you a brand new Bio::SeqI implementing object that is the reversed complement of the sequence. for protein sequences this throws an exception of "Sequence is a protein. Cannot revcom" β€” like, it simply will not, sorry not sorry 😭

the id is the same id as the original sequence, and the accession number is also identical. if someone wants to track that this sequence has been reversed, they need to define their own extensions. 🌸

to do an inplace edit of an object you can go:

$seqobj = $seqobj->revcom();

which of course causes Perl to handle the garbage collection of the old object, but roughly speaking it is as efficient as an inplace edit. slay ✨

  • Returns: A new (fresh) Bio::SeqI object
  • Args: none

trunc

  • Title: trunc
  • Usage: $subseq = $myseq->trunc(10,100);
  • Function: gives you a truncation of a sequence. simple as that πŸ’…
  • Returns: A fresh Bio::SeqI implementing object.
  • Args: Numbers for the start and end positions

πŸ”’ Internal methods

these ones are internal to PrimarySeq, so like... they're the backstage crew 🧚

_guess_alphabet

  • Title: _guess_alphabet
  • Usage: (nothing here, it's just vibes)
  • Function: automatically guess and set the type of sequence: dna, rna, protein, or '' if the sequence was empty. this method first removes dots (.), dashes (-) and question marks (?) before guessing the alphabet using the IUPAC conventions for ambiguous residues. and because the DNA and RNA characters are also valid characters for proteins, there is no foolproof way of determining the right alphabet. this is our best guess only! πŸ™ˆ
  • Returns: string 'dna', 'rna', 'protein' or ''.
  • Args: none

and that's a wrap on the whole page, bestie πŸŽ‰ this one came from the perl v5.32.1 docs, dated 2021-08-15, and the page itself is Bio::PrimarySeq(3pm) β€” go forth and sequence things, you absolute icon πŸ‘‘πŸ’–

πŸ“¦ where this page comes from