Hi Perlmonks,

I am interested in extracting the name of genes from a NCBI Genbank file using accession number. Say, the accession number is NC_025572. When the accession number is used as a query in Nucleotide database of NCBI (https://www.ncbi.nlm.nih.gov/), it opens up a Genbank file with the title "Petrolisthes haswelli complete mitochondrial genome, isolate Mar55". In this file, the word CDS is repeated several times with a link and followed by information like <1..1534 /gene="COX1" or 1605..2289 /gene="COX2" or 2423..2773 /gene="ND3" etc. I have come across some perl codes from google search to extract the name from Genbank file. I have given the script below. It gives only the main title i.e. "Petrolisthes haswelli complete mitochondrial genome, isolate Mar55" and not the individual gene name like COX1 or COX2 or ND3. The digits prior to each gene name indicate position of sequence like 1..1534 or 1605..2289 or 2423..2773, respectively. I seek suggestions from perlmonks how to extract the gene name and its corresponding sequence for each gene. The output may look like:

>NC_025572 Gene COX1 ACGAAACGATGATTTTTTTCAACTAACCATAAGGATATTGGAACTTTATACTTTATTTTTGGAGCTTGAT CGGGTATAGTAGGCACTACACTCAGATTAATTATTCGAACAGAACTCGGTCAGCCAGGTAGATTAATTGG AGATGATCAGATTTATAATGTTGTTGTTACCGCCCACGCTTTCGTTATAATTTTTTTTATAGTTATACCA ATCATAATTGGAGGATTTGGCAATTGACTAGTTCCTTTAATACTAGGAGCCCCTGATATAGCCTTTCCTC GAATGAATAACATAAGATTTTGACTCCTACCTCCCTCGCTCACCCTACTTCTAATAAGAGGGATAGTTGA AAGAGGAGTTGGTACTGGATGAACTGTCTACCCACCTCTATCAGCAGGTATTGCCCACGCAGGAGCATCA GTTGATATAGGAATCTTTTCTCTCCATCTTGCAGGTGTTTCTTCTATTTTAGGAGCAGTTAACTTTATAA CTACTGTTATTAATATACGACCCTCAGGAATGACTATAGACCGTATGCCATTATTTGTTTGGGCCGTATT TATTACAGCTATTTTACTTTTATTATCTTTACCTGTTTTAGCAGGAGCCATCACAATACTTTTAACAGAT CGTAATTTAAATACTTCCTTTTTTGACCCTGCTGGAGGAGGAGACCCTATTCTTTATCAACATCTTTTTT GATTTTTTGGTCACCCCGAGGTTTATATTCTTATTCTTCCCGCATTTGGTATAATTTCACACATCGTAAG TCAAGAATCAGGAAAAAAAGAGTCTTTTGGAACATTAGGTATGATTTACGCAATATTGGCTATTGGTATC TTAGGTTTTATCGTTTGAGCACACCACATATTCACCGTTGGTATAGACGTTGATACACGAGCTTATTTTA CATCAGCCACAATAATTATTGCCATCCCCACTGGAATTAAAATTTTCAGATGACTAGGAACGCTTCAAGG AAACCAAATGAATTACAGACCTTCTATAGTCTGAGCTCTAGGTTTTATTTTTCTCTTTACAGTTGGAGGC TTGACTGGTGTTATTTTAGCTAACTCTTCTATTGATACCGTACTACATGACACTTATTATGTAGTAGCTC ACTTTCATTATGTTCTTTCAATAGGAGCTGTCTTCGGAATTTTTGCTGGTATTGCCCATTGATTTCCTCT ATTTACTGGTGTTTCTACTAATCCTAAATGACTAAAAATCCATTTTTCAGTAATATTCCTAGGGGTAAAC TTAACTTTCTTTCCTCAACACTTCCTTGGATTAAATGGAATACCTCGACGTTATTCTGATTATCCTGACG CTTATACCCCATGAAACGTTTTATCTTCCGTTGGATCTTTAGTTTCTTTATGCGCAGTTATTGGTTTCAT CTTTATTGTATGAGAAGCTCTAATTTCTTCACGACCTGTCTTATTTACCCTTTCTCAACCTACATCGATT GAATGAAAACATCCTTATCCGCCCGCTGATCACAGATATATAGAAATTCCTATTCTTTCTAATT >NC_025572 Gene COX2 ATGGCAACATGAGGTTCACTTGGTTTTCAAGATAGAGCATCTCCTTTAATGGAGCACCTTATTTACTTCC ACGATCACGCGATAATTGTCCTTACCTTGATTACAGCCTTCGTGGGCTATATAATAATTTCCCTTTTACC AAACACTTTTACAAATCGATTCCTTTTAGAAAATCAAAAGATTGAAATCATTTGAACTATTATCCCAGCT TTCATTTTAGTTTTTATTGCTCTCCCCTCATTACGGCTTCTTTACCTTCTTGATGAAGTCAACAATCCAA GAATTACTTTAAAAACCGTTGGCCATCAATGGTACTGGTCTTATGAATACTCCGATTTTCATCAAATTGA ATTTGACTCTTATATAATCCAACCAAGAGATTCAGTAGACTCAACATTCCGTCTCATTGACGTTGACAAT CGAGCAGTTTTACCAATAAATTCTCAAATTCGTGTACTAATTAGAGCCGCTGATGTAATTCATTCTTGAA CCGTACCTGCTCTAGGAGTTAAAGCTGATGCTATCCCAGGCCGATTAAATCAAGTAAGATTCATAATTAA CCGCCCAGGTTTATTTTTCGGTCAATGTTCTGAAATTTGCGGAGCTAATCACAGGTTTATACCTATTGTT ATCGAAAGTGTTTCACTTGATTGTTTTCTAAAATGAGTGTCATCACAAGAAGAAT

Here goes the code:

#!/usr/bin/perl use warnings; use strict; use Bio::DB::GenBank; use Bio::SeqIO; use Text::Wrap; my $gb= new Bio::DB::GenBank; my $acc="NC_025572"; my $seq1 = $gb->get_Seq_by_acc($acc); my $desc=$seq1->desc(); print "\n $desc\n"; exit;

I have got the following output from the script. It does not show name of individual gene.

Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\x>cd d* C:\Users\x\Desktop>k.pl Petrolisthes haswelli complete mitochondrial genome, isolate Mar55. C:\Users\x\Desktop>

I welcome suggestions from perlmonks to sort out this problem.


In reply to How can one extract a name using perl? by supriyoch_2008

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.