# Additional file 2 # to run this program, you need two text files: # 1. the locus sequence (referred to here as locusfile.txt); this should be a sequence with the repeats in lowercase # 2. the breakpoint sequences (referred to here as breaks.text); this should be a list of the breakpoints, one on each line; # to run the program, go to command line, go into the correct directory, and type: # find_site.pl locusfile.txt breaks.txt # this part of the program reads locusfile.txt and creates $seq from it my $locus= $ARGV[0]; open(IN1,"<$locus") or die $!; my $seq = ''; while (){ chomp; $seq = $seq . $_; }; close (IN1); # this part reads breaks.txt, matches them to $seq, and returns their distance to a repeat my $breaks= $ARGV[1]; open(IN2,"<$breaks") or die $!; open(OUT,">outputfile.txt") or die $!; $numberofbreaks = 0; while ($breaksequence=){ $breaksequence =~ s/^\s+//; $breaksequence =~ s/\s+$//; $rc = scalar reverse $breaksequence; $rc =~ tr/ACGTacgt/TGCAtgca/; if ($seq =~ m/($breaksequence)/i) { my $matchposition = $+[0]-1; my $matchletter = substr($seq,$matchposition,1); my $distance = getDistance($seq,$matchposition); $numberofbreaks = $numberofbreaks +1; print OUT "$breaksequence matches\t$matchposition\t$matchletter\t$distance\n"; } elsif ($seq =~ m/($rc)/i) { my $rcmatchposition = $-[0]; my $rcmatchletter = substr($seq,$rcmatchposition,1); my $rcdistance = getDistance($seq,$rcmatchposition); $numberofbreaks = $numberofbreaks +1; print OUT "$breaksequence was reverse complemented to $rc\t$rcmatchposition\t$rcmatchletter\t$rcdistance\n"; } else {print OUT "$breaksequence and its reverse complement have no match"; }; }; print OUT "\nYou matched $numberofbreaks breaks.\n" ; # this part does the same thing for 1000 random positions for each breakpoint matched print OUT "\nrandom site no.\t position in sequence \t distance to a repeat\n" ; for (my $i = 0; $i <= (1000 * $numberofbreaks); $i++) { my $randdistance; my $seqLen = length($seq); my $randomPos = int(rand($seqLen)); my $randdistance = getDistance($seq,$randomPos); print OUT "$i\t$randomPos\t$randdistance\n"; }; close OUT; # this subroutine measures the distance between a position in $seq and the nearest repeat sub getDistance { # defining variables my ($seq,$matchposition) = @_ ; my $matchletter = substr($seq,$matchposition,1); my $maxD = length($seq); my $leftDistance = $matchposition; my $rightDistance = length($seq) - $matchposition; # defining the distance # if the position in question is lowercase, the distance is 0 if ($matchletter eq lc($matchletter)) { return 0; # else search left (1st while) and right (2nd) then return the shortest distance (if, else) } else { $i = $matchposition; while (($i >= 0) && ($leftDistance == $matchposition)) { $i--; $val = substr($seq,$i,1); if ($val eq lc($val)) { $leftDistance = (abs($matchposition - $i))-1; } } $i = $matchposition; while ($i < length($seq) && $rightDistance == (length($seq) - $matchposition)) { $i++; $val = substr($seq,$i,1); if ($val eq lc($val)) { $rightDistance = abs($matchposition - $i); } } if ($leftDistance < $rightDistance) { return $leftDistance; } else { return $rightDistance; } } }