loop(0); # the next section takes each route and counts the number of unique snp's for each route # for the num of possible routes through the matrix for $i (0 ... $#finalroute) { $number_of_unique_columns=0; %count=(); # for each step of the particular route we are looking at for (@{$finalroute[$i]}) { $count{$_}++; } # this loop counts the number of keys , therefore gives the number of columns used in this route thru the matrix for (keys %count) { $number_of_unique_columns++; } $route[$i]=$number_of_unique_columns; } # $column_limit is user input set at the beginning and is the cut-off for the num of columns used for $i ( 1 ... $column_limit ) { #step the route array which has the number of columns used #for each route. If it equals the $i value (number of #columns) we #are currently looking at then print out the route thru the #matrix that is associated with it i.e @{$finalroute[$_]} for (0 ... $#route) { print "@{$finalroute[$_]}\n$route[$_]\n" if $route[$_]==$i; } } sub loop{ my ($row,@array)=@_ ; for (1 ... $#number_of_columns) { push @array,$_ if $matrix[$row][$_] ==1; my $length=@array; my $lengthofmatrix=@matrix; if ($row==$lengthofmatrix) { $finalroute[$block][$y]=[@array] if $length==$lengthofmatrix; $y++ if $length==$lengthofmatrix; } else { loop($row+1,$block,@array); } pop @array if $matrix[$row][$_]==1; } }