Skip to content

Commit

Permalink
Shit broken, but all DataReader function calls are looking good tonig…
Browse files Browse the repository at this point in the history
…ht mmm mmm mmm.
  • Loading branch information
dns-mcdaid committed Aug 4, 2016
1 parent e3e5f0e commit 58e492d
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 34 deletions.
18 changes: 18 additions & 0 deletions data/test_data_01.txt
Original file line number Diff line number Diff line change
@@ -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
113 changes: 92 additions & 21 deletions public/javascripts/backend/visGeneServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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;
}
};

Expand All @@ -137,6 +208,7 @@ VisGene.usage = function(){
};
/**
* @param args {String[]}
* @callback {function}
*/
VisGene.main = function(args, callback) {
try {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/data/dataReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
});
});
Expand Down
28 changes: 17 additions & 11 deletions public/javascripts/data/dataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");
}
Expand All @@ -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) {
Expand All @@ -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);
});
},

Expand All @@ -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");
Expand Down Expand Up @@ -179,6 +184,7 @@ DataSource.prototype = {
}
this.reader.readSungear(sungearU);
this.sunSrc = sungearU;
callback();
}
},
/**
Expand Down
3 changes: 2 additions & 1 deletion public/javascripts/data/vpConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 58e492d

Please sign in to comment.