#!/usr/bin/perl # The first line might be #!/usr/local/bin/perl etc # depending on the system. # gsort.pl: # Do not delete this comment.##################### if ( $#ARGV < 0 ) { print "usage: $0 summary_file hom_file switch > outfile.\n"; print "Homology matrix is extracted according to the summary information.\n"; print "switch: 0 - default; 1 - output also related sequences.\n"; exit 1; } $infile = $ARGV[0]; $homfile = $ARGV[1]; $switch = $ARGV[2]; $startRelated = " Related groups:"; $endRelated = " END Related groups."; $domainlist = "Domain list"; print STDERR "Summary file is $infile.\n"; print STDERR "Homolog file is $homfile.\n"; if ( $switch == 1) { print "Output includes related groups.\n"; } open(INFILE, $infile) || die "Unable to open summary file: $infile.\n"; open(HOMFILE, $homfile) || die "Unable to open homology file: $homfile.\n"; $exitflag = 0; while() { if ( $_ =~ /^\ / || $_ =~ /^Number/ || $_ eq "\n" ) { next; } @list = split( /\s+/, $_ ); $grpno = $list[0]; $grpstring = "Group " . $grpno . ":"; $outputflag = 0; while() { if ( $outputflag == 1 ){ print $_; if ( $_ eq "\n" ) { $counter += 1; if ( $counter >= 2 ) { if ( $switch == 1 ) { $outputflag = 2; next; } else { $outputflag = 0; last; } } } } elsif ( $outputflag == 2 ) { if ( $_ =~ /^$startRelated/ ) { print $_; $counter = 0; } elsif ( $_ =~ /^$endRelated/ ) { print $_; print "\n"; $outputflag = 0; $counter = 0; last; } elsif ( $_ =~/$domainlist/ ) { $counter = -1; print $_; } elsif ( $_ eq "\n" ) { $counter += 1; if ( $counter >= 2 ) { $counter = 0; $outputflag = 0; last; } else { print $_; } } else { print $_; } } else { $line = $_; if ( $line eq "\n" ) { next; } if ( $line =~ /^$grpstring/ ) { $outputflag = 1; $counter = 0; print $line; next; } } } } close(INFILE); close(HOMFILE); #end