Commit 17c2f250 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

sequence is conserved

parent b88c1510
...@@ -25,6 +25,22 @@ define(['gikCell'], function(GIKCell){ ...@@ -25,6 +25,22 @@ define(['gikCell'], function(GIKCell){
return "unassigned"; 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; return DNABrickCell;
}); });
\ No newline at end of file
...@@ -51,10 +51,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cubeCell'], ...@@ -51,10 +51,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cubeCell'],
var index = self.getLatticeIndex(); 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 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]; 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++){ for (var i=0;i<16;i++){
var nucleotide = null; var nucleotide = null;
if (topNeighbor && i<8) nucleotide = self.getCompliment(topNeighbor.getNucleotideAtIndex(i+8)); if (seq === undefined){
if (bottomNeighbor && i>7) nucleotide = self.getCompliment(bottomNeighbor.getNucleotideAtIndex(i-8)); 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, { parts.push(new PartSubclass(self.index.x, self, {
nuclType: nucleotide, nuclType: nucleotide,
vertIndex: i, vertIndex: i,
......
...@@ -90,5 +90,15 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', ...@@ -90,5 +90,15 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell',
this.length = null; 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; return GIKSuperCell;
}); });
\ No newline at end of file
/**
* 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
...@@ -504,6 +504,10 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre ...@@ -504,6 +504,10 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
}); });
}, },
loopCells: function(callback){
this._loopCells(this.sparseCells, callback);
},
_loopCells: function(cells, callback){ _loopCells: function(cells, callback){
for (var x=0;x<cells.length;x++){ for (var x=0;x<cells.length;x++){
for (var y=0;y<cells[0].length;y++){ for (var y=0;y<cells[0].length;y++){
......
...@@ -35,6 +35,7 @@ require.config({ ...@@ -35,6 +35,7 @@ require.config({
globals: 'models/Globals', globals: 'models/Globals',
appState: 'models/AppState', appState: 'models/AppState',
fileSaver: 'models/FileSaver', fileSaver: 'models/FileSaver',
dnaExport: 'dnaExport/dnaExport',
//communication //communication
socketio: '../dependencies/socket.io-1.3.5', socketio: '../dependencies/socket.io-1.3.5',
......
...@@ -3,21 +3,27 @@ ...@@ -3,21 +3,27 @@
*/ */
define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'text!menus/templates/DNAExportMenuView.html'], define(['jquery', 'underscore', 'menuParent', 'dnaExport', 'text!menus/templates/DNAExportMenuView.html'],
function($, _, MenuParentView, plist, lattice, template){ function($, _, MenuParentView, dnaExport, template){
return MenuParentView.extend({ return MenuParentView.extend({
events: { events: {
"click #saveSequences": "_saveToFile"
}, },
_initialize: function(){ _initialize: function(){
}, },
_saveToFile: function(e){
e.preventDefault();
dnaExport.save();
},
_makeTemplateJSON: function(){ _makeTemplateJSON: function(){
return {}; return dnaExport.toJSON();
}, },
template: _.template(template) template: _.template(template)
......
export sequences 32bp sequences:<br/>
\ No newline at end of file <% _.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/>
...@@ -5,11 +5,15 @@ ...@@ -5,11 +5,15 @@
define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWrapper'], function(_, saveAs, lattice, materials, ribbon, menuWrapper){ 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){ // require(['jsonFn'], function(JSONfn){
// console.log(data.toString()); // console.log(data.toString());
var jsonString = JSON.stringify(data, null, '\t'); var jsonString = JSON.stringify(data, null, '\t');
if (noQuotes){
jsonString = jsonString.replace(/"/g, '');
}
var blob = new Blob([jsonString], {type: "text/plain;charset=utf-8"}); var blob = new Blob([jsonString], {type: "text/plain;charset=utf-8"});
saveAs(blob, name + extension); saveAs(blob, name + extension);
if (data.assembler){ if (data.assembler){
...@@ -54,6 +58,10 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra ...@@ -54,6 +58,10 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra
_saveFile(data, name, ".user"); _saveFile(data, name, ".user");
} }
function saveSequences(seqArray, name){
_saveFile(seqArray, name || "seqs", ".txt", true);
}
function saveMaterial(id, material){ function saveMaterial(id, material){
var data = {materials:{}}; var data = {materials:{}};
data.materials[id] = material || _getMaterialDataToSave(id); data.materials[id] = material || _getMaterialDataToSave(id);
...@@ -139,7 +147,8 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra ...@@ -139,7 +147,8 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra
saveMachineConfig: saveMachineConfig, saveMachineConfig: saveMachineConfig,
// saveAssembler: saveAssembler, // saveAssembler: saveAssembler,
// saveUser: saveUser, // saveUser: saveUser,
loadFile: loadFile loadFile: loadFile,
// loadUser: loadUser // loadUser: loadUser
saveSequences: saveSequences
} }
}); });
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment