From 58e492d354b91bde3ea22227072e183d4d573014 Mon Sep 17 00:00:00 2001 From: Dennis McDaid Date: Thu, 4 Aug 2016 00:33:55 -0400 Subject: [PATCH] Shit broken, but all DataReader function calls are looking good tonight mmm mmm mmm. --- data/test_data_01.txt | 18 ++++ public/javascripts/backend/visGeneServer.js | 113 ++++++++++++++++---- public/javascripts/data/dataReader.js | 2 +- public/javascripts/data/dataSource.js | 28 +++-- public/javascripts/data/vpConnection.js | 3 +- 5 files changed, 130 insertions(+), 34 deletions(-) create mode 100644 data/test_data_01.txt diff --git a/data/test_data_01.txt b/data/test_data_01.txt new file mode 100644 index 0000000..1983cc2 --- /dev/null +++ b/data/test_data_01.txt @@ -0,0 +1,18 @@ +List1 | List2 | gene +1 | 0 | At1g01050 +1 | 0 | At1g01450 +1 | 0 | At1g01460 +1 | 0 | At1g01510 +1 | 0 | At1g01560 +1 | 0 | At1g01740 +1 | 0 | At1g02970 +1 | 0 | At1g03030 +1 | 0 | At1g03450 +1 | 0 | At1g03590 +0 | 1 | At1g77760 +0 | 1 | At5g53460 +0 | 1 | At1g05250 +0 | 1 | At3g49960 +0 | 1 | At5g17820 +1 | 1 | At1g03740 +1 | 1 | At1g03920 \ No newline at end of file diff --git a/public/javascripts/backend/visGeneServer.js b/public/javascripts/backend/visGeneServer.js index defb333..8e5ae51 100644 --- a/public/javascripts/backend/visGeneServer.js +++ b/public/javascripts/backend/visGeneServer.js @@ -7,6 +7,7 @@ const DataReader = require('../data/dataReader'); const DataSource = require('../data/dataSource'); const ExternalConnection = require('../data/externalConnection'); const VPConnection = require('../data/vpConnection'); +const ParseException = require('../data/parseException'); /** * @param u {URL} @@ -71,17 +72,18 @@ VisGene.prototype = { init : function(callback) { var vpU = null; try { - vpU = url.format("./index.html?sungearU="); + // TODO: Don't hardcode in production + vpU = url.parse("./index.html?data_url=test_data/test_data_01.txt"); this.extAttrib = VPConnection.makeAttributes(vpU); } catch (e) { - console.error("old-style VP connection failed, trying generic external connection (exception follows)"); - console.error(e.message); + console.log("old-style VP connection failed, trying generic external connection (exception follows)"); + console.log(e.message); if (vpU !== null) { try { this.extAttrib = ExternalConnection.makeExportAttributes(vpU); } catch (e2) { - console.error("external connection failed, resorting to load menu (exception follows)"); - console.error(e2.message); + console.log("external connection failed, resorting to load menu (exception follows)"); + console.log(e2.message); } } } @@ -94,28 +96,97 @@ VisGene.prototype = { this.dataDir += "/"; } this.dataU = DataReader.makeURL(this.base, this.dataDir); - console.log(this.dataU); - - var potato = function(callback) { - DataReader.testRequest(function() { - callback(); - }); - callback(); - }; // prepare data source - //this.src = new DataSource(this.dataU); + this.src = new DataSource(this.dataU); var exp = new ExperimentList(url.resolve(this.dataU, "exper.txt"), url.resolve(this.dataU, "species.txt"), this.dataU, function() { this.exp = exp; - potato(callback); + this.run(callback); }.bind(this)); }, - run : function() { + run : function(callback) { if (this.extAttrib !== null && this.extAttrib.get("sungearU") !== null) { - this.src.setAttributes(this.extAttrib, this.dataU); - this.openFile(); + this.src.setAttributes(this.extAttrib, this.dataU, function() { + this.openFile(this.extAttrib, function() { + callback(); + }); + }.bind(this)); + + } + }, + + openFile : function(attrib, callback) { + console.log("data file: " + attrib.get("sungearU")); + // var status = new StatusDialog(f, this); + var t = new LoadThread(attrib); + t.run(this, function() { + if (t.getException() !== null) { + console.log(t.getException()); + } else { + var iL = attrib.get("itemsLabel", "items"); + var cL = attrib.get("categoriesLabel", "categories"); + // Set titles for geneF, geneM, goF, and goM + var r = this.src.getReader(); + if (this.showWarning && r.missingGenes.size() + r.dupGenes.size() > 0) { + var msg = "There are inconsistencies in this data file:"; + if (r.missingGenes.size() > 0) { + msg += "\n" + r.missingGenes.size() + " input " + iL + " unkown to Sungear have been ignored."; + } + if (r.dupGenes.size() > 0) { + msg += "\n" + r.dupGenes.size() + " " + iL + " duplicated in the input file; only the first occurence of each has been used."; + } + msg += "\nThis will not prevent Sungear from running, but you may want to resolve these issues."; + msg += "\nSee Help | File Info for details about the " + iL + " involved."; + console.log(msg); + } + } + callback(); + }.bind(this)); + } +}; + +/** + * Experiment and master data load thread to separate the load + * operation from the main GUI thread. + * @author RajahBimmy + */ +/** + * Loads an experiment and, if necessary, master data, giving + * load status updates. + * @param u URL of the experiment file to load + * @param status dialog for status updates + */ +function LoadThread(attrib) { + this.attrib = attrib; + this.ex = null; + this.status = null; +} + +LoadThread.prototype = { + constructor : LoadThread, + run : function(parent, callback) { + try { + console.log("Preparing Sungear Display"); + parent.src.set(this.attrib, this.status, function() { + console.log("done!"); + }); + } catch (oo) { + if (typeof oo !== 'ParseException') { + console.log("Out of memory?"); + // this.status.setModal(false); + //parent.src.getReader().clear(); + this.ex = new ParseException("Out of memory"); + } else { + this.ex = oo; + } } + // this.status.setVisible(false); + // this.status.dispose(); + return; + }, + getException : function() { + return this.ex; } }; @@ -137,6 +208,7 @@ VisGene.usage = function(){ }; /** * @param args {String[]} + * @callback {function} */ VisGene.main = function(args, callback) { try { @@ -172,9 +244,8 @@ VisGene.main = function(args, callback) { for (var j = i; j < args.length; j++) { plugin.push(args[j]); } - var myUrl = url.format("./"); - console.log(myUrl); - var vis = new VisGene(myUrl, warn, plugin, dataDir); + var localUrl = url.format("./"); + var vis = new VisGene(localUrl, warn, plugin, dataDir); vis.init(function() { console.log("Made it back to vis init!"); callback(vis); diff --git a/public/javascripts/data/dataReader.js b/public/javascripts/data/dataReader.js index f9ec340..970dae0 100755 --- a/public/javascripts/data/dataReader.js +++ b/public/javascripts/data/dataReader.js @@ -431,7 +431,7 @@ DataReader.readURL = function(u, callback) { // Print only read bytes to avoid junk. if (bytes > 0) { - callback(buf.slice(0, bytes)); + callback(buf.slice(0, bytes).toString()); } }); }); diff --git a/public/javascripts/data/dataSource.js b/public/javascripts/data/dataSource.js index 3956351..665cad0 100644 --- a/public/javascripts/data/dataSource.js +++ b/public/javascripts/data/dataSource.js @@ -60,9 +60,11 @@ DataSource.prototype = { * @throws IOException on low-level file read and file not found errors * @throws ParseException on Sungear-specific file format errors */ - setAttributes : function(attrib, base) { - this.checkAttributes(attrib, base); - this.attrib = attrib; + setAttributes : function(attrib, base, callback) { + this.checkAttributes(attrib, base, function (response) { + this.attrib = response; + callback(); + }); }, /** * Get the attributes object. @@ -79,7 +81,7 @@ DataSource.prototype = { * @throws IOException if a file cannot be read, or a file with no default location cannot be read * @throws ParseException if a file format issue is encountered */ - checkAttributes : function(attrib, base) { + checkAttributes : function(attrib, base, callback) { if (attrib.get("sungearU") === null) { throw new ParseException("sungear file not specified"); } @@ -95,6 +97,7 @@ DataSource.prototype = { speciesFile = "species.txt"; } var list = new SpeciesList(DataReader.makeURL(base, speciesFile), base); + console.log("List: " + list); sp = list.getSpecies(sn); // if there's a species file, assume we're dealing with gene data if (attrib.get("itemsLabel") === null) { @@ -106,17 +109,18 @@ DataSource.prototype = { } // the check basic attribs if (attrib.get("geneU") == null) { - attrib.put("geneU", (sp !== null) ? sp.geneU : new URL(DataSource.GENE_DEFAULT, base)); + attrib.put("geneU", (sp !== null) ? sp.geneU : DataReader.makeURL(base, DataSource.GENE_DEFAULT)); } if (attrib.get("listU") == null) { - attrib.put("listU", (sp !== null) ? sp.listU : new URL(DataSource.LIST_DEFAULT, base)); + attrib.put("listU", (sp !== null) ? sp.listU : DataReader.makeURL(base, DataSource.LIST_DEFAULT)); } if (attrib.get("hierU") == null) { - attrib.put("hierU", (sp !== null) ? sp.hierU : new URL(DataSource.HIER_DEFAULT, base)); + attrib.put("hierU", (sp !== null) ? sp.hierU : DataReader.makeURL(base, DataSource.HIER_DEFAULT)); } if (attrib.get("assocU") == null) { - attrib.put("assocU", (sp !== null) ? sp.assocU : new URL(DataSource.ASSOC_DEFAULT, base)); + attrib.put("assocU", (sp !== null) ? sp.assocU : DataReader.makeURL(base, DataSource.ASSOC_DEFAULT)); } + callback(attrib); }); }, @@ -135,10 +139,11 @@ DataSource.prototype = { * @throws IOException on low-level file errors * @throws ParseException on Sungear-specific file format issues */ - set : function(attrib, status) { - if (typeof status === 'undefined') { - this.set(attrib, null); + set : function(attrib, status, callback) { + if (typeof callback === 'undefined') { + this.set(attrib, null, status); } else { + console.log("MADE IT TO SET: " + attrib); var geneU = attrib.get("geneU"); var listU = attrib.get("listU"); var hierU = attrib.get("hierU"); @@ -179,6 +184,7 @@ DataSource.prototype = { } this.reader.readSungear(sungearU); this.sunSrc = sungearU; + callback(); } }, /** diff --git a/public/javascripts/data/vpConnection.js b/public/javascripts/data/vpConnection.js index cd7604d..14a642b 100644 --- a/public/javascripts/data/vpConnection.js +++ b/public/javascripts/data/vpConnection.js @@ -6,11 +6,12 @@ const ParseException = require('./parseException'); function makeAttributes(doc) { var queryString = doc.query; + console.log(queryString); if (queryString === null || typeof queryString === 'undefined') { throw new ParseException("no query data"); } var attrib = new Attributes(queryString); - if (attrib.get("session_id") === null) { + if (attrib.get("session_id") === null || typeof attrib.get("session_id") === 'undefined') { throw new ParseException("missing required attribute: session_id"); } attrib.put("export_session_id", attrib.get("session_id"));