-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: mark up structure with linked positions of proteins not in struc…
…ture.
- Loading branch information
Showing
2 changed files
with
693 additions
and
18 deletions.
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
..._js/data_pages/project_search_ids_driven_pages/structure_page/structure-markup-handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.