
effc
Novice
Nov 23, 2012, 1:04 PM
Post #1 of 5
(3241 views)
|
loop question?
|
Can't Post
|
|
I wrote a script that will take a data point for one coordinate and create a file. Now I want to create a file per column with each of the row headers as well (including the data). Can't seem to figure it out in my script this is what I have so fa, but it's still doing the original operation. #!/usr/bin/perl # parse JnJ output file and create single data file for each animal id/probe print "start\n"; my $file = "JnJ.txt"; my $rowCounter = 0; my @animalNames; my $numCol; open (IN, "$file" || die); #main objective to pop data from X/Y with headers, this just appears to define while (my $line = <IN>) { if ($rowCounter < 1) #process first line { $rowCounter = $rowCounter + 1; @animalNames = split('\t', $line); #array definition $numCol = scalar(@animalNames); #scalar definition } #read first line = list of hybs #scalar = number of hybs #open a file for each hyb / add header line (PROBE, ID) #make a hash for number and array name elsif ($rowCounter > 0) { my $colCounter = 2; my @probeData = split('\t', $line); #row my $probeName = @probeData[0]; while ($colCounter < $numCol) { my $animalName = @animalNames[$colCounter]; my @animalIds = split('\|', $animalName); my $animalId = @animalIds[2]; my $probeValue = @probeData[$colCounter]; open (OUT, ">>$animalId") or die("Cant open $animalId, $!"); for($rowCounter < 35131) #35131 is the amount of rows in file { print OUT "$animalName\n$probeName\t$probeValue"; close (OUT); } $colCounter = $colCounter + 1; } } } close (IN); Thanks in advance!!
|