Bforde has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question on loops
by tobyink (Canon) on Dec 12, 2011 at 14:09 UTC | |
by Bforde (Initiate) on Dec 12, 2011 at 15:04 UTC | |
by tobyink (Canon) on Dec 12, 2011 at 17:48 UTC | |
|
Re: Question on loops
by TJPride (Pilgrim) on Dec 12, 2011 at 15:42 UTC | |
by Bforde (Initiate) on Dec 12, 2011 at 16:42 UTC | |
|
Re: Question on loops
by umasuresh (Hermit) on Dec 12, 2011 at 15:37 UTC |