spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Extract the unique intervals from two arrays in perl?


Process the files line by line. If there's no overlap, report the interval that starts earlier and advance its file. In case of an overlap, advance both files.

#!/usr/bin/perl
use warnings;
use strict;

use Data::Dumper;

my @F;
open $F[0], '<', 'file1.txt' or die $!;
open $F[1], '<', 'file2.txt' or die $!;

# Skip headers.
readline $_ for @F;

my @boundaries;
my @results;

sub earlier {
    my ($x, $y) = @_;
    if (! @{ $boundaries[$y] }
        or $boundaries[$x][1] <
$boundaries[$y][0]
    ) {
        push @results, $boundaries[$x];
        $boundaries[$x] = [ split ' ', readline
$F[$x] ];
        return 1
    }
    return 0
}

sub overlap {
    my ($x, $y) = @_;
    if ($boundaries[$x][1] <
$boundaries[$y][1]) {
        do { $boundaries[$x] = [ split ' ',
readline $F[$x] ] }
          until ! @{ $boundaries[$x] }
          or $boundaries[$x][0] >
$boundaries[$y][1];
        $boundaries[$y] = [ split ' ', readline
$F[$y] ];
        return 1
    }
    return 0
}

sub advance_both {
    @boundaries = map [ split ' ', readline $_ ],
@F;
}

# init.
advance_both();
while (grep defined, @{ $boundaries[0] }, @{
$boundaries[1] }) {

    earlier(0, 1)
    or earlier(1, 0)
    or overlap(0, 1)
    or overlap(1, 0)
    or advance_both();
}

print join(' , ', map { join '-', @$_ } @results),
"
";

Categories : Perl

Related to : Extract the unique intervals from two arrays in perl?
Sorting arrays of intervals in perl?
You need to extract first number for every element, and do numerical comparison using <=> operator, my @array = qw(1-5 7-9 10-15 20-58 123-192 234-256); my @sorted = sort { my ($aa,$bb) = map /^([0-9]+)/, $a,$b; $aa <=> $bb; } @array;

Categories : Perl
How to obtain the complement intervals from an array of intervals in perl?
Set::IntSpan use warnings; use strict; use Set::IntSpan; my @ary1 = qw(23-44 85-127 168-209); my $spec = join ',', @ary1; my $set = Set::IntSpan->new($spec); my $list = $set->holes(); print "$list "; __END__ 45-84,128-167

Categories : Arrays
Sample array at even intervals
What you want is a uniform discrete distribution. Because the number of elements is not divisible by the limit, you would want some flexibility in the limit to keep it evenly distributed. To do so, you could just perform the sampling in elements/limit intervals, rounding the result to its nearest integer. If your limit is flexible and you can cover more ground by finding the biggest possible limi

Categories : Javascript
Custom Carousel Intervals?
You can create a custom attribute that denotes how long the slide should be visible for, pull that out for the active item on the slide.bs.carousel or slid.bs.carousel events (whichever you prefer/works best for you), then set it as a timeout to go to the next slide. HTML: <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> <!-- Indicators --> <ol c

Categories : Javascript
Adding confidence intervals ggplot
In the first way, the dd object you are using is not having the lwr/upr columns. So you cannot really plot them. Can you do a: dd<-merge(dd,pd2,by='date') just after the melts and then: p <- ggplot(dd) + geom_line(aes(x=date, y=value, colour=variable)) p + geom_ribbon(data=dd,aes(x=date, y=value, ymin=lwr,ymax=upr, group=variable),alpha=0.3) Is this helping?

Categories : R
Recently Add
unable to connect selenium webDriver through perl bindings
SSL error calling Perl web service via https using LWP
SOAP::Lite always faults in debug mode
perl referencing a hash outside of the scope that populated it (histogram)
Perl script to print out all the lines containing a keyword and the line below it
PERL Unicode Escape string pass from command line argument wrong output
Perl process crashes after handling signal
Marpa: Can I explicitly disallow keywords as identifiers?
Perl: Import text, containing ÅÄÖ, from file
error using perl - Proc::ProcessTable. works in cmd line, not in .pl file
DBIx::Class chaining resultsets with same table in prefetch
Time as input, print timetable in Perl
compare values of different tables perl
Automatically increasing ID generation using PERL
Syntax Error, first line after dostuff
Delete files in a folder using Perl
Perl '-d' operator is not detecting a directory
Perl appending text to new line
write_timeout in IO::Socket::Timeout
Using ForkManager and Perl properly?
Is a cyclic dependency solved with require?
Posting metric to google analytics from perl script
How can I check if a user enters my page the first time?
Sorting arrays of intervals in perl?
Perl: How to get the link target of a soundcloud feed mp3
Uninitialized value in concatenation
Perl code - pipe "|" in `open()` statement
perl command line backticks with matrix
Perl OO - Creating a list of objects
extract gene-id + function annotation from .gff
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.