#!/usr/bin/env raku
# Check if the correct number of arguments are provided
if @*ARGS.elems != 2 {
say "Usage: ./compare_bed_files.raku file1.bed file2.bed";
exit 1;
}
# Read the contents of the two BED files
my @bed1 = slurp(@*ARGS[0]).lines;
my @bed2 = slurp(@*ARGS[1]).lines;
# Iterate over each interval in the first BED file
for my $line1 (@bed1) {
my @fields1 = $line1.split("\t");
my $chr1 = @fields1[0];
my $start1 = @fields1[1];
my $end1 = @fields1[2];
# Check for overlaps with intervals in the second BED file
for my $line2 (@bed2) {
my @fields2 = $line2.split("\t");
my $chr2 = @fields2[0];
my $start2 = @fields2[1];
my $end2 = @fields2[2];
# Check for chromosome match and overlap
if $chr1 eq $chr2 && $start1 < $end2 && $end1 > $start2 {
say "Overlap found:";
say "File 1: $line1";
say "File 2: $line2";
say "";
}
}
}
say "Comparison completed.";