Skip to content

Commit

Permalink
New: mark up structure with linked positions of proteins not in struc…
Browse files Browse the repository at this point in the history
…ture.
  • Loading branch information
mriffle committed Jul 20, 2020
1 parent 53f91f8 commit 1adec02
Show file tree
Hide file tree
Showing 2 changed files with 693 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
"use strict";

export class StructureMarkupHandler {

constructor() {
this._proteinsMarkedOnStructure = { };
this._lastInsertId = 0;
}

/**
* Get the next id to use
*
* @returns {number}
*/
getNewId() {
this._lastInsertId++;
return this._lastInsertId;
}

/**
* Delete the protein annotation data with the given id
*
* @param id
*/
deleteStructureProteinMarkup({id}) {
delete this._proteinsMarkedOnStructure[id];
}

/**
* Add the given protein annotation data
*
* @param proteinId
* @param start
* @param end
* @param color
*/
addProteinColorAnnotation({proteinId, start, end, color}) {
const newId = this.getNewId();
const structureMarkupObject = {
"proteinId" : proteinId,
"start" : start,
"end" : end,
"color" : color,
"id" : newId
}

this._proteinsMarkedOnStructure[newId] = structureMarkupObject;

console.log(this);
}

/**
* Replace the protein annotation with the given id with the given data
* @param id
* @param proteinId
* @param start
* @param end
* @param color
*/
updateProteinColorAnnotation({id, proteinId, start, end, color}) {
const structureMarkupObject = {
"proteinId" : proteinId,
"start" : start,
"end" : end,
"color" : color,
"id" : id
}

this._proteinsMarkedOnStructure[id] = structureMarkupObject;
}

/**
* Get all the protein color anotation objects in order of id
*
* @returns {[]}
*/
getOrderedProteinColorAnnotations() {

const sortedIds = this.getSortedIds();

let objects = [];

for (const id of sortedIds) {
objects.push(this._proteinsMarkedOnStructure[id]);
}

return objects;
}

/**
* Get all the ids sorted from smallest to largest
*
* @returns {this}
*/
getSortedIds() {
let ids = [];

for (const id of Object.keys(this._proteinsMarkedOnStructure)) {
ids.push(id);
}

ids = ids.sort();
return ids;
}

/**
* Get the data structure to use for storing the state of this object in the URL hash
*
* @returns {[]}
*/
getDataStructureForHash() {
let ds = [];

for(const markup of this.getOrderedProteinColorAnnotations()) {
let item = "";
item += markup.proteinId + "-";
item += markup.start + "-";
item += markup.end + "-";
item += markup.color;

ds.push(item);
}

return ds;
}

/**
* Populate this object with data passed in via the dataObject, expected format is
* ["proteinid-start-end-color", "proteinid-start-end-color", ...]
* @param dataObject
*/
initializeFromJSON(dataObject) {

console.log('dataObject', dataObject);

if(!dataObject) { return; }

for(const stringifiedData of dataObject) {
const fields = stringifiedData.split('-');

const proteinId = fields[0];
const start = parseInt(fields[1]);
const end = parseInt(fields[2]);
const color = fields[3];

this.addProteinColorAnnotation({
proteinId:proteinId,
start:start,
end:end,
color:color
});
}
}

}

0 comments on commit 1adec02

Please sign in to comment.