Hello

I am new to perl so I apologise in advance for the crudeness of my question and of my code.

I am writing a script mainly in BioPerl which will allow me to edit a genbank file. The script reads a tab delimited text file containing two columns which are separated into two list V1 and V2. The script then parses a genbank file (an annotated DNA file) and extracts a third list (V3). Each element in V1 is then to be compared against V3 and where they are equal do something. the problem lies in that the script does not seem to cycle through each element of V1. Instead only the results for the final element of V1 is displayed. I have tried a number of different methods to solve this problem but I always get the same results. Below is a sample of the original code

The input file 'list' has the format

HP17_05860 HP_01111,

HP17_05865 HP_01112

use Bio::SeqIO; open (LIST1, "list"); while (<LIST1>){ ($V1, $V2) = split(/\t/, $_); } close(LIST1); my $seqIO_object = Bio::SeqIO->new(-file=>"infile.gb"); my $seq_object = $seqio_object ->next_seq; for my $feat_object ($seq_object->get_SeqFeatures){ if ($feat_object->primary_tag eq "CDS"){ if ($feat_object->has_tag('locus_tag')){ for my $V3 ($feat_object ->get_tag_values('locus_tag')){ if ($V1 eq $V3){ print "locus_tag: ", $V1, " is unique\n"; } } } } }

Each element in V1 is contained in V3 so with the input above the out put should read

locus_tag: HP17_05860 is unique

locus_tag: HP17_05865 is unique

However the output I get is

locus_tag: HP17_05865 is unique

this problem is probably easily solved with the appropriate use of arrays and loops

regards

Brian


In reply to Question on loops by Bforde

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.