Script Documentation: Difference between revisions

From Eterna Wiki

(Corrected getPairmap example)
(Update formatting)
 
(4 intermediate revisions by 3 users not shown)
Line 5: Line 5:
<div style="right: 50%; float: left; position: relative;">
<div style="right: 50%; float: left; position: relative;">
<div style="width: 46%; left: 52%; float: left; position: relative; padding: 0 0 1em 0; overflow: hidden;">
<div style="width: 46%; left: 52%; float: left; position: relative; padding: 0 0 1em 0; overflow: hidden;">
<p class="script-section-title">== Pervasives ==</p>
== Pervasives==
<p class="script-functions">&nbsp;</p>
<p class="script-functions">&nbsp;</p>
<p class="script-title">=== out(text) ===</p>
===out(text)===
<p class="script-description">display text in result textarea</p>
<p class="script-description">display text in result textarea</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p class="script-title">=== outln(text) ===</p>
===outln(text)===
<p class="script-description">display text in result textarea with newline</p>
<p class="script-description">display text in result textarea with newline</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p class="script-functions">=== clear() ===</p>
===clear()===
<p class="script-description">clear result textarea</p>
<p class="script-description">clear result textarea</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>== Library functions ==</p>
==Library functions==
<p class="script-functions">=== Lib.bases ===</p>
===Lib.bases ===
<p class="script-description">"AGCU"</p>
<p class="script-description">"AGCU"</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p class="script-functions">=== Lib.fold(sequence) ===</p>
===Lib.fold(sequence)===
<p class="script-description">return folded structure with sequence</p>
<p class="script-description">return folded structure with sequence</p>
<p>ex) Lib.fold("GGGGCCCC") = "((....))";</p>
<p>ex) Lib.fold("GGGGCCCC") = "((....))";</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== Lib.energyOfStruct(sequence, structure) ===</p>
===Lib.energyOfStruct(sequence, structure)===
<p class="script-description">return energy of structure</p>
<p class="script-description">return energy of structure</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== Lib.EternaScript(script id) ===</p>
===Lib.EternaScript(script id)===
<p class="script-description">return other user's script</p>
<p class="script-description">return other user's script</p>
<p>ex) var func = Lib.EternaScript(script_id);</p>
<p>ex) var func = Lib.EternaScript(script_id);</p>
<p>ex) func(parameters);</p>
<p>ex) func(parameters);</p>
<p><em>Passing parameters between scripts is a little tricky. &nbsp;</em></p>
<p><em>See&nbsp;http://www.eternagame.org/web/script/8074717/ </em></p>
<p><em>and&nbsp;http://www.eternagame.org/web/script/8074800/</em></p>
<p><em>for an example.</em></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== Lib.getStructure(puzzle id) ===</p>
=== Lib.getStructure(puzzle id)===
<p class="script-description">return structure of puzzle</p>
<p class="script-description">return structure of puzzle</p>
<p>ex) Lib.getStructure(1001759)</p>
<p>ex) Lib.getStructure(1001759)</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== Lib.replace(sequence, index, target) ===</p>
===Lib.replace(sequence, index, target)===
<p class="script-description">return sequence which character at index in sequence replaced to target</p>
<p class="script-description">return sequence which character at index in sequence replaced to target</p>
<p>ex) Lib.replace("AGCU", 2, "A") = "AGAU";</p>
<p>ex) Lib.replace("AGCU", 2, "A") = "AGAU";</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== Lib.nextSequence(sequence) ===</p>
===Lib.nextSequence(sequence) ===
<p class="script-description">return next sequence of sequence in the order of default bases</p>
<p class="script-description">return next sequence of sequence in the order of default bases</p>
<p>ex) Lib.nextSequence("AAAA") = "GAAA";</p>
<p>ex) Lib.nextSequence("AAAA") = "GAAA";</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== Lib.nextSequenceWithBases(sequence, bases) ===</p>
===Lib.nextSequenceWithBases(sequence, bases)===
<p class="script-description">return next sequence of sequence in the order of bases</p>
<p class="script-description">return next sequence of sequence in the order of bases</p>
<p>ex) Lib.nextSequenceWithBases("UUUU", "UCGA") = "CUUU";</p>
<p>ex) Lib.nextSequenceWithBases("UUUU", "UCGA") = "CUUU";</p>
<p>ex) Lib.nextSequenceWithBases("AUAA", "UCGA") = "UCAA";</p>
<p>ex) Lib.nextSequenceWithBases("AUAA", "UCGA") = "UCAA";</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== Lib.random(from, to) ===</p>
===Lib.random(from, to)===
<p class="script-description">return random number between from and to</p>
<p class="script-description">return random number between from and to</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p class="script-functions">=== Lib.randomSequence(size) ===</p>
===Lib.randomSequence(size)===
<p class="script-description">return random sequence with length of size</p>
<p class="script-description">return random sequence with length of size</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== Lib.map(function, sequence) ===</p>
===Lib.map(function, sequence)===
<p class="script-description">applies function to each sequence bases</p>
<p class="script-description">applies function to each sequence bases</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p class="script-functions">=== Lib.filter(function, sequence) ===</p>
===Lib.filter(function, sequence)===
<p class="script-description">return sequences only satisfy the function</p>
<p class="script-description">return sequences only satisfy the function</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p class="script-functions">=== Lib.splitDefault(structure) ===</p>
===Lib.splitDefault(structure)===
<p class="script-description">split structure into a structure array</p>
<p class="script-description">split structure into a structure array</p>
<p>ex) Lib.splitDefault("((..))") = ["((", "..", "))"];</p>
<p>ex) Lib.splitDefault("((..))") = ["((", "..", "))"];</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== Lib.join(array) ===</p>
===Lib.join(array)===
<p class="script-description">join array with each element to sequence</p>
<p class="script-description">join array with each element to sequence</p>
<p>ex) Lib.join(Lib.split("((..))")) = "((..))";</p>
<p>ex) Lib.join(Lib.split("((..))")) = "((..))";</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== Lib.distance(source structure, destination structure) ===</p>
===Lib.distance(source structure, destination structure)===
<p class="script-description">return differences between source structure and destination structure</p>
<p class="script-description">return differences between source structure and destination structure</p>
<p>if same then 0 else +1</p>
<p>if same then 0 else +1</p>
Line 76: Line 80:
<p>ex) Lib.distance("(((())))", "(())") = -1</p>
<p>ex) Lib.distance("(((())))", "(())") = -1</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== Lib.distanceCustom(function, source structure, destination structure) ===</p>
===Lib.distanceCustom(function, source structure, destination structure)===
<p class="script-description">return differences between source structure and destination structure with custom rule</p>
<p class="script-description">return differences between source structure and destination structure with custom rule</p>
<p>ex) Lib.distanceCustom(function(index){ ... }, source, dest);</p>
<p>ex) Lib.distanceCustom(function(index){ ... }, source, dest);</p>
Line 82: Line 86:
</div>
</div>
<div style="width: 46%; left: 56%; float: left; position: relative; padding: 0 0 1em 0; overflow: hidden;">
<div style="width: 46%; left: 56%; float: left; position: relative; padding: 0 0 1em 0; overflow: hidden;">
<p>== Class RNA ==</p>
==Class RNA==
<p><a href="http://kws.eternadev.org/web/script/">example code</a></p>
<p>[http://kws.eternadev.org/web/script/ example code]</p>
<p class="script-functions">&nbsp;</p>
<p class="script-functions">&nbsp;</p>
<p class="script-title">=== getPairmap(structure) ===</p>
===getPairmap(structure)===
<p class="script-description">return the array of pair information</p>
<p class="script-description">return the array of pair information</p>
<p>ex) getPairmap("((...))") = [6,5,,,,1,0]</p>
<p>ex) getPairmap("((...))") = [6,5,,,,1,0]</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== getStructure() ===</p>
===getStructure() ===
<p class="script-description">return structure</p>
<p class="script-description">return structure</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== getRootElement() ===</p>
===getRootElement()===
<p class="script-description">return root RNAElement class of rna object</p>
<p class="script-description">return root RNAElement class of rna object</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== map() ===</p>
===map()===
<p class="script-description">applies function to all RNAElement</p>
<p class="script-description">applies function to all RNAElement</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>== Class RNAElement ==</p>
==Class RNAElement==
<p class="script-functions">&nbsp;</p>
<p class="script-functions">&nbsp;</p>
<p class="script-title">=== getParent() ===</p>
===getParent()===
<p class="script-description">return the parent RNAElement class</p>
<p class="script-description">return the parent RNAElement class</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== getChilds() ===</p>
=== getChilds()===
<p class="script-description">return the child RNAElement class array</p>
<p class="script-description">return the child RNAElement class array</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== getElements() ===</p>
===getElements() ===
<p class="script-description">return the array of structure and index JSON objects</p>
<p class="script-description">return the array of structure and index JSON objects</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== isPaired() ===</p>
===isPaired()===
<p class="script-description">return boolean whether the stack element is paired or not</p>
<p class="script-description">return boolean whether the stack element is paired or not</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== getBaseType() ===</p>
===getBaseType()===
<p class="script-description">return RNAElement.Stack or RNAElement.Loop if the element is stack or loop</p>
<p class="script-description">return RNAElement.Stack or RNAElement.Loop if the element is stack or loop</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== getType() ===</p>
===getType()===
<p class="script-description">return RNAElement.Hairpin, RNAElement.Bulge, RNAElement.Internal, RNAElement.Multiloop or RNAElement.Dangling if the element is hairpin, bulge, internal, multiloop or dangling</p>
<p class="script-description">return RNAElement.Hairpin, RNAElement.Bulge, RNAElement.Internal, RNAElement.Multiloop or RNAElement.Dangling if the element is hairpin, bulge, internal, multiloop or dangling</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== getIndices() ===</p>
===getIndices()===
<p class="script-description">return the array of indices</p>
<p class="script-description">return the array of indices</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== isStack() / isLoop() / isHairpin() / isBulge() /<br /> isInternal() / isMultiloop() / isDangling() ===</p>
===isStack() / isLoop() / isHairpin() / isBulge() / isInternal() / isMultiloop() / isDangling()===
<p class="script-description">return boolean wheter the element is stack, loop, hairpin, bulge, internal, multiloop or dangling</p>
<p class="script-description">return boolean wheter the element is stack, loop, hairpin, bulge, internal, multiloop or dangling</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>=== getSegmentCount() ===</p>
===getSegmentCount()===
<p class="script-description">return how many structure segments included</p>
<p class="script-description">return how many structure segments included</p>
<p>if the multiloop consists of 2 branches then getSegmentCount() of multiloop returns 2</p>
<p>if the multiloop consists of 2 branches then getSegmentCount() of multiloop returns 2</p>
Line 135: Line 139:
</div>
</div>
<div style="clear: both; float: left; overflow: hidden;">
<div style="clear: both; float: left; overflow: hidden;">
<p>==See Also==</p>
==See Also==
<ul>
<ul>
<li>[[API for Server Data Queries]]</li>
<li>[[API for Server Data Queries]]</li>
<li>There is a beginners guide to the script interface [https://docs.google.com/document/d/1VC94wTuRhNd-FN60ueaBc5mUxBsiIy8UzJzQL6ap3CE/edit?pli=1 here] on google docs.</li>
<li>There is a beginners guide to the script interface [https://docs.google.com/document/d/1VC94wTuRhNd-FN60ueaBc5mUxBsiIy8UzJzQL6ap3CE/edit?pli=1 here] on google docs.</li>
<li>Scripting lectures in [http://eternawiki.org/wiki/index.php5/EteRNA_University EteRNA University]</li>
<li>[https://docs.google.com/document/d/1AVs401fSZVD8FNNgkMQbFcxm_5O6RqpbSAk9o19f6Z8/edit#heading=h.8bg64ampbuz5 HTML Magic - Learn tricks for sharing material] by&nbsp;[[User:Machinelves|Machinelves]] and&nbsp;[[User:Eli Fisker|Eli Fisker]]</li>
</ul>
</ul>
<p>&nbsp;</p>
<p>[[Category:Computational Tools]]</p>
</div>
</div>

Latest revision as of 18:59, 18 June 2022

 

 

Pervasives

 

out(text)

display text in result textarea

 

outln(text)

display text in result textarea with newline

 

clear()

clear result textarea

 

Library functions

Lib.bases

"AGCU"

 

Lib.fold(sequence)

return folded structure with sequence

ex) Lib.fold("GGGGCCCC") = "((....))";

 

Lib.energyOfStruct(sequence, structure)

return energy of structure

 

Lib.EternaScript(script id)

return other user's script

ex) var func = Lib.EternaScript(script_id);

ex) func(parameters);

Passing parameters between scripts is a little tricky.  

See http://www.eternagame.org/web/script/8074717/

and http://www.eternagame.org/web/script/8074800/

for an example.

 

Lib.getStructure(puzzle id)

return structure of puzzle

ex) Lib.getStructure(1001759)

 

Lib.replace(sequence, index, target)

return sequence which character at index in sequence replaced to target

ex) Lib.replace("AGCU", 2, "A") = "AGAU";

 

Lib.nextSequence(sequence)

return next sequence of sequence in the order of default bases

ex) Lib.nextSequence("AAAA") = "GAAA";

 

Lib.nextSequenceWithBases(sequence, bases)

return next sequence of sequence in the order of bases

ex) Lib.nextSequenceWithBases("UUUU", "UCGA") = "CUUU";

ex) Lib.nextSequenceWithBases("AUAA", "UCGA") = "UCAA";

 

Lib.random(from, to)

return random number between from and to

 

Lib.randomSequence(size)

return random sequence with length of size

 

Lib.map(function, sequence)

applies function to each sequence bases

 

Lib.filter(function, sequence)

return sequences only satisfy the function

 

Lib.splitDefault(structure)

split structure into a structure array

ex) Lib.splitDefault("((..))") = ["((", "..", "))"];

 

Lib.join(array)

join array with each element to sequence

ex) Lib.join(Lib.split("((..))")) = "((..))";

 

Lib.distance(source structure, destination structure)

return differences between source structure and destination structure

if same then 0 else +1

if different length then just return -1

ex) Lib.distance("((..))", "((()))") = 2

ex) Lib.distance("(((())))", "(())") = -1

 

Lib.distanceCustom(function, source structure, destination structure)

return differences between source structure and destination structure with custom rule

ex) Lib.distanceCustom(function(index){ ... }, source, dest);

 

Class RNA

example code

 

getPairmap(structure)

return the array of pair information

ex) getPairmap("((...))") = [6,5,,,,1,0]

 

getStructure()

return structure

 

getRootElement()

return root RNAElement class of rna object

 

map()

applies function to all RNAElement

 

Class RNAElement

 

getParent()

return the parent RNAElement class

 

getChilds()

return the child RNAElement class array

 

getElements()

return the array of structure and index JSON objects

 

isPaired()

return boolean whether the stack element is paired or not

 

getBaseType()

return RNAElement.Stack or RNAElement.Loop if the element is stack or loop

 

getType()

return RNAElement.Hairpin, RNAElement.Bulge, RNAElement.Internal, RNAElement.Multiloop or RNAElement.Dangling if the element is hairpin, bulge, internal, multiloop or dangling

 

getIndices()

return the array of indices

 

isStack() / isLoop() / isHairpin() / isBulge() / isInternal() / isMultiloop() / isDangling()

return boolean wheter the element is stack, loop, hairpin, bulge, internal, multiloop or dangling

 

getSegmentCount()

return how many structure segments included

if the multiloop consists of 2 branches then getSegmentCount() of multiloop returns 2

 

Documentation for functions and APIs at the devel stage can be found on Script Documentation (devel)

See Also