Script Documentation: Difference between revisions

From Eterna Wiki

(Blanked the page)
(Added pointers to samples of passing parameters when using Lib.EternaScript)
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
<p>&nbsp;</p>
<p>__TOC__</p>
<p>&nbsp;</p>
<div style="clear: both; float: left; overflow: hidden;">
<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;">
<p class="script-section-title">== Pervasives ==</p>
<p class="script-functions">&nbsp;</p>
<p class="script-title">=== out(text) ===</p>
<p class="script-description">display text in result textarea</p>
<p>&nbsp;</p>
<p class="script-title">=== outln(text) ===</p>
<p class="script-description">display text in result textarea with newline</p>
<p>&nbsp;</p>
<p class="script-functions">=== clear() ===</p>
<p class="script-description">clear result textarea</p>
<p>&nbsp;</p>
<p>== Library functions ==</p>
<p class="script-functions">=== Lib.bases ===</p>
<p class="script-description">"AGCU"</p>
<p>&nbsp;</p>
<p class="script-functions">=== Lib.fold(sequence) ===</p>
<p class="script-description">return folded structure with sequence</p>
<p>ex) Lib.fold("GGGGCCCC") = "((....))";</p>
<p>&nbsp;</p>
<p>=== Lib.energyOfStruct(sequence, structure) ===</p>
<p class="script-description">return energy of structure</p>
<p>&nbsp;</p>
<p>=== Lib.EternaScript(script id) ===</p>
<p class="script-description">return other user's script</p>
<p>ex) var func = Lib.EternaScript(script_id);</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>=== Lib.getStructure(puzzle id) ===</p>
<p class="script-description">return structure of puzzle</p>
<p>ex) Lib.getStructure(1001759)</p>
<p>&nbsp;</p>
<p>=== Lib.replace(sequence, index, 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>&nbsp;</p>
<p>=== Lib.nextSequence(sequence) ===</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>&nbsp;</p>
<p>=== Lib.nextSequenceWithBases(sequence, 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("AUAA", "UCGA") = "UCAA";</p>
<p>&nbsp;</p>
<p>=== Lib.random(from, to) ===</p>
<p class="script-description">return random number between from and to</p>
<p>&nbsp;</p>
<p class="script-functions">=== Lib.randomSequence(size) ===</p>
<p class="script-description">return random sequence with length of size</p>
<p>&nbsp;</p>
<p>=== Lib.map(function, sequence) ===</p>
<p class="script-description">applies function to each sequence bases</p>
<p>&nbsp;</p>
<p class="script-functions">=== Lib.filter(function, sequence) ===</p>
<p class="script-description">return sequences only satisfy the function</p>
<p>&nbsp;</p>
<p class="script-functions">=== Lib.splitDefault(structure) ===</p>
<p class="script-description">split structure into a structure array</p>
<p>ex) Lib.splitDefault("((..))") = ["((", "..", "))"];</p>
<p>&nbsp;</p>
<p>=== Lib.join(array) ===</p>
<p class="script-description">join array with each element to sequence</p>
<p>ex) Lib.join(Lib.split("((..))")) = "((..))";</p>
<p>&nbsp;</p>
<p>=== Lib.distance(source structure, 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 different length then just return -1</p>
<p>ex) Lib.distance("((..))", "((()))") = 2</p>
<p>ex) Lib.distance("(((())))", "(())") = -1</p>
<p>&nbsp;</p>
<p>=== Lib.distanceCustom(function, source structure, destination structure) ===</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>&nbsp;</p>
</div>
<div style="width: 46%; left: 56%; float: left; position: relative; padding: 0 0 1em 0; overflow: hidden;">
<p>== Class RNA ==</p>
<p><a href="http://kws.eternadev.org/web/script/">example code</a></p>
<p class="script-functions">&nbsp;</p>
<p class="script-title">=== getPairmap(structure) ===</p>
<p class="script-description">return the array of pair information</p>
<p>ex) getPairmap("((...))") = [6,5,,,,1,0]</p>
<p>&nbsp;</p>
<p>=== getStructure() ===</p>
<p class="script-description">return structure</p>
<p>&nbsp;</p>
<p>=== getRootElement() ===</p>
<p class="script-description">return root RNAElement class of rna object</p>
<p>&nbsp;</p>
<p>=== map() ===</p>
<p class="script-description">applies function to all RNAElement</p>
<p>&nbsp;</p>
<p>== Class RNAElement ==</p>
<p class="script-functions">&nbsp;</p>
<p class="script-title">=== getParent() ===</p>
<p class="script-description">return the parent RNAElement class</p>
<p>&nbsp;</p>
<p>=== getChilds() ===</p>
<p class="script-description">return the child RNAElement class array</p>
<p>&nbsp;</p>
<p>=== getElements() ===</p>
<p class="script-description">return the array of structure and index JSON objects</p>
<p>&nbsp;</p>
<p>=== isPaired() ===</p>
<p class="script-description">return boolean whether the stack element is paired or not</p>
<p>&nbsp;</p>
<p>=== getBaseType() ===</p>
<p class="script-description">return RNAElement.Stack or RNAElement.Loop if the element is stack or loop</p>
<p>&nbsp;</p>
<p>=== getType() ===</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>=== getIndices() ===</p>
<p class="script-description">return the array of indices</p>
<p>&nbsp;</p>
<p>=== isStack() / isLoop() / isHairpin() / isBulge() /<br /> isInternal() / isMultiloop() / isDangling() ===</p>
<p class="script-description">return boolean wheter the element is stack, loop, hairpin, bulge, internal, multiloop or dangling</p>
<p>&nbsp;</p>
<p>=== getSegmentCount() ===</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>
</div>
</div>
</div>
<div style="clear: both; float: left; overflow: hidden;">
<p>&nbsp;</p>
<p>Documentation for functions and APIs at the devel stage can be found on [[Script Documentation (devel)]]</p>
</div>
<div style="clear: both; float: left; overflow: hidden;">
<p>==See Also==</p>
<ul>
<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>Scripting lectures in [http://eternawiki.org/wiki/index.php5/EteRNA_University EteRNA University]</li>
<li><a href="https://docs.google.com/document/d/1AVs401fSZVD8FNNgkMQbFcxm_5O6RqpbSAk9o19f6Z8/edit#heading=h.8bg64ampbuz5">HTML Magic - Learn tricks for sharing material</a> by&nbsp;[[User:Machinelves|Machinelves]] and&nbsp;[[User:Eli Fisker|Eli Fisker]]</li>
</ul>
<p>&nbsp;</p>
</div>

Revision as of 22:19, 28 August 2017

 

 

== 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 ==

<a href="http://kws.eternadev.org/web/script/">example code</a>

 

=== 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==