I have a little bit problem in my code which I am unable to sort out. My input file is
536 ENERGY = -176.2 proMy code is
$data_file="HIVgag.ct"; open(MYFILE, $data_file) || die("Could not open file!"); $b=$between=$energy=0; while (<MYFILE>) { if (/energy/i) { $energy++; $between=$b; } elsif ($energy) {$b++} } print "$energy / $between\n"; close(MYFILE); open(MYFILE, $data_file) || die("Could not open file!"); open(WRITE, ">final.net"); print WRITE "*vertices $between\n"; while(<MYFILE>) { foreach $row (<MYFILE>) { @row = $row; (@row[0],@row[1],@row[2], @row[3], @row[4], @row[5], @row[6])=split(/\ +s+/,$row); if (@row[2] ne ENERGY) { print WRITE "@row[1] $row[2]\n"; print"@row[1] $row[2]\n"; } } } close(MYFILE); open(MYFILE, $data_file) || die("Could not open file!"); { print WRITE "*edges\n"; my $energy; while ( <MYFILE> ) { if ( /\bENERGY\b/ ) { ++$energy; next; } my ( $key, @fields ) = grep $_, split; for my $field ( @fields ) { if ( $field ne 'G' && $field ne 'A' && $field ne 'C' && $field ne +'G' ) { print WRITE "$key $field $energy\n"; } } } } close(WRITE);
My code rearranges the input file in a way such that the first two columns of the file is written in *vertices portion. And in the *edges portion the 1st column of the input file makes a pair with the 3rd, 4th , 5th and 6th column omitting the pairs containing zero in 3rd, 4th, 5th and 6th column. The 3rd column of *edges consists of the number of “energy block” in which the pair exists. Thus the output file is
*vertices 3What I want is in the *vertices portion it should only read the first two columns of the first “energy block” and then it should jump to *edges portion which implies that in this case it should only print 1 G, 2 G and 3 G and then jump to *edges portion. And in *edges portion the first column of input file should not make pair with 6th (last) column. So the output should be like
*vertices 3I shall be very thankful for help.
In reply to Spliting file + removing column by AG87
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |