[Bio] / FigKernelScripts / svr_keep_only.pl Repository:
ViewVC logotype

View of /FigKernelScripts/svr_keep_only.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.1 - (download) (as text) (annotate)
Sun Sep 19 13:25:56 2010 UTC (9 years, 6 months ago) by overbeek
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
support filtering on function or role

use strict;
use SAPserver;
use ScriptThing;

use Data::Dumper;

=head1 svr_keep_only

=head2 Introduction

    svr_keep_only -f='Threonine synthase (EC'  < ids > ids.that.pass 2> ids.that.fail

Reads a stream of PEGs, filtering out those that do not have a desired function or functional role.
Those that are filtered out are written to STDERR.  Those that pass go to STDOUT.

=head2 Command-Line Options

=over 4

=item -f='functions to keep'

Specifies the function that must be on PEGs that are kept

=item -r='functional role to keep'

Specifies a functional role.  All IDs with this role will be kept.

=item -s

Asks for comments to be stripped from the function before checking for a match

=item -d

specifies that the designated criteria is for deletion, not retention


=head2 Command-Line Options

=over 4

=item -url

The URL for the Sapling server, if it is to be different from the default.

=item -c

Column index. If specified, indicates that the input IDs should be taken from the
indicated column instead of the last column. The first column is column 1.


=head3 Output Format

Input lines will be copied to the output (STDOUT) when they pass the criteria for matching.


my $strip = 0;
my $column=0;
my $delete = 0;
my $url = "";

use Getopt::Long;
my $rc =  GetOptions( 'url=s' => \$url, 
		      'c=i'   => \$column,
		      'f=s'   => \$function,
		      'r=s'   => \$role,
		      'd'     => \$delete,
		      's'     => \$strip);

# Get the server object.
my $sapO = SAPserver->new(url => $url);

while (my @tuples = ScriptThing::GetBatch(\*STDIN, undef, $column)) 
    my @pegs = map { $_->[0] } @tuples;
    my $funcH = $sapO->ids_to_functions( -ids => \@pegs );
    foreach my $request (@tuples)
	my($peg,$line) = @$request;
	my $func       = $funcH->{$peg};
	if (! $func) { $func = "" }
	if ($strip)  { $func =~ s/\s*\#.*$// }
	my $matches = 0;
	if ($function)
	    $matches = ($function eq $func);
	elsif ($role && $func)
	    foreach my $x (&SeedUtils::roles_of_function($role))
		if ($x eq $role)
		    $matches = 1;
	if (($delete && (! $matches)) ||
	    ((! $delete) && $matches))
	    print $line,"\n";
	    print STDERR $line,"\n";

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3