Mercurial > repos > iuc > hyphy_strike_ambigs
comparison scripts/annotator.bf @ 0:7c86ceaf523c draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/hyphy/ commit 2742ee3b4e90f65352845265d2f85c4263e0eabb"
| author | iuc |
|---|---|
| date | Tue, 20 Apr 2021 10:27:46 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:7c86ceaf523c |
|---|---|
| 1 LoadFunctionLibrary ("libv3/tasks/trees.bf"); | |
| 2 LoadFunctionLibrary ("libv3/tasks/alignments.bf"); | |
| 3 LoadFunctionLibrary ("libv3/convenience/regexp.bf"); | |
| 4 LoadFunctionLibrary ("libv3/IOFunctions.bf"); | |
| 5 | |
| 6 tags = { | |
| 7 "^Node" : "Internal" | |
| 8 }; | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 tree = trees.LoadAnnotatedTopology (TRUE); | |
| 14 ts = tree[^"terms.trees.newick_with_lengths"]; | |
| 15 root_node = io.PromptUserForString ("Root on this node"); | |
| 16 | |
| 17 | |
| 18 | |
| 19 Topology T = ts; | |
| 20 ts = RerootTree (T, root_node); | |
| 21 ACCEPT_ROOTED_TREES = FALSE; | |
| 22 Topology T = ts; | |
| 23 ACCEPT_ROOTED_TREES = TRUE; | |
| 24 Topology TR = ts; | |
| 25 | |
| 26 | |
| 27 NORMALIZE_SEQUENCE_NAMES = FALSE; | |
| 28 SetDialogPrompt ("File with the sequences to label as the in-clade"); | |
| 29 DataSet query = ReadDataFile (PROMPT_FOR_FILE); | |
| 30 GetString (seqNames,query,-1); | |
| 31 | |
| 32 label = io.PromptUserForString ("Use this label"); | |
| 33 | |
| 34 | |
| 35 for (s;in;seqNames) { | |
| 36 tags [s && 6] = label; | |
| 37 } | |
| 38 | |
| 39 reg_exp = Rows (tags); | |
| 40 | |
| 41 | |
| 42 node_labels = {}; | |
| 43 for (_regexp_, _leaves_; in; regexp.PartitionByRegularExpressions (BranchName (T,-1), reg_exp)) { | |
| 44 tag = tags[_regexp_]; | |
| 45 | |
| 46 if (tag != "Internal") { | |
| 47 | |
| 48 if (Abs (tag) == 0) { | |
| 49 tag = "Reference"; | |
| 50 } | |
| 51 | |
| 52 for (l; in; _leaves_) { | |
| 53 node_labels[l] = tag; | |
| 54 } | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 node_labelsR = {}; | |
| 59 for (_regexp_, _leaves_; in; regexp.PartitionByRegularExpressions (BranchName (TR,-1), reg_exp)) { | |
| 60 tag = tags[_regexp_]; | |
| 61 | |
| 62 if (tag != "Internal") { | |
| 63 | |
| 64 if (Abs (tag) == 0) { | |
| 65 tag = "Reference"; | |
| 66 } | |
| 67 | |
| 68 for (l; in; _leaves_) { | |
| 69 node_labelsR[l] = tag; | |
| 70 } | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 | |
| 75 leaf_labels = node_labels; | |
| 76 node_labelsF = node_labels; | |
| 77 node_labels * ((trees.ParsimonyLabel ("T", node_labels))["labels"]); | |
| 78 node_labelsR * ((trees.ParsimonyLabel ("T", node_labelsR))["labels"]); | |
| 79 node_labelsF * ((trees.ParsimonyLabel ("T", node_labelsF))["labels"]); | |
| 80 | |
| 81 output_to = io.PromptUserForString ("Write output to this prefix"); | |
| 82 | |
| 83 fprintf (output_to + "labels.json", CLEAR_FILE, leaf_labels); | |
| 84 fprintf (output_to + "int.nwk", CLEAR_FILE, tree.Annotate ("T", "relabel_and_annotate", "{}", FALSE)); | |
| 85 fprintf (output_to + "clade.nwk", CLEAR_FILE, tree.Annotate ("TR", "relabel_and_annotate_full", "{}", FALSE)); | |
| 86 fprintf (output_to + "full.nwk", CLEAR_FILE, tree.Annotate ("T", "relabel_and_annotate_full", "{}", FALSE)); | |
| 87 | |
| 88 function relabel_and_annotate (node_name) { | |
| 89 _label = ""; | |
| 90 if (node_labels / node_name && leaf_labels / node_name == FALSE) { | |
| 91 _label = "{" + node_labels[node_name] + "}"; | |
| 92 } | |
| 93 return node_name + _label; | |
| 94 } | |
| 95 | |
| 96 function relabel_and_annotate_full (node_name) { | |
| 97 _label = ""; | |
| 98 if (node_labelsR / node_name) { | |
| 99 _label = "{" + node_labelsR[node_name] + "}"; | |
| 100 } | |
| 101 return node_name + _label; | |
| 102 } |
