diff --git a/js/cells/DNABrickCell.js b/js/cells/DNABrickCell.js index 273e6c9330bc9467fb9e0ecc491031c0142678c3..fda51dd6defb2369f1bba9e8837518ea6e70429e 100644 --- a/js/cells/DNABrickCell.js +++ b/js/cells/DNABrickCell.js @@ -25,6 +25,22 @@ define(['gikCell'], function(GIKCell){ return "unassigned"; }; + DNABrickCell.prototype.getSequence = function(){ + if (this._sequence) return this._sequence; + var sequence = ""; + if (!this.parts || this.parts.length < 16) { + console.warn("need to calc nucleotides for this cell"); + return sequence; + } + for (var i=0;i<16;i++){ + var nucleotide = this.parts[i].getNucleotide(); + if (nucleotide) sequence += nucleotide; + else console.warn("no nucleotide found for this part"); + } + this._sequence = sequence; + return sequence; + }; + return DNABrickCell; }); \ No newline at end of file diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js index b81dab5da187e7822777f6901434f04c08cecb01..f4ef144423612d26fe608eb431237861a3e1fdec 100644 --- a/js/cells/GIKCell.js +++ b/js/cells/GIKCell.js @@ -51,10 +51,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cubeCell'], var index = self.getLatticeIndex(); if (parent.cells[index.x][index.y][index.z+1]) var topNeighbor = parent.cells[index.x][index.y][index.z+1]; if (parent.cells[index.x][index.y][index.z-1]) var bottomNeighbor = parent.cells[index.x][index.y][index.z-1]; + var seq = this._sequence; for (var i=0;i<16;i++){ var nucleotide = null; - if (topNeighbor && i<8) nucleotide = self.getCompliment(topNeighbor.getNucleotideAtIndex(i+8)); - if (bottomNeighbor && i>7) nucleotide = self.getCompliment(bottomNeighbor.getNucleotideAtIndex(i-8)); + if (seq === undefined){ + if (topNeighbor && i<8) nucleotide = self.getCompliment(topNeighbor.getNucleotideAtIndex(i+8)); + if (bottomNeighbor && i>7) nucleotide = self.getCompliment(bottomNeighbor.getNucleotideAtIndex(i-8)); + } else nucleotide = seq[i]; parts.push(new PartSubclass(self.index.x, self, { nuclType: nucleotide, vertIndex: i, diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index e1dbc543bb985453aeec028ae5f3bc0c1eeda3a1..14988e2e28d900209a3f1f548fd629ebbc350dbc 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -90,5 +90,15 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', this.length = null; }; + + GIKSuperCell.prototype.getSequence = function(){//todo this goes somewhere else + var sequence = ""; + for (var i=0;i<this.length;i++){ + if (i>0) sequence += "-";//linker + sequence += this.cells[i][0][0].getSequence(); + } + return sequence; + }; + return GIKSuperCell; }); \ No newline at end of file diff --git a/js/dnaExport/dnaExport.js b/js/dnaExport/dnaExport.js new file mode 100644 index 0000000000000000000000000000000000000000..fd5dbfd1a815726e0c58c8638f75de1a314c2dd7 --- /dev/null +++ b/js/dnaExport/dnaExport.js @@ -0,0 +1,51 @@ +/** + * Created by aghassaei on 9/15/15. + */ + + +define(['underscore', 'backbone', 'lattice', 'appState', 'fileSaver'], + function(_, Backbone, lattice, appState, fileSaver){ + + var DNAExport = Backbone.Model.extend({ + + defaults: { + sequence32: [], + sequence16: [] + }, + + + initialize: function(){ + + this.listenTo(appState, "change:currentNav", this._navChanged); + + this.generateSequences(); + }, + + _navChanged: function(){ + if (appState.get("currentNav") == "navDNAAssemble") this.generateSequences(); + }, + + generateSequences: function(){ + var sequences32 = []; + var sequences16 = []; + lattice.loopCells(function(cell, x, y, z){ + if (!cell) return; + if (cell.getLength() == 2) sequences32.push(cell.getSequence()); + else if (cell.getLength() == 1) sequences16.push(cell.getSequence()); + else console.warn("unexpected cell of length " + cell.getLength()); + }); + this.set("sequence32", sequences32); + this.set("sequence16", sequences16); + }, + + save: function(){ + var data = this.toJSON(); + fileSaver.saveSequences(data); + } + + }); + + + return new DNAExport(); + +}); \ No newline at end of file diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index 65db63519f17de6aa971e0ad80567402dfefc11f..378cdcbaba6cfefb423511a2896c5949a1245a14 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -504,6 +504,10 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }); }, + loopCells: function(callback){ + this._loopCells(this.sparseCells, callback); + }, + _loopCells: function(cells, callback){ for (var x=0;x<cells.length;x++){ for (var y=0;y<cells[0].length;y++){ diff --git a/js/main.js b/js/main.js index c73073d12872c0b8510679e21f6be78f2ba68b36..183b62a71c3607db82a176df2e2341d2dbe12b2c 100644 --- a/js/main.js +++ b/js/main.js @@ -35,6 +35,7 @@ require.config({ globals: 'models/Globals', appState: 'models/AppState', fileSaver: 'models/FileSaver', + dnaExport: 'dnaExport/dnaExport', //communication socketio: '../dependencies/socket.io-1.3.5', diff --git a/js/menus/DNAExportMenuView.js b/js/menus/DNAExportMenuView.js index be46f0b904453903a61937fb0a746bce0f0d83b1..2581d0dd49c13e895f14b9f88b5691cdad49ee00 100644 --- a/js/menus/DNAExportMenuView.js +++ b/js/menus/DNAExportMenuView.js @@ -3,21 +3,27 @@ */ -define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'text!menus/templates/DNAExportMenuView.html'], - function($, _, MenuParentView, plist, lattice, template){ +define(['jquery', 'underscore', 'menuParent', 'dnaExport', 'text!menus/templates/DNAExportMenuView.html'], + function($, _, MenuParentView, dnaExport, template){ return MenuParentView.extend({ events: { + "click #saveSequences": "_saveToFile" }, _initialize: function(){ }, + _saveToFile: function(e){ + e.preventDefault(); + dnaExport.save(); + }, + _makeTemplateJSON: function(){ - return {}; + return dnaExport.toJSON(); }, template: _.template(template) diff --git a/js/menus/templates/DNAExportMenuView.html b/js/menus/templates/DNAExportMenuView.html index 206addaa25c733eda9ea53dd417d8130dc91abef..fc06e73547875546725829f777d096d9287032b3 100644 --- a/js/menus/templates/DNAExportMenuView.html +++ b/js/menus/templates/DNAExportMenuView.html @@ -1 +1,9 @@ -export sequences \ No newline at end of file +32bp sequences:<br/> +<% _.each(sequence32, function(seq){ %> + <%= seq %><br/> +<% }); %><br/> +16bp sequences:<br/> +<% _.each(sequence16, function(seq){ %> + <%= seq %><br/> +<% }); %><br/> +<a href="#" id="saveSequences" class="btn btn-block btn-lg btn-success">Save to File</a><br/> diff --git a/js/models/FileSaver.js b/js/models/FileSaver.js index 2902c199c4a5bf895e82564384cba205c0391c79..8283b87abec01f11c2ca175bde7f2bcbd27f1c08 100644 --- a/js/models/FileSaver.js +++ b/js/models/FileSaver.js @@ -5,11 +5,15 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWrapper'], function(_, saveAs, lattice, materials, ribbon, menuWrapper){ - function _saveFile(data, name, extension){ + function _saveFile(data, name, extension, noQuotes){ // require(['jsonFn'], function(JSONfn){ // console.log(data.toString()); var jsonString = JSON.stringify(data, null, '\t'); + if (noQuotes){ + jsonString = jsonString.replace(/"/g, ''); + } + var blob = new Blob([jsonString], {type: "text/plain;charset=utf-8"}); saveAs(blob, name + extension); if (data.assembler){ @@ -54,6 +58,10 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra _saveFile(data, name, ".user"); } + function saveSequences(seqArray, name){ + _saveFile(seqArray, name || "seqs", ".txt", true); + } + function saveMaterial(id, material){ var data = {materials:{}}; data.materials[id] = material || _getMaterialDataToSave(id); @@ -139,7 +147,8 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra saveMachineConfig: saveMachineConfig, // saveAssembler: saveAssembler, // saveUser: saveUser, - loadFile: loadFile + loadFile: loadFile, // loadUser: loadUser + saveSequences: saveSequences } }); \ No newline at end of file