Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mindlessbrain
    Junior Member
    • Dec 2010
    • 7

    #1

    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!
  • kmcarr
    Senior Member
    • May 2008
    • 1181

    #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

    • SEQadmin2
      16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
      by SEQadmin2





      NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification,...
      10-30-2026, 06:46 AM
    • SEQadmin2
      Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
      by SEQadmin2



      Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

      Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
      ...
      10-14-2026, 09:55 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by SEQadmin2, Yesterday, 07:59 AM
    0 responses
    13 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 11-05-2026, 09:25 AM
    0 responses
    32 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 11-03-2026, 11:54 AM
    0 responses
    45 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-28-2026, 09:57 AM
    0 responses
    170 views
    0 reactions
    Last Post SEQadmin2  
    Working...