Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bio::DB::Fasta makeid sub

    Hi there,

    I am having trouble getting the makeid option work for my fasta db.

    Here is the header of my the first sequence in my file.

    >gi|149538895|ref|XP_001512649.1| PREDICTED: similar to Olfactory receptor 18 (Olfactory receptor 145-1) (Olfactory receptor TPCR34) [Ornithorhynchus anatinus]

    What I want is to make the ids the gi number.

    Code:
    #!/usr/bin/perl
    
    use Bio::SeqIO;
    use Bio::Seq;
    use Bio::DB::Fasta;
    use Bio::PrimarySeq;
    use Bio::LocationI;
    use Bio::Tools::SeqWords;
    
    sub make_my_id();
    
    #Directory of fasta files
    my $file = "/home/[user]/Desktop/Olfactory/Ornithorhynchus_anatinus_olfactory/ornithorhynchus_anatinus_sample.fasta";
    
    ######################## With Subroutine ##########################
    my $db = Bio::DB::Fasta->new($file,-reindex, -makeid=>\&make_my_id);
     
    my @names = $db->ids;
    foreach (@names) {print $_, "\n";}
    
    #my $seq = $db->seq('149538895'); 
    #print $seq, "\n\n";
    
    ######Subroutines#################
    sub make_my_id {
      my $line = shift;
      # get a different id from the fasta header, e.g.
      $line =~ m/(\|.*?\|)/;
      my $ID = $1;
      $ID = substr($ID, 1, -1);
      #print $ID, "\n";
      return $1;
    }
    Any insight as to whats going wrong would be very appreciated! Thanks!

  • #2
    Options for BioPerl objects need to be passed as key=>value pairs; simply having "-reindex" in your option list will not work. Change this to "-reindex=>1".

    May I also suggest a simplification of your regex. If you know that the only files you will be parsing have NCBI formatted deflines then they will always start with ">gi|<gi_number>|" and gi_number is always an integer.

    Replace:

    Code:
    $line =~ m/(\|.*?\|)/;
    my $ID = $1;
    $ID = substr($ID, 1, -1);
    With:

    Code:
    my ($ID) = $line =~ m/^gi\|(\d+)\|/

    Comment

    Latest Articles

    Collapse

    • seqadmin
      Current Approaches to Protein Sequencing
      by seqadmin


      Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
      04-04-2024, 04:25 PM
    • seqadmin
      Strategies for Sequencing Challenging Samples
      by seqadmin


      Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
      03-22-2024, 06:39 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by seqadmin, 04-11-2024, 12:08 PM
    0 responses
    25 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 10:19 PM
    0 responses
    28 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 09:21 AM
    0 responses
    24 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-04-2024, 09:00 AM
    0 responses
    52 views
    0 likes
    Last Post seqadmin  
    Working...
    X