Uff, there is an elegant mistake. In the data;
mRNA join(68351..68408,76646..77296) /gene="DEFB125" /product="defensin, beta 125" /note="Derived by automated computational analysi +s using gene prediction method: BestRefseq." /transcript_id="NM_153325.2" /db_xref="GI:76563935" /db_xref="GeneID:245938" /db_xref="HGNC:18105" CDS join(68351..68408,76646..77058) /gene="DEFB125" /note="Derived by automated computational analysi +s using gene prediction method: BestRefseq." /codon_start=1 /product="defensin, beta 125 preproprotein prepro +protein" /protein_id="NP_697020.2" /db_xref="GI:76563936" /db_xref="CCDS:CCDS12989.2" /db_xref="GeneID:245938" /db_xref="HGNC:18105" gene 123252..126392 /gene="DEFB126" /note="Derived by automated computational analysi +s using gene prediction method: BestRefseq." /db_xref="GeneID:81623" /db_xref="HGNC:15900" mRNA join(123252..123327,126056..126392) /gene="DEFB126" /product="defensin, beta 126" /note="Derived by automated computational analysi +s using gene prediction method: BestRefseq." /transcript_id="NM_030931.2" /db_xref="GI:30061484" /db_xref="GeneID:81623" /db_xref="HGNC:15900" CDS join(123270..123327,126056..126333) /gene="DEFB126" /note="Derived by automated computational analysi +s using gene prediction method: BestRefseq." /codon_start=1 /product="defensin, beta 126 preproprotein prepro +protein" /protein_id="NP_112193.1" /db_xref="GI:13624333" /db_xref="CCDS:CCDS12990.1" /db_xref="GeneID:81623" /db_xref="HGNC:15900"
In the code above, it does not care whether db_xref="GI comes from mRNA or CDS. But I need to get the GI value for CDS - not mRNA! I thought the following (a slight modification for the matching pattern of CDS=>GI) would fix this problem but it did not. Any suggestion is welcome.
#!/usr/bin/perl use strict; use warnings; my $data = '/DATA/GenBankFile.gb'; # GenBank file is located at C:\DAT +A open INFILE, '<', $data or die "Please insert a new coin!\n"; my ( $cds, $gi, $version ); # Declaration of variables while ( <INFILE> ) { last if m!//$!; # Mark the end-of-file if ( /^VERSION.*\w:(\d+)/ ) { # Extract GI of the entire file $version = $1; } elsif ( /^\s*CDS\(s+\S+\n+\)*\Sdb_xref="GI:(\d+)/ ) { # Extract th +e protein gi $gi = $1; } elsif ( /^\s*CDS\s*(\S+)/ ) { # Extract the annotation $cds = $1; } if ( defined $cds && defined $gi && defined $version ) { # Print o +nly when all variables are defined print "$gi\t$version\t$cds\n"; $gi = $cds = undef; # Get ready for the next loop } } close INFILE;

In reply to Re: Read, match string and print by sophix
in thread Read, match string and print by sophix

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.