Advertisement
Guest User

Untitled

a guest
Feb 6th, 2018
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.20 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use constant { RIGHT=>1, LEFT=>0, NAME=>2 };
  5.  
  6. my(@repeats,@genes, @t47);
  7.  
  8. loadFile(\@genes,"genes-g38-201505-nodoppel-chr1.csv",0,1,3);
  9. loadFile(\@repeats,"repeats-g38-201505-nodoppel-chr1.csv",1,2,3);
  10. loadFile(\@t47,"47k-80-80-ignore-random-noreverse-chr1.csv",0,1,2);
  11.  
  12. @repeats=sort {$a->[RIGHT] <=> $b->[RIGHT]} @repeats;
  13.  
  14. my $tl=@t47;
  15. my $gl=@genes;
  16. my $rl=@repeats;
  17. my ($gi, $ri)=(0,0);
  18. for(my $ti=0;$ti<$tl;$ti++) {
  19.   $gi++ while($genes[$gi][RIGHT] <= $t47[$ti][LEFT] && $gi<$gl);
  20.   $ri-- while($repeats[$ri][RIGHT] > $t47[$ti][RIGHT] && $ri>0);
  21.   $ri++ while($repeats[$ri][RIGHT] <= $t47[$ti][RIGHT] && $ri<$rl);
  22.   for(0..3) {
  23.     next if($t47[$ti][LEFT] <= $genes[$gi][LEFT] ||
  24.             $t47[$ti][RIGHT] <= $repeats[$ri+$_][LEFT] ||
  25.             $t47[$ti][LEFT] >= $genes[$gi][RIGHT] ||
  26.             $t47[$ti][RIGHT] >= $repeats[$ri+$_][RIGHT]
  27.             );
  28.     print join(',',@{$t47[$ti]},$genes[$gi][NAME],$repeats[$ri+$_][NAME]),"\n";
  29.   }
  30. }
  31.  
  32. sub loadFile {
  33.   my $o=shift;
  34.   my $name=shift;
  35.   open(my $fl,"<",$name) or die("Can't open file $name\n");
  36.   while(<$fl>) {
  37.    chomp;
  38.    my @r=(split(/,/))[@_];
  39.    push @{$o}, \@r;
  40.   }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement