Advertisement
Guest User

Untitled

a guest
Feb 6th, 2018
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.11 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. my $tl=@t47;
  13. my $gl=@genes;
  14. my $rl=@repeats;
  15. my ($gi, $ri)=(0,0);
  16. $|=1;
  17. for(my $ti=0;$ti<$tl;$ti++) {
  18.   $gi++ while($genes[$gi][RIGHT] <= $t47[$ti][LEFT] && $gi<$gl);
  19.   $ri-- while($repeats[$ri][RIGHT] > $t47[$ti][RIGHT] && $ri>0);
  20.   $ri++ while($repeats[$ri][RIGHT] <= $t47[$ti][RIGHT] && $ri<$rl);
  21.   next if($t47[$ti][LEFT] <= $genes[$gi][LEFT] ||
  22.           $t47[$ti][RIGHT] <= $repeats[$ri][LEFT] ||
  23.           $t47[$ti][LEFT] >= $genes[$gi][RIGHT] ||
  24.           $t47[$ti][RIGHT] >= $repeats[$ri][RIGHT]
  25.           );
  26.   print join(',',@{$t47[$ti]},$genes[$gi][NAME],$repeats[$ri][NAME]),"\n";
  27. }
  28.  
  29. sub loadFile {
  30.   my $o=shift;
  31.   my $name=shift;
  32.   open(my $fl,"<",$name) or die("Can't open file $name\n");
  33.   while(<$fl>) {
  34.    chomp;
  35.    my @r=(split(/,/))[@_];
  36.    push @{$o}, \@r;
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement