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
      Essential Discoveries and Tools in Epitranscriptomics
      by seqadmin




      The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
      04-22-2024, 07:01 AM
    • 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

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by seqadmin, 04-30-2024, 12:17 PM
    0 responses
    13 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-29-2024, 10:49 AM
    0 responses
    19 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-25-2024, 11:49 AM
    0 responses
    26 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-24-2024, 08:47 AM
    0 responses
    24 views
    0 likes
    Last Post seqadmin  
    Working...
    X