#!/usr/bin/perl use strict; use warnings; #exit if there's more or less than two arguments if(scalar(@ARGV)!= 2) { print "\nUsage script.pl \n"; exit(); } ##you will print results but first remove any previous files my $remove_random = "random.txt"; if (unlink($remove_random) == 1) { print "Existing \"random.txt\" file was removed\n"; } ## proceed by opening the file my $ro = $ARGV[0]; open(DATA3, $ro); while ($ro = ) { #now make a file for the output my $output_r = "random.txt"; if (! open(POS, ">>$output_r") ) { print "Cannot open file \"$output_r\" to write to!!\n\n"; exit; } # now randomly generate the columns to count z's # but first declare variables my $randomize = $ARGV[1]; # the number of columns entered at command-line my $range = $randomize; # the maximum number of columns my $minimum = 1; # the minimum number of columns my $y; # the increasing number of columns my $x; # the random genome selected my $count; # count the number of randomisations done my @uniform = (); my @data = (); my $n = 0; #loop through the selection process for($y = 1; $y < $range +1; $y++){ # make selection from 2 columns to 96 columns print "\n"; # separate each random selection by a space for($x = 1; $x < $y; $x++){ # do the random column selection #randomly select columns my $random_number = int(rand($range)) + $minimum; #print the columns selected at random print $random_number . "\n"; $count++; ## random columns for selection have been created ## now compare the elements of each of the groups selected and count only the number of z's common to all columns for each group! ## i.e. count only those times that have z's in all of them (i.e. the group) ##this bit of the script is not working ### # @uniform = $random_number; # my @temp = map { [ $_[1], $_[0], $_ ] } # step 1 # map { $_->[2] } # step 2 # @uniform; #Count array elements that match a pattern #In a scalar context, grep returns a count of the selected elements. #foreach my $num_genes(@temp){ #print POS "@temp\n"; #} } } #evaluate the number of random columns/columns selections used for this analysis print POS "\n". $count*30 ." random columns selections were used!!\n"; print "\n". $count*30 ." random columns selections were used!!\n"; } # the end # my $count2; open (FILE, "random.txt") or die"can't count clusters\n"; $count2++ while ; print "\n$count2 round(s) done\n";