Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by $new_guy (Acolyte)
on Sep 29, 2010 at 10:51 UTC ( [id://862587]=note: print w/replies, xml ) Need Help??


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

Dear Moritz,

The numbers are generated at random and I just print them to the screen to show what they are. But, yes you could store them in a file! So what i intend to do is to use the random numbers generated to do the counts! For instance if my group has 38, 39, 40; then what I intend to do is to compare the z's in columns 38, 39, 40 (that have been randomly generated) of my file! So if they are 44, 45, 99, ...., 123; I would like to count and find the average of all the z's that are common to all these columns!

The bit that doesn't work is where I run out of ideas and got stuck!

  • Comment on Re^2: Selecting, matching and counting column elements, using randomly generated numbers

Replies are listed 'Best First'.
Re^3: Selecting, matching and counting column elements, using randomly generated numbers
by moritz (Cardinal) on Sep 29, 2010 at 11:24 UTC
    But, yes you could store them in a file!

    But your program doesn't do that. And later on you want to compare those values to some other values, and it doesn't work... because you don't have access to them anymore.

    So, let's summarize: You generate values, but you don't store them. You read data from a while, but you don't do anything with it. So there's are at least two steps missing: extracting the columns from the read data, and make the generated data available to the program itself.

    When you've done these two steps, maybe you'll get unstuck.

    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?

    Perl 6 - links to (nearly) everything that is Perl 6.

      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 script.pl <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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://862587]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found