Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Searching and Coutning using 2 files with multiple columns

by bichonfrise74 (Vicar)
on Sep 17, 2009 at 00:02 UTC ( [id://795737]=note: print w/replies, xml ) Need Help??


in reply to Searching and Coutning using 2 files with multiple columns

This might help you get started.
#!/usr/bin/perl use strict; my $file_1 = <<END; chr1 3204562 3661779 chr1 4334223 4350673 chr1 4481008 4486694 chr1 4764014 4775968 chr1 4797773 4836816 chr1 4847574 4887987 chr1 4847574 4887987 chr1 4848208 4887987 chr1 4900049 5009660 chr1 5073053 5152630 END my @boundary_records; open( my $file, '<', \$file_1 ) or die( "Error could not open $file_1" ); while( <$file> ) { push( @boundary_records, [ split( /\s+/ ) ] ); } close( $file ); my $count = 0; while( <DATA> ) { chomp; my @test_records = split( /\s+/ ); for my $i (@boundary_records) { if ( $test_records[1] eq $i->[0] and $test_records[2] > $i->[1] and $test_records[3] < $i->[2] ) { $count++; } } print "$_ = $count\n"; $count = 0; } __DATA__ Xkr4 chr1 3204562 3661779 - 3 457.217 Rp1 chr1 4334223 4350673 - 4 16.45 Sox17 chr1 4481008 4486694 - 5 5.686 Mrpl15 chr1 4764014 4775968 - 5 11.954 Lypla1 chr1 4797773 4836816 + 9 39.043 Tcea1 chr1 4847574 4887987 + 10 40.413 Tcea1 chr1 4848208 4887987 + 10 39.779 Rgs20 chr1 4900049 5009660 - 5 109.611

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://795737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-19 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found