// GnomapSRSTest.java // d.gilbert, oct02 //package iubio.srs; import java.io.*; import java.util.*; import java.text.DecimalFormat; import java.text.NumberFormat; import iubio.srs.SRSjni; /** GnomapSRSTest -- test speed of using SRS for genome map feature table lookups by range. Using sample data from Lincoln Stein tested with mysql and postgresql For test genome feature data in IUBio SRS, see lib GNOMAPT at http://iubio.bio.indiana.edu/srs/ http://iubio.bio.indiana.edu/srs6bin/cgi-bin/wgetz?-page+LibInfo+-lib+GNOMAPT there is a big diff in these two query times: time getz '[gnomapt-chr:Chr1]&[gnomapt-bpb#100000:105000]' -c 63 0.47u 0.05s 0:00.57 91.2% time getz '[gnomapt-chr:Chr1]&[gnomapt-bpb#:105000]&[gnomapt-bpe#100000:]' -c 67 25.03u 0.35s 0:25.62 99.0% time getz '[gnomapt-chr:Chr4]&[gnomapt-bpb#10500000:10505000]' -c 74 0.45u 0.09s 0:00.64 84.3% time getz '[gnomapt-chr:Chr4]&[gnomapt-bpb#:10505000]&[gnomapt-bpe#10500000:]' -c 76 23.49u 0.29s 0:24.56 96.8% nobin_mysql.txt:Chr4:10500000..10505000 72 rows in 7.635 seconds, 0.106 sec/row nobin_srs.txt:Chr4:10500000..10505000 74 rows in 0.0690 sec, 0.0009 sec/row @author: Don Gilbert @date: mar 2003 */ public class GnomapSRSTest { static boolean debug= false; static boolean retrieve= false; static boolean twofields= false; static boolean dobin= false; static String lib= "gnomapt"; // gnomapt or gnomapld static String org= "bench"; // for variant benchmark data sets static String binorg= "binbench"; // for variant benchmark data sets public static void main( String[] args ) { String queryfile= "queries.txt"; for (int i= 0; i= search.start q= "["+lib+"-org:"+org+"]&["+lib+"-chr:"+id+"]&["+lib+"-bpb#:"+e+"]&["+lib+"-bpe#"+b+":]"; else // search.start <= feat.start <= search.end q= "["+lib+"-org:"+org+"]&["+lib+"-chr:"+id+"]&["+lib+"-bpb#"+b+":"+e+"]"; //^^ this one is quicker, less precise? ~ binned data if (debug) errln("getz '"+q+"'"); //this.init(srs); //? int nrows= srs.queryGetz( q); //int nrows= srs.anySearch( q); if (debug) errln("nrows= "+nrows); if (retrieve) for (int irow= 0; irow "+new String(kv[i])); // do something with it.. } } long etime= System.currentTimeMillis() - estart; double sec= etime / 1000.0; double pr= (nrows==0) ? 0 : sec/nrows; println(id+":"+b+".."+e+"\t"+nrows+" rows in " +nf.format(sec)+" sec, " +nf.format(pr)+" sec/row"); } srs.close(); srs= null; bs.close(); } //from perl package Bio::DB::GFF::Util::Binning; static int MINBIN = 1000; static int MAXBIN = 1000000; String getBins(String b, String e) { try { //$start = 0 unless defined $start; //$end = MAXBIN unless defined $end; int start= Integer.parseInt(b); int end= Integer.parseInt(e); StringBuffer bins= new StringBuffer("&("); //my @bins; int minbin = MINBIN; int maxbin = MAXBIN; int tier = maxbin; boolean first= true; while ( tier >= minbin) { String tier_start= bin_bot( tier, start); String tier_end= bin_bot ( tier, end);//bin_top String q; if ( tier_start.equals(tier_end)) { q= "["+lib+"-bin:"+tier_start+"]"; //push @bins,"fbin=$tier_start"; } else { q="["+lib+"-bin#"+tier_start+":"+tier_end+"]"; //push @bins,"fbin between $tier_start and $tier_end"; } if (!first) bins.append("|"); first= false; bins.append(q); tier /= 10; } //return $query = join("\n\t OR ",@bins); bins.append(")"); return bins.toString(); } catch (Exception ex) { ex.printStackTrace(); return ""; } } //*bin_top = \&bin_bot; //sub bin_name { sprintf("%d.%06d",@_) } static NumberFormat denom= new DecimalFormat("000000"); //static NumberFormat binf = new DecimalFormat("#####.000000"); String bin_bot(int tier, int pos) throws Exception { //bin_name($tier,int($pos/$tier)); int d= (int)(pos/tier); String bn= String.valueOf(tier)+"."+denom.format(d); return bn; //Number bx= binf.parse(bn); //return bx.doubleValue(); } /* getz '[gnomapt-org:binbench]&[gnomapt-chr:Chr1]& ([gnomapt-bin:1000000.0]|[gnomapt-bin:100000.0]|[gnomapt-bin:10000.0] |[gnomapt-bin#1000.0:1000.000005]) &[gnomapt-bpb#:5000]&[gnomapt-bpe#0:]' .. would srs binning work better as ?? [lib-bp#start:end] | ([lib-bin:100000.0]|[lib-bin:10000.0]|...) */ public SRSjni open() { SRSjni srs= new SRSjni(); init(srs); return srs; } public void init(SRSjni srs) { long si= srs.newSession(); // == newSession(); //== srs.open() // dont need this ldap stuff?? srs.setBaseDN("srv=srs","srv=srs"); // dont need? srs.setSearchScope(2);// 0,1,2 //* BioseqSet BioseqEntry BioseqRecord BinaryBioseqRecord srs.setObjectClasses("BioseqRecord"); //srs.setReturnAttributes("seq"); } final static void println(String s) { System.out.println(s); } final static void errln(String s) { System.err.println(s); } final static void printhead(String s) { System.out.println(); System.out.println(); System.out.println(">>>>>> "+s); } }