Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoFold fix #37

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ to display.
Below is an example of a simple web page which uses a `FornaContainer` to show
a simple RNA molecule:

![blah blah](https://raw.githubusercontent.com/pkerpedjiev/fornac/develop/doc/img/forna-container-screenshot.png "An example of the FornaContainer")
<img src="./doc/img/forna-container-screenshot.png" width="150">

The code for creating this web page is rather straightforward. After importing
some necessary javascript files, we create a container using `new
Expand Down Expand Up @@ -44,7 +44,7 @@ This after the RNA container.

Display two cofolded sequences using the format of [RNAcofold](http://rna.tbi.univie.ac.at/cgi-bin/RNAcofold.cgi):

![Cofolded sequences](https://raw.githubusercontent.com/pkerpedjiev/fornac/master/doc/img/cofold_example.png "An example of cofolded sequences displayed using the FornaContainer")
<img src="./doc/img/cofold_example.png" width="150">

```javascript
var container = new fornac.FornaContainer("#cofold_ss",
Expand Down Expand Up @@ -91,7 +91,7 @@ This only makes sense in connection with the `animation` argument. If it's
true, the external loops will be arranged in a nice circle. If false, they will
be allowed to flop around as the force layout dictates:

<img src="https://github.com/pkerpedjiev/fornac/blob/master/doc/img/uncircularized_exterior.png" width=200 align=center />
<img src="./doc/img/uncircularized_exterior.png" width="150">

### labelInterval [default=10]

Expand Down
8 changes: 8 additions & 0 deletions dist/02188894d5236b1517df3210b79c2a7f.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dist/fornac.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/fornac.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/fornac.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
2 changes: 1 addition & 1 deletion dist/fornac.js.map

Large diffs are not rendered by default.

Binary file modified doc/img/cofold_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/uncircularized_exterior.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h4>This is a custom-colored RNA</h4>

function cofoldContainer() {
var container = new fornac.FornaContainer("#cofold_ss",
{'animation': true, 'zoomable': false, 'initialSize':[500,300]});
{'animation': false, 'zoomable': false, 'initialSize':[500,300]});

var options = {'structure': '..((((...))))...((...((...((..&............))...))...))..',
'sequence': 'ACGAUCAGAGAUCAGAGCAUACGACAGCAG&ACGAAAAAAAGAGCAUACGACAGCAG'
Expand Down
110 changes: 109 additions & 1 deletion src/fornac.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,107 @@ export function FornaContainer(element, passedOptions = {}) {
// add them back to the plot
}

let splitMultiStrand = function(rna) {
// split a multi strand RNA into its individual strands
// get the position of the '&' character in the dotbracket string
let breakPositions = [];
for (let i = 0; i < rna.dotbracket.length; i++) {
if (rna.dotbracket[i] == '&') {
breakPositions.push(i);
}
}

let toRemove = [];
// collect all the base pairs that are between split strands
for (let i = 0; i < rna.links.length; i++) {
let link = rna.links[i];

if (link.linkType != 'basepair')
continue; // only consider base pairs

for (let j = 0; j < breakPositions.length; j++) {
let node = rna.nodes[breakPositions[j]]; // take the split node
// take the two links that connect the split node
let linkSource = rna.links.filter(link => link.source === node)[0];
let linkTarget = rna.links.filter(link => link.target === node)[0];
if (link.source.num <= linkSource.source.num && link.target.num >= linkTarget.target.num) {
console.log('crossing basepair', link);
link.breakFrom = 0;
// find the strand that the source is in
for (let k = 0; k < breakPositions.length - 1; k++) {
if (link.source.num > breakPositions[k] && link.source.num < breakPositions[k+1])
link.breakFrom = k+1;
}
// find the strand that the target is in
link.breakTo = j+1;
link.from = link.source.num;
// find the position of the source in the strand
if (link.breakFrom > 0) link.from -= breakPositions[link.breakFrom-1] + link.breakFrom;
// find the position of the target in the strand
link.to = link.target.num - linkTarget.target.num;
toRemove.push(link);
}
}
}


// Remove all base pairs that are between these two nodes and add them as extra
// links
console.log('toRemove:', toRemove);
let sequences = rna.seq.split('&');

// remove the base pairs
for (let i = 0; i < toRemove.length; i++) {
rna.pairtable[toRemove[i].source.num] = 0;
rna.pairtable[toRemove[i].target.num] = 0;
}

// extract the dotbracket string of the rna
// cut it at the position of this backbone bond
console.log('sequences:', sequences);

let rnaDotBracket = rnaUtilities.pairtableToDotbracket(rna.pairtable);
let dotbrackets = []; // array to hold the dotbracket strings of the individual strands
let rnaPositions = rna.getPositions('nucleotide') // get the nucleotide positions, cut them at the positions of the backbone bond
let positions = [];
let rnaUids = rna.getUids();
let uids = [];
let lastBreak = 0; // the position of the last break
for (let i = 0; i <= breakPositions.length; i++) {
// cut the dotbracket
dotbrackets.push(rnaDotBracket.slice(lastBreak, breakPositions[i]));
// add the positions
positions.push(rnaPositions.slice(lastBreak, breakPositions[i]));
// add the uids
uids.push(rnaUids.slice(lastBreak, breakPositions[i]));
lastBreak = breakPositions[i] + 1;
}

console.log('positions:', positions);

delete self.rnas[rna.uid];
let newRnas = [];
for (let i = 0; i < sequences.length; i++) {
let newRna = self.addRNA(dotbrackets[i], { 'sequence': sequences[i],
'positions': positions[i],
'uids': uids[i] });
newRnas.push(newRna);
}
// add the extra links
for (let i = 0; i < toRemove.length; i++) {
console.log('toRemove[i]', toRemove[i]);
self.extraLinks.push(
{'source': newRnas[toRemove[i].breakFrom].nodes[toRemove[i].from-1],
'target': newRnas[toRemove[i].breakTo].nodes[toRemove[i].to-1],
'value': 1,
'uid': slugid.nice(),
'linkType': 'intermolecule'});
recalculateGraph();
self.update();
}
console.log('self.extraLinks:', self.extraLinks);
}

var removeLink = function(d) {
// remove a link between two nodes
let index = self.graph.links.indexOf(d);
Expand Down Expand Up @@ -1907,6 +2008,13 @@ export function FornaContainer(element, passedOptions = {}) {
else
self.addRNAJSON(rnaJson, {centerView: passedOptions.centerView});

// if the structure containes multistrands, let's split before the '&'
console.log('structure:', structure);
if (structure.indexOf('&') !== -1 && structure != '&' && structure.indexOf('&') !== 0) {
console.log('splitting multistrand');
splitMultiStrand(rnaJson);
return;
};
return rnaJson;
};

Expand Down Expand Up @@ -2126,7 +2234,7 @@ export function FornaContainer(element, passedOptions = {}) {
if (node.nodeType != 'nucleotide')
continue;

console.log('node:', node);
// console.log('node:', node);
nodeIdxs[node.uid] = currIdx;
currIdx += 1;

Expand Down
Loading