Difference between revisions of "Template:Clade converter/doc"

From blackwiki
Jump to navigation Jump to search
imported>Jts1882
(remove duplication →‎List Converter)
imported>Jts1882
(modify for what template should show →‎Example)
Line 82: Line 82:
 
}}
 
}}
 
</pre>
 
</pre>
|output1=<pre>  {{clade
+
|output1={{Clade converter
  |label1=A
+
|indent=3
  |1={{clade
+
|list=
      |1=A1
+
@A
      |2=A2
+
@@A1
      }}
+
@@A2
  |2=B
+
@B
  |label3=C
+
@C
  |3={{clade
+
@@C1
      |1=C1
+
@@C2
      |label2=C2
+
@@@C2a
      |2={{clade
+
@@@C2b
        |1=C2a
+
@@@@C2b1
        |label2=C2b
+
@@@@C2b2
        |2={{clade
+
@@C3
            |1=C2b1
+
@D
            |2=C2b2
+
@@D1
            }}
+
@@D2
        }}
+
}}
      |3=C3
 
      }}
 
  |label4=D
 
  |4={{clade
 
      |1=D1
 
      |2=D2
 
      }}
 
  }}</pre>
 
 
|comment1={{cladeN
 
|comment1={{cladeN
 
|label1=label
 
|label1=label

Revision as of 13:18, 27 November 2019

Newick Converter

Convert simple Newick strings to the clade structure. This is a tool to aid contruction of cladograms using the {{clade}} template and not for use directly in the article namespace.

Parameters

  • |newickstring= – the Newick format data to be converted
  • |indent= – optionally set an indent, which will indent every line by N spaces. This can help alignment in the final cladogram.

Example

The following code

{{Template:Clade newick converter
|newickstring=((lion,jaguar,leopard),((siberian,javan,bengal)tiger,snow leopard))panthera
|indent=10
}}

produces the output below

Modified Newick string:
((lion,jaguar,leopard),((siberian,javan,bengal)tiger,snow leopard))panthera
Output of clade template structure:
{{clade
          |label1=panthera
          |1={{clade
             |label1=
             |1={{clade
                |1=lion
                |2=jaguar
                |3=leopard
                }}
             |label2=
             |2={{clade
                |label1=tiger
                |1={{clade
                   |1=siberian
                   |2=javan
                   |3=bengal
                   }}
                |2=snow leopard
                }}
             }}
}}

Processing the Newick string

The Newick format data provided Open Tree of Life and other sources typically has extraneous encoding data. This extra information can be removed using the |newickN-pattern= and |newickN-replace= parameters which supply a Lua pattern (similar to Regex) and replacement. The following code uses Newick format data for the genus Prionailurus downloaded from using Open Tree of Life (source data):


{{clade newick converter
   |newickstring=(Prionailurus_planiceps_ott86166,(((Prionailurus_bengalensis_chinensis_ott198595,Prionailurus_bengalensis_euptilurus_ott547362,Prionailurus_bengalensis_bengalensis_ott5557509,Prionailurus_bengalensis_rabori_ott7067613)Prionailurus_bengalensis_ott280108,Prionailurus_iriomotensis_ott418475),Prionailurus_viverrinus_ott862641),Prionailurus_rubiginosus_ott507541)Prionailurus_ott570215
   |newick-pattern=([%a_]+)_(ott[%d]*)
   |newick-replace={{'}}{{'}}%1{{'}}{{'}}
   |newick-pattern2=(%a)(%l+)_
   |newick-replace2=%1._ 
}}

produces

Modified Newick string:
(Prionailurus planiceps ott86166,(((Prionailurus bengalensis chinensis ott198595,Prionailurus bengalensis euptilurus ott547362,Prionailurus bengalensis bengalensis ott5557509,Prionailurus bengalensis rabori ott7067613)Prionailurus bengalensis ott280108,Prionailurus iriomotensis ott418475),Prionailurus viverrinus ott862641),Prionailurus rubiginosus ott507541)Prionailurus ott570215
Output of clade template structure:
{{clade
|label1=Prionailurus ott570215
|1={{clade
   |1=Prionailurus planiceps ott86166
   |label2=
   |2={{clade
      |label1=
      |1={{clade
         |label1=Prionailurus bengalensis ott280108
         |1={{clade
            |1=Prionailurus bengalensis chinensis ott198595
            |2=Prionailurus bengalensis euptilurus ott547362
            |3=Prionailurus bengalensis bengalensis ott5557509
            |4=Prionailurus bengalensis rabori ott7067613
            }}
         |2=Prionailurus iriomotensis ott418475
         }}
      |2=Prionailurus viverrinus ott862641
      }}
   |3=Prionailurus rubiginosus ott507541
   }}
}}

In this example there are two replacements. The first strips the _ott suffix and applies Wikitext markup. Note the Wikitext markup has to be handled with a template ({{'}}) The second abbreviates the genus name when not standalone. In addition, underscores are always replaced by spaces.

List Converter

Converts a Wikitext like list to a clade structure. The list uses the symbol @ as the * would be processed as wikitext.

Example

The following illustrates the code and the desired output:

Template call with pseudo-Wikitext listOutput of template as clade codeThe cladogram that the code produces
{{Clade converter
|indent=3
|list=
@A
@@A1
@@A2
@B
@C
@@C1
@@C2
@@@C2a
@@@C2b
@@@@C2b1
@@@@C2b2
@@C3
@D
@@D1
@@D2
}}
   {{clade
   |label1=A
   |1={{clade
      |1=A1
      |2=A2
      }}
   |2=B
   |label3=C
   |3={{clade
      |1=C1
      |label2=C2
      |2={{clade
         |1=C2a
         |label2=C2b
         |2={{clade
            |1=C2b1
            |2=C2b2
            }}
         }}
      |3=C3
      }}
   |label4=D
   |4={{clade
      |1=D1
      |2=D2
      }}
   }}
label
A

A1



A2




B


C

C1


C2

C2a


C2b

C2b1



C2b2





C3



D

D1



D2