vikuuu has asked for the wisdom of the Perl Monks concerning the following question:

How i can get the last few say 20 nucleotides in a fasta subsequence by using BIOPERL as i was not able to find a module in which i can get the last subsequences in a sequences . the only way i got was to use the end and starting position to get the subseq() ,but i dont know the two positions so i cant use that .So please help.
  • Comment on How Do I Get the Last 20 Nucleotides In A FASTA Subsequence?

Replies are listed 'Best First'.
Re: How Do I Get the Last 20 Nucleotides In A FASTA Subsequence?
by almut (Canon) on Mar 10, 2010 at 13:46 UTC

    I may be missing something... but wouldn't using the Perl built-in substr, i.e. a simple substr($seq, -20) do the job?

    (A negative offset returns that many chars counting from the end of the string.)

Re: How Do I Get the Last 20 Nucleotides In A FASTA Subsequence?
by space_agent (Acolyte) on Mar 10, 2010 at 13:52 UTC

    Actually you don't need a bioperl module for this.
    You can use the builtin substr function instead:

    #!/usr/bin/perl -w use Bio::DB::GenBank; $db_obj = Bio::DB::GenBank->new; $seq_obj = $db_obj->get_Seq_by_acc(EU864037); $sequence = $seq_obj->seq; $pos = length($sequence)-20; #go to position from end $seqend = substr($sequence,$pos,20); print "whole sequence: $sequence\n\n", "Just the end: $seqend \n"; #just for verifying
Re: How Do I Get the Last 20 Nucleotides In A FASTA Subsequence?
by Anonymous Monk on Mar 10, 2010 at 14:37 UTC
    What is a nucleotide? From Bio::Seq
    # gets sequence as a string from sequence object $seqstr = $seqobj->seq(); # actual sequence as a string $seqstr = $seqobj->subseq(10,50); # slice in biological coordina +tes $seqobj->length() # length
    so I guess
    $segstr = $segobj->subseg( $segobj->length - 20, $segobj->length );
      Thanks dude....