From: Nomi H. <no...@us...> - 2002-01-30 22:56:32
|
Update of /cvsroot/gmod/apollo/src/java/apollo/dataadapter In directory usw-pr-cvs1:/tmp/cvs-serv20172 Modified Files: Tag: sanger_branch GAMEAdapter.java Log Message: I'm a little reluctant to commit this because there is some slightly kludgey stuff for testing different ways to select a datafile without actually having a GUI for it yet, so you can type into the file selection box things like "gene=cact" or "band=34A" and it will find the relevant XML file via a cgi. (In the case of a query that spans more than one scaffold, it will just use the FIRST one it finds.) Index: GAMEAdapter.java =================================================================== RCS file: /cvsroot/gmod/apollo/src/java/apollo/dataadapter/GAMEAdapter.java,v retrieving revision 1.30.2.19 retrieving revision 1.30.2.20 diff -C2 -d -r1.30.2.19 -r1.30.2.20 *** GAMEAdapter.java 2002/01/30 19:29:36 1.30.2.19 --- GAMEAdapter.java 2002/01/30 22:56:28 1.30.2.20 *************** *** 78,86 **** public String getName() { ! return "GAME Adapter"; } public String getType() { ! return "GAME XML Filename or URL"; } --- 78,86 ---- public String getName() { ! return "GAME XML Adapter"; } public String getType() { ! return "GAME XML source (filename, URL, gene=cact, band=34A, or sequence=ACGT)"; } *************** *** 100,106 **** public GAMEAdapter(String xmlsource) { ! if (xmlsource.startsWith("http")) setURL(xmlsource); else { System.out.println("Setting filename: " + xmlsource); // DEL setFilename(xmlsource); --- 100,109 ---- public GAMEAdapter(String xmlsource) { ! if (xmlsource.startsWith("http")) { ! setFilename((String) null); setURL(xmlsource); + } else { + setURL((String) null); System.out.println("Setting filename: " + xmlsource); // DEL setFilename(xmlsource); *************** *** 110,117 **** public void setFilename(String filename) { // !! This is just while debugging ! if (filename.startsWith("http")) setURL(filename); ! else this.filename = filename; } --- 113,124 ---- public void setFilename(String filename) { // !! This is just while debugging ! if (filename.startsWith("http")) { ! setFilename((String) null); setURL(filename); ! } ! else { ! setURL((String) null); this.filename = filename; + } } *************** *** 125,128 **** --- 132,139 ---- public void setURL(String urlstring) { + if (urlstring == null) { + this.url = null; + return; + } try { this.url = new URL(urlstring); *************** *** 134,137 **** --- 145,159 ---- } + public URL getURL() { + return url; + } + + public String getInputName() { + if (url != null) + return (url.toString()); + else + return filename; + } + public Properties getStateInformation() { Properties props = new Properties(); *************** *** 948,955 **** ex2.printStackTrace(); } ! String message = "Couldn't read " + filename; ! if (url != null) ! message = "Couldn't read " + url; ! throw new DataAdapterException(message); } return curation; --- 970,974 ---- ex2.printStackTrace(); } ! throw new DataAdapterException(ex2.getMessage()); } return curation; *************** *** 970,977 **** } else if ((filename != null) && !(filename.equals(""))) { ! // !! FOR DEBUGGING--assume that a SHORT filename is actually a GENE NAME ! if (filename.length() < 6) { // DEL ! System.out.println("Assuming " + filename + " is actually a gene name you're searching for"); ! url = getURLForGene(filename); if (url == null) { System.err.println("Couldn't find url for " + filename); --- 989,1041 ---- } else if ((filename != null) && !(filename.equals(""))) { ! // !! FOR DEBUGGING--filename that starts with gene= is a GENE NAME ! if (filename.startsWith("gene=")) { ! String gene = filename.substring(5); ! url = getURLForGene(gene); ! if (url == null) { ! String message = "Couldn't find url for " + filename; ! System.err.println(message); ! stream = null; ! throw new DataAdapterException(message); ! } ! if (url != null) { ! try { ! System.err.println("Trying to open url " + url + " for reading"); ! stream = url.openStream(); ! } catch (Exception e) { ! String message = "Gene " + gene + " not found"; ! System.err.println(message); ! stream = null; ! throw new DataAdapterException(message); ! } ! } ! } ! // !! FOR DEBUGGING--"filename" that starts with "band=" is a cytological location ! else if (filename.startsWith("band=")) { ! String band = filename.substring(5); ! url = getURLForBand(band); ! if (url == null) { ! String message = "Couldn't find url for " + filename; ! System.err.println(message); ! stream = null; ! throw new DataAdapterException(message); ! } ! if (url != null) { ! try { ! System.err.println("Trying to open url " + url + " for reading"); ! stream = url.openStream(); ! } catch (Exception e) { ! String message = "Couldn't find scaffold for cytological location " + band; ! System.err.println(message); ! stream = null; ! throw new DataAdapterException(message); ! } ! } ! } ! ! // !! FOR DEBUGGING--"filename" that starts with "sequence=" is a DNA string to search for with BLAST ! else if (filename.startsWith("sequence=")) { ! String seq = filename.substring(9); ! url = getURLForSequence(seq); if (url == null) { System.err.println("Couldn't find url for " + filename); *************** *** 995,999 **** stream = new FileInputStream (filename); } catch (Exception e) { - System.err.println("Error: could not open file " + filename + " for reading."); stream = null; // If we couldn't find filename, and it's a relative, rather than absolute, path, --- 1059,1062 ---- *************** *** 1002,1006 **** String rootdir = System.getProperty("APOLLO_ROOT"); setFilename(rootdir + "/" + filename); ! System.err.println("Trying " + getFilename()); // DEL try { InputStream newstream = XMLInputStream(); --- 1065,1069 ---- String rootdir = System.getProperty("APOLLO_ROOT"); setFilename(rootdir + "/" + filename); ! System.err.println("Trying to open " + getFilename()); // DEL try { InputStream newstream = XMLInputStream(); *************** *** 1008,1019 **** } catch (DataAdapterException e2) { ! System.err.println(getFilename() + " didn't work either, oh well"); // DEL throw new DataAdapterException("Error: could not open file " + filename + " for reading."); } } ! throw new DataAdapterException("Error: could not open file " + filename + " for reading."); } } } return stream; } --- 1071,1084 ---- } catch (DataAdapterException e2) { ! // System.err.println(getFilename() + " didn't work either, oh well"); // DEL throw new DataAdapterException("Error: could not open file " + filename + " for reading."); } } ! throw new DataAdapterException("Error: could not open " + getInputName() + " for reading."); } } } + fireProgressEvent(new ProgressEvent(this, new Double(65.0), + "Reading GAME XML...")); return stream; } *************** *** 1023,1027 **** * returns an Curation derived from the XML document */ ! private void readXML(InputStream istream) { element_chain = new Stack(); --- 1088,1093 ---- * returns an Curation derived from the XML document */ ! private void readXML(InputStream istream) ! throws DataAdapterException { element_chain = new Stack(); *************** *** 1045,1051 **** xml_parser.parse(new InputSource(istream)); } catch (Exception e) { ! System.err.println("Fatal Error near element # " + element_count + " : " + e.getMessage()); ! e.printStackTrace(); } } --- 1111,1117 ---- xml_parser.parse(new InputSource(istream)); } catch (Exception e) { ! System.err.println("Fatal Error in xml parse near element # " + element_count + " : " + e.getMessage()); ! throw new DataAdapterException("Fatal error while trying to parse xml from " + getInputName()); } } *************** *** 1906,1910 **** public URL getURLForGene(String gene) { ! // This CGI actually does a redirect to the relevant XML String query = "http://www.fruitfly.org:90/cgi-bin/annot/which-xml.pl?namesearch=" + gene; try { --- 1972,1977 ---- public URL getURLForGene(String gene) { ! // This CGI actually does a redirect to the relevant XML, so the URL we return here ! // will yield the XML when opened. String query = "http://www.fruitfly.org:90/cgi-bin/annot/which-xml.pl?namesearch=" + gene; try { *************** *** 1916,1919 **** --- 1983,2021 ---- return(null); } + fireProgressEvent(new ProgressEvent(this, new Double(12.0), + "Searching for location of " + gene + "...")); + return(url); + } + + public URL getURLForBand(String band) { + // Returns the URL for the xml of the FIRST scaffold in the requested band + String query = "http://www.fruitfly.org:90/cgi-bin/annot/which-xml.pl?band=" + band; + try { + this.url = new URL(query); + } catch ( Exception ex ) { + System.err.println("caught exception creating URL " + query); + System.out.println(ex.getMessage()); + ex.printStackTrace(); + return(null); + } + fireProgressEvent(new ProgressEvent(this, new Double(10.0), + "Searching for FIRST scaffold at cytological location " + band + "...")); + return(url); + } + + // ! Proof-of-concept method gets the URL for the XML for the scaffold that has the + // best blast hit to the given sequence (uses the fruitfly blast server) + public URL getURLForSequence(String seq) { + String query = "http://www.fruitfly.org:90/cgi-bin/annot/which-xml.pl?sequence=" + seq; + try { + this.url = new URL(query); + } catch ( Exception ex ) { + System.err.println("caught exception creating URL " + query); + System.out.println(ex.getMessage()); + ex.printStackTrace(); + return(null); + } + fireProgressEvent(new ProgressEvent(this, new Double(5.0), + "Running BLAST query--please be patient...")); return(url); } |