Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re^4: Selecting, matching and counting column elements, using randomly generated numbers by $new_guy
in thread Selecting, matching and counting column elements, using randomly generated numbers by $new_guy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-25 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found