Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

having problems to find targets in a array

Status
Not open for further replies.

JohnFKarlson

IS-IT--Management
Feb 19, 2009
2
NO
The problem is that i have a file i get from
a database, that contain the names i need more info about
and then i need to extract the data that contain the info from anotter file..

Well and as the n00bi i am, i cant get the code to work,..
So there fore i ask you pepole about some help,...

##################################################
part of file 1: (the names i need more info about)
##################################################

252831_at
253333_at
261933_at
247138_at
258908_at
263897_at
252900_at
258281_at
266608_at
248819_at
260818_at
246627_s_at
245832_at
257746_at
250407_at
267035_at
263714_at
262825_at
259254_at
266257_at
252652_at
249910_at
261758_at
263845_at
251984_at
245690_at
259149_at
267470_at
256186_at
258047_at
261907_at
258037_at
259568_at
250207_at
251827_at
252123_at

#######################################
end of part of file 1: (the names i need more info about)
#######################################

#######################################
exampel the file2: (data i need to extract)
#######################################
244901_at AtMg00640 -1,1 D -0,3 NC 15,1 P 61,1 P 16,9 P 28,7 P hypothetical protein
244902_at AtMg00650 -0,7 D -0,3 NC 13,9 P 65,8 P 11,1 P 37,3 P NADH dehydrogenase subunit 4L
244903_at AtMg00660 -0,5 NC -0,6 NC 20,2 P 39 P 14 P 23,7 P hypothetical protein
244904_at ATMG00670 0,4 NC -1,5 NC 3,6 A 6,2 A 1,4 A 8,5 A hypothetical protein
244905_at AtMg00680 3,3 NC 0,3 NC 8 A 0,9 A 12,3 A 11,4 A hypothetical protein
244906_at AtMg00690 -1,6 D -0,7 NC 39,3 A 92 P 24,6 A 31,4 P hypothetical protein
244907_at AtMg00710 -0,6 NC -1 NC 5,9 A 0,6 A 2,6 A 0,5 A hypothetical protein
244908_at AtMg00720 -0,9 NC -0,9 NC 1 A 2,4 A 0,3 A 0,6 A hypothetical protein
244909_at ATMG00740 -0,5 NC -0,2 NC 10,9 A 13,6 A 11,8 A 8,8 A hypothetical protein
244910_s_at ATMG00750 -0,3 NC -0,5 NC 10,2 P 9,2 A 8 P 6 A hypothetical protein
244911_at ATMG00820 -2,1 NC -2,1 NC 7,4 P 4,6 A 1,6 A 1 A hypothetical protein
#######################################
end of exampel of the file2: (data i need to extract)
#######################################

Okey so below i have try to write a code to extract parts of the info, but with out anny luck,...

#######################################
#!/usr/bin/perl -w

$targets1 = 'target_genes_at.txt'; #the data i need more info about
open(TAG,$targets1);
@targets1 = <TAG>;
close TAG;
$cal1 = 'solfanelli_data.txt'; #were the info is stored
open(CAL,$cal1);
@cal1 = <CAL>;
close CAL;

$i=1;
$ts= @targets1;


print "there is $ts array valuges in this file";
print "\n";


while ($i<($ts-1))
{
$i=$i+1;
$hell = @targets1[$i];
print $hell; #well it print out my targets,
for my $line (@cal1) {
if($line =~ /^$hell/) { #But it dont do it here
$line =~ /^$hell/;
$loc = $line;
}elsif($line =~ /^255056_at/) {
$line =~ /^255056_at/;
$def = $line;
}elsif($line =~ /\s/) {
$line =~ s/\s*//;
$NoMORE = $line;
}
}

print "*** The found target from the Import of the Target list @hell ***\n";
print "The hitt from the target list shud be here!: $loc Why not?";

}
;
exit;




 
This appears to be your first post. Please repost your question in this thread and use the code tags to keep the formatting of the code and data you post. Just below the box where you post your question is a link: "Process TGML". See that page for use of code tags.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
The data you need is in @field[n]. Didn't have time to follow you code, but run this to see if it will get you started. You extact fields are seperate by ':'.

open(TAG,"Target.txt");
open(CAL,"Extract.txt");

my %target;
while ( <TAG> ) {
next unless /^\d/;
chomp;
$target{$_} = undef;
}
close TAG;

while ( <CAL> ) {
next unless /^\d/;
chomp;
my (@field) = split;
my $key = shift @field;
my $info = join(':',@field);
$target{$key} = $info;
}
foreach ( sort keys %target ) {
print "$_ : $target{$_}\n" if $target{$_};
}
close CAL;
exit;
 
Tanx Ejaggers
But i have alleady get a simular result...

The problem, is it dont show the "targets" im after,
it just putt the data from the extract in a nice alfabetic
list...

Added the data at "if it gonna help
 
OK then don't use the code tags.

Not well tested:

Code:
use strict;
use warnings;
open(my $TAG, "<", "c:/perl_test/Target.txt") or die "$!";
my @targets = <$TAG>;
close $TAG;
chomp(@targets);
@targets = sort @targets;
#print "$_\n" for @targets;
open(my $CAL, "<", "c:/perl_test/Extract.txt") or die "$!";
OUTTER: foreach my $target (@targets) {
   my $len = length($target);
   INNER: while ( <$CAL> ) {
      if ($target eq substr $_,0,$len) {
         print "$target >>> $_";
         next OUTTER;
      }
      else {
         next INNER;
      }
   }
}
close $CAL;
exit;

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
This is a little better going by the exact files you posted:

Code:
use strict;
use warnings;
open(my $TAG, "<", "c:/perl_test/Target.txt") or die "$!";
my @targets = <$TAG>;
close $TAG;
chomp(@targets);
@targets = sort @targets;
#print "$_\n" for @targets;
open(my $CAL, "<", "c:/perl_test/Extract.txt") or die "$!";
<$CAL>,<$CAL>;#skip first two lines
OUTTER: foreach my $target (@targets) {
   my $len = length($target);
   INNER: while ( <$CAL> ) {
      if ($target eq substr $_,0,$len) {
         print "$target >>> $_";
         next OUTTER;
      }
      else {
         next INNER;
      }
   }
}
close $CAL;
exit;

Make sure there are no blank lines in the target file or check for them in the "foreach" loop otherwise you will get a false match in the other file.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top