[phylocom-user] converts a tabular `fy format' phylogeny to Newick, parenthetical forma

Carmen Palacios carmen.palacios at univ-perp.fr
Tue Sep 6 04:26:09 PDT 2011


Dear Cam,

Thank you for your reply. Your instructions worked perfectly! I'll
keep this script handy.

Cheers,

Gustavo.

On Tue, Sep 6, 2011 at 7:44 AM, Cam Webb <cwebb at oeb.harvard.edu> wrote:
> #!/bin/gawk -f
>
> # fy2new
> # converts a tabular `fy format' phylogeny to Newick, parenthetical format
>
> # (c) 2011 Cam Webb
> # Distributed under (open source) BSD 3-clause licence
>
> # fy-format = tab-delimited fields
> # Â  1. nodeID (starting at 0 for root node)
> # Â  2. parent node nodeID
> # Â  3. number of daughter nodes
> # Â  4. comma-delimited list of daughter nodeIDs (optional)
> # Â  5. depth of node (number of edges from root)
> # Â  6. branch length to parent node (a float)
> # Â  7. node name (terminal or interior node)
>
> BEGIN{
>
> Â if(ARGC != 2)
> Â  Â {
> Â  Â  Â print " Â Usage: fy2new file.fy";
> Â  Â  Â exit;
> Â  Â }
>
> Â FS="\t";
> Â NoBl = 1;
> }
>
> {
> Â NodeNo = $1;
> Â up[NodeNo] = $2;
> Â noat[NodeNo] = $3;
> Â bl[NodeNo] = $6;
> Â taxon[NodeNo] = $7;
>
> Â if ($6 != "") { NoBl = 0 };
> Â if (nnodes < NodeNo) {nnodes = NodeNo};
> }
>
> END{
>
> Â if(ARGC != 2) exit ;
>
> Â nnodes = nnodes+1;
>
> Â # SetNodePointers
>
> Â for (x = 0; x < nnodes; x++)
> Â  Â {
> Â  Â  Â ldown[x] = -99;
> Â  Â  Â rsister[x] = -99;
> Â  Â  Â first[x] = 1;
> Â  Â }
>
> Â for (x = 0; x < nnodes; x++)
> Â  Â {
> Â  Â  Â # starting at terms
> Â  Â  Â if (noat[x] == 0)
> Â  Â  Â  Â {
> Â  Â  Â  Â  Â y = x;
> Â  Â  Â  Â  Â # while not yet at the root
> Â  Â  Â  Â  Â while (y != 0)
> Â  Â  Â  Â  Â  Â {
> Â  Â  Â  Â  Â  Â  Â # is this the first daughter in new structure?
> Â  Â  Â  Â  Â  Â  Â  Â if (ldown[up[y]] == -99)
> Â  Â  Â  Â  Â  Â  Â  Â  Â {
> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â ldown[up[y]] = y;
> Â  Â  Â  Â  Â  Â  Â  Â  Â }
> Â  Â  Â  Â  Â  Â  Â  Â # if not, find the dangling sister
> Â  Â  Â  Â  Â  Â  Â  Â else
> Â  Â  Â  Â  Â  Â  Â  Â  Â {
> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â # start at ldown
> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â mark = ldown[up[y]];
> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â # move to node with an empty rsister
> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â while (rsister[mark] != -99)
> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â {
> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â mark = rsister[mark];
> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â }
> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â rsister[mark] = y;
> Â  Â  Â  Â  Â  Â  Â  Â  Â }
>
> Â  Â  Â  Â  Â  Â  Â  Â # test for refollowing old routes
> Â  Â  Â  Â  Â  Â  Â  Â if (first[up[y]] == 1) {y = up[y]; first[y] = 0;}
> Â  Â  Â  Â  Â  Â  Â  Â else break;
>
> Â  Â  Â  Â  Â  Â }
> Â  Â  Â  Â }
> Â  Â }
>
> Â # Recurse through levels
>
> Â tmp = "";
> Â printf("%s;\n", downPar(0, tmp));
>
> }
>
> function downPar(atn, tmp, Â  Â  Â  Â  Â  x, which, tmpnext )
> {
> Â which = 0;
>
> Â if (noat[atn] == 0)
> Â  Â {
> Â  Â  Â tmp = taxon[atn];
> Â  Â  Â if (!NoBL)
> Â  Â  Â  Â {
>          tmp = tmp  ":" bl[atn];
> Â  Â  Â  Â }
> Â  Â }
> Â else
> Â  Â {
> Â  Â  Â x = ldown[atn];
> Â  Â  Â tmp = Â "(";
> Â  Â  Â tmp = tmp downPar(x, tmpnext[which]);
>
> Â  Â  Â x = rsister[x]; which++;
>
> Â  Â  Â while (x != -99)
> Â  Â  Â  Â {
>          tmp = tmp  ",";
> Â  Â  Â  Â  Â tmp = tmp downPar(x, tmpnext[which]);
> Â  Â  Â  Â  Â x = rsister[x]; which++;
> Â  Â  Â  Â }
>      tmp = tmp  ")";
>      tmp = tmp  taxon[atn];
> Â  Â  Â if (!NoBL)
> Â  Â  Â  Â {
> Â  Â  Â  Â  Â if ((atn != 0) || (Droptail == 0))
> Â  Â  Â  Â  Â  Â {
>              tmp = tmp  ":" bl[atn];
> Â  Â  Â  Â  Â  Â }
> Â  Â  Â  Â }
> Â  Â }
>
> Â return tmp;
> }
>
> # END OF FILE
_______________________________________________
phylocom-user mailing list
phylocom-user at lists.phylodiversity.net
http://lists.phylodiversity.net/listinfo.cgi/phylocom-user-phylodiversity.net

-- 
Ce message a été vérifié par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a été trouvé.
CRI UPVD http://www.univ-perp.fr


-- 
Ce message a été vérifié par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a été trouvé.
CRI UPVD http://www.univ-perp.fr




More information about the phylocom-user mailing list