#!perl # ldapsearch.pl =head1 NOTES Test LDAP directory of genome data at http://euGenes.org/ This script fetches and prints sequence and associated gene features from an ldap directory of genome annotations at euGenes.org The species, chromosome, feature kind and base range can be specified. Search of high level directories provide information on contents of the specific attributes available in species-chromosome directories. =cut use lib '/Users/gilbertd/bio/perlib/'; # dgg home perls use URI::URL; use LWP::UserAgent; use Net::LDAP; my $ns= 0; foreach my $a (@ARGV) { if ($a =~ m,^ldap://,) { ldapSearch($a); $ns++; } elsif ($a =~ m,^test,) { test(); $ns++; } elsif ($a =~ m,^h,) { help(); $ns++; } } if ($ns == 0) { help(); } exit; sub help { print("ldapsearch [ help | test | ldap://url.../?... ]\n"); print(" Simple client for LDAP, testing Bio-data directory servers\n"); print(" Call with ldap url or 'test' to test these bio-directories:\n"); print("\n"); $helping= 1; test(); } sub test { my $url; print("Biosequence directory - top level (SRS-LDAP, service srv=srs)\n"); $url= "ldap://iubio.bio.indiana.edu:3895/srv=srs"; ldapSearch( $url ); print("Biosequence directory (search for protein kinesin)\n"); $url= "ldap://iubio.bio.indiana.edu:3895/srv=srs??sub" ."?(&(objectClass=*)(lib=swissprot trembl refseq)(des=kinesin))" ."?sizelimit=2"; ldapSearch( $url ); print("Top level genome map directory (service srv=srsgnomap)\n"); $url= 'ldap://eugenes.org:3891/srv=srsgnomap??one?(&(objectClass=*))?'; ldapSearch( $url ); print("One level directory of worm species data\n"); $url= 'ldap://eugenes.org:3891/spp=worm,srv=srsgnomap??one?(&(objectClass=*))?'; ldapSearch( $url ); print("Search directory of fly species, chromosome 2L, and all subdirectories \n"); print("for Feature and NA-Sequence objects, for the chromosome base range\n"); print("and limit search to specific feature (ft) kinds\n"); $url= 'ldap://eugenes.org:3891/ft=gene,chr=2L,spp=fly,srv=srsgnomap' .'?' # id,loc,name' #,map,dbxref .'?sub' ."?(&(|(objectClass=Feature)(objectClass=NA-Sequence))" # search filter ."(|(ft=gene)(ft=CDS)(ft=insertion))" .'(start=>50000)(stop=<80000))' ## .'(start=<2000000)(stop=>1000000))' .'?sizelimit=20,deref=always' ; ldapSearch( $url ); exit; } # minimal ldapSearch() - should do error checks sub ldapSearch { my $surl= shift; my $url= new URI::URL($surl); print "Search URL: $url\n\n"; return if $helping; if ($url->scheme ne 'ldap') { warn "not ldap: $url\n"; return; } my $scope = $url->scope || "base"; my @opts = (scope => $scope); push @opts, "base" => $url->dn if $url->dn; push @opts, "filter" => $url->filter if $url->filter; my @attrs = $url->attributes; push @opts, "attrs" => \@attrs if @attrs; my @extn = $url->extensions; push @opts, @extn if (@extn); $ldap = new Net::LDAP($url->host, port => $url->port) or die "$@"; $ldap->bind; # anonymous my $mesg = $ldap->search(@opts); if ($mesg->code) { warn $mesg->error,"\n"; } else { foreach my $e ($mesg->all_entries) { $e->dump; } } $ldap->unbind; print "\n"; }