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
      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
      ...
      Yesterday, 09:55 AM
    • SEQadmin2
      New Genomics Technologies Take Aim at Long-Standing Limits
      by SEQadmin2


      Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

      We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
      ...
      09-28-2026, 10:25 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by SEQadmin2, Today, 10:52 AM
    0 responses
    8 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, Yesterday, 05:39 AM
    0 responses
    15 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-13-2026, 09:56 AM
    0 responses
    15 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-09-2026, 11:14 AM
    0 responses
    27 views
    0 reactions
    Last Post SEQadmin2  
    Working...