Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: overlapping regions

by Cristoforo (Deacon)
on Apr 25, 2012 at 00:31 UTC ( #966967=note: print w/ replies, xml ) Need Help??


in reply to overlapping regions

I thought that I would post a possible solution (using the module Set::IntSpan). It eliminates making the logic to detect overlap by testing for set intersection between the spans in the cnv file and the spans in the genelist* files. For each line in the genelist file, it checks to see if it intersects with any/all lines in the cnv file.

However, this may not be what you were looking for as far as output/results. :-(

#!/usr/bin/perl use strict; use warnings; use Set::IntSpan; my $cnv = <<EOF; start stop size(in bp) 5389769 98256008 3567 7452344 871875466 64547 EOF my $genelist1 = <<EOF; name start stop BRCA1 41196312 41277500 TP53 7571720 7590863 EOF my $genelist3 = <<EOF; name start stop OMG 29621668 29624380 NR3C1 142657496..142815077 EOF my @cnv; open my $fh, "<", \$cnv; <$fh>; # toss header while (<$fh>) { chomp; my ($start, $stop, $size) = split /\t/; push @cnv, { span => Set::IntSpan->new("$start-$stop"), size => $size, }; } close $fh or die $!; printf "%-10s%10s%10s%10s\n", ('gene name', qw/ size start stop /); for (\$genelist1, \$genelist3) { open $fh, "<", $_; <$fh>; # toss header while (<$fh>) { chomp; my ($name, $start, $stop) = split /\t|(?<=\d)\.\.(?=\d)/; my $span = Set::IntSpan->new("$start-$stop"); for my $href (@cnv) { my $intersect = $span->intersect( $href->{span} ); if ($intersect) { printf "%-10s%10s%10s%10s\n", $name, $href->{size}, $intersect->min, $intersect- +>max; } } } close $fh or die $!; }
And produced this output
gene name size start stop BRCA1 3567 41196312 41277500 BRCA1 64547 41196312 41277500 TP53 3567 7571720 7590863 TP53 64547 7571720 7590863 OMG 3567 29621668 29624380 OMG 64547 29621668 29624380 NR3C1 64547 142657496 142815077

Hoping this is something like you were asking. The same genename overlapped with both spans in the cnv file for all of the genenames except for the last one, NR3C1. It overlapped with the span in the cnv file with size=64547 but not with the span with size=3567

Chris


Comment on Re: overlapping regions
Select or Download Code
Re^2: overlapping regions
by perllearner007 (Acolyte) on Apr 25, 2012 at 13:58 UTC
    Thanks Chris. This also makes a bit of sense. Its great if the same gene overlaps with both spans in the cnv file. Let me try and run this with my gene list which is much larger and see if this works or not. As for my previous code.. I fixed a few things but I think it is something to do with my sub function. I am working on fixing that.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-08-22 05:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (147 votes), past polls