Currently, I am loading a file, extracting information from it, storing the data in an object, and then adding that object to an array. One of the attributes of the object is a 'sequence': [] key-value pair. After storing a DNA sequence in the 'sequence' value of my object, I am attempting to concatenate all the elements. However, my attempts to achieve this using .join() have been unsuccessful. Here is the code snippet I am working with:
// Checking for File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Success! All File APIs are supported.
} else {
alert('The File APIs are not fully supported in this browser.');
}
var objArray = [];
var obj;
function parse(event) {
// Retrieving the file from an HTML input tag
var file = event.target.files[0];
if(file) {
// Creating a new FileReader
var reader = new FileReader();
// When the reader loads
reader.onload = function(evt) {
// Storing the file contents in a variable
var contentsByLine = evt.target.result.split('\n');
// Notifying the user about the successful file upload
console.log('File ' + file.name + ' was successfully loaded.');
for(var i in contentsByLine){
if(contentsByLine[i][0] == '>'){
obj = {
id: contentsByLine[i],
sequence: [],
lead_trim: 0,
trail_trim: 0
};
objArray.push(obj);
}else{
obj.sequence.push(contentsByLine[i]);
}
// console.log(objArray[i]['sequence']);
}
console.log(objArray)
// Creating a DataView.
var dataView = new Slick.Data.DataView();
// Using the DataView as a data provider for SlickGrid.
var grid = new Slick.Grid("#table", dataView, columns, options);
// Making the grid respond to DataView change events.
dataView.onRowCountChanged.subscribe(function (e, args) {
grid.updateRowCount();
grid.render();
});
dataView.onRowsChanged.subscribe(function (e, args) {
grid.invalidateRows(args.rows);
grid.render();
});
var data = [];
for (var i in objArray){
objArray[i]['sequence'].join();
data.push(objArray[i]);
}
dataView.setItems(data);
dataView.getItems();
//console.log(data);
}
reader.readAsText(file);
} else {
alert('Failed to upload file!');
}
}
document.getElementById('fileItem').addEventListener('change', parse, false);