in reply to Re: divide multi-column input file into sub-files depending on specific column's value
in thread divide multi-column input file into sub-files depending on specific column's value
Hi, thanks for your time. I know, it was a really long post :( I was just testing your answer, it does indeed do part of what I want. My problem is that it's a bit too smart for my perl knowledge :P As you can see I tried to approach it in a very lengthy way because I could understand it better. I'll try to understand exactly what's happening in the code you posted, it is indeed very useful.
Can I ask one more favour? Could you please maybe explain, when/if you find some time to read the rest of my post, what I'm doing wrong with populating the array? I've been googling for hours and don't seem to be able to get it. All I'm trying to write is that all the $match variables are meant to belong in the @match array, or does that make no sense? In my mind, I'm trying to find a way to print $match and have all the values from -10 to 10 printed. Does that sound correct or am I completely off?
Update: Ok this is what I did and it's working! :) I modified my code from my original post (code attempt #2) by adding and editing your contribution. I believe it works correctly for my purpose, I'm now confirming that my output files are correct.
#!/usr/bin/perl use warnings; use strict; my %fhs; my $molecule = "1kc4"; open my $FILE, '<', 'input_file' or die $!; while (<$FILE>) { chomp; my @columns = unpack('a8 a8 a8 a6'); #print join(" ",map {$_} @columns), "\n"; #print "@columns[3] \n"; foreach (@columns[$#columns]) { my $abs = abs( $columns[ $#columns ] ); open $fhs{ $abs }, '>', "${molecule}_cluster_" . $abs or die $! un +less exists $fhs{ $abs }; my $file = $fhs{ $abs }; my $ID = $_; my $IDform = sprintf ("%4s", $ID); my $currentline = $.; my $currentlineform = sprintf ("%7s", $currentline);## my @selection = (@columns[0..$#columns-1]); my $layout = "%10s"x(@selection) . "\n"; printf $file $IDform . $currentlineform . $layout, @selection; } }
The output filenames are correct and one of them looks like this: 8 109 -42.129 -57.475 94.651 8 110 -45.520 -62.056 90.318 8 111 -49.196 -63.045 92.577 8 112 -46.086 -71.753 88.267 -8 113 -48.146 -76.799 77.638 8 114 -41.865 -62.567 86.437
It would be great if you could take a look and let me know if you see something erroneous in my code. Thank you again for your time :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: divide multi-column input file into sub-files depending on specific column's value
by BrowserUk (Patriarch) on Jul 05, 2016 at 14:37 UTC | |
by angela2 (Sexton) on Jul 05, 2016 at 15:50 UTC | |
by AnomalousMonk (Archbishop) on Jul 05, 2016 at 16:34 UTC | |
by BrowserUk (Patriarch) on Jul 05, 2016 at 16:11 UTC | |
by angela2 (Sexton) on Jul 05, 2016 at 16:23 UTC | |
by Anonymous Monk on Jul 05, 2016 at 16:39 UTC |