Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^4: Selecting, matching and counting column elements, using randomly generated numbers

by $new_guy (Acolyte)
on Sep 30, 2010 at 13:06 UTC ( #862788=note: print w/replies, xml ) Need Help??

in reply to Re^3: Selecting, matching and counting column elements, using randomly generated numbers
in thread Selecting, matching and counting column elements, using randomly generated numbers

I have decided to store all the randomly generated numbers in the file random.txt. It was what i was doing initially but then I also had to find out how many times the script was running! Iterations and so I removed the "POS" file handle for the randomly generated numbers.

Now, I have decide to make two files! One to count the number of iterations and to destroy it once am done with it! And the other to store the random generated numbers!

#!/usr/bin/perl use strict; use warnings; #exit if there's more or less than two arguments if(scalar(@ARGV)!= 2) { print "\nUsage <file name> <number + of columns>\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 = <DATA3>) { #now make a file for the output my $output_r = "random.txt"; if (! open(R, ">>$output_r") ) { print "Cannot open file \"$output_r\" to write to!!\n\n"; exit; } #now make a file for a count of the number of iteratio +ns my $output_s = "random_count.txt"; if (! open(RC, ">>$output_s") ) { print "Cannot open file \"$output_s\" to write to!!\n\n"; exit; } # now randomly generate the columns to count elements (or z's) # but first declare variables my $randomize = $ARGV[1]; # the number of columns entered at com +mand-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 column +s to 96 columns print R "\n"; # separate each random selec +tion by a space for($x = 1; $x < $y; $x++){ # do the random colum +n selection #randomly select columns my $random_number = int(rand($range)) + $minimum; #print the columns selscted at random print R $random_number . "\n"; $count++; ## random columns for selection have been created ## now map the elements of each of the groups selected ## count only those that have z's in all of them my @temp = map { ($_[1], $_[0], $_ )[2] } @uniform; # @uniform = $random_number; # push @{$data[$n++]}, (split /\s+/, $ro); # 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_elements(@temp){ #print POS "$temp[2][1]\n"; #} } } #evaluate the number of random columns selections used for this analys +is print RC "\n". $count*30 ." random columns selections were u +sed!!\n"; print "\n". $count*30 ." random columns selections were used +!!\n"; } # the end # my $count2; open (FILE, "random_count.txt") or die"can't count c +lusters\n"; $count2++ while <FILE>; print "\n$count2 round(s) done\n"; #now remove the iterations file unlink("random_count.txt");

Now the numbers stored in random.txt separated by white spaces are my columns in the file read in: "<file name>" - provided at command line and I posted it above.

" Also please notice that your description of what you want to do is incomplete: you write you want to compare values, but you never mentioned what you want to do with the result of the comparison. Store it? count it? make funny bit masks? destroy the world? "

I would like to compare the z's in the corresponding rows of the columns; if they all have z's I make a count; if they don't I don't count. Then I want to write the z's to a file

The desired out put should be like this, note that the first column with out the z's (ie it has only numbers should not be tampered with):

0 23 34 56 78 99 ... n 0 58 97 22 10 ... n 0 78 56 77 ... n 1 66 67 ... n 1 54 ... n Mean 23 46 77 ... etc

desirably, a mean at very the bottom would be nice

  • Comment on Re^4: Selecting, matching and counting column elements, using randomly generated numbers
  • Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://862788]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2018-05-21 01:30 GMT
Find Nodes?
    Voting Booth?