-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
221 additions
and
6 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(((((sample-55:41.71429,sample-46:41.28571)Inner36:2.08594,(sample-12:42.79847,sample-6:42.20153)Inner50:1.41406)Inner73:1.17639,(((((sample-89:39.37228,sample-72:40.62772)Inner7:2.88906,(sample-45:40.87658,sample-41:41.12342)Inner20:2.11094)Inner59:0.95241,(sample-27:41.71186,sample-24:41.28814)Inner40:2.29759)Inner77:0.51510,(sample-80:41.63672,(sample-82:40.88750,sample-21:41.11250)Inner19:0.86328)Inner35:2.70365)Inner84:0.48215,(((sample-53:39.58763,sample-9:39.41237)Inner2:3.35795,(sample-4:41.68852,sample-3:42.31148)Inner38:1.14205)Inner55:1.86063,(((sample-99:43.18750,(sample-69:40.72472,sample-11:40.27528)Inner10:2.31250)Inner57:0.78292,(sample-59:40.65000,sample-5:40.35000)Inner9:3.21708)Inner71:0.49007,((sample-64:42.29009,sample-51:41.70991)Inner46:1.50781,((sample-92:39.63235,sample-40:40.36765)Inner14:2.19477,(sample-36:41.94129,sample-0:42.05871)Inner33:1.30523)Inner56:0.99219)Inner72:0.29118)Inner75:0.68624)Inner85:0.26394)Inner90:0.19666)Inner95:0.08868,(((sample-98:41.20513,sample-10:40.79487)Inner21:2.48769,((sample-97:39.56720,sample-76:39.43280)Inner6:1.17105,sample-7:41.32895)Inner23:2.51231)Inner66:1.14558,((sample-74:41.75746,sample-60:41.24254)Inner32:2.66667,(sample-57:40.47159,sample-1:40.52841)Inner11:3.58333)Inner81:0.38567)Inner86:0.41473)Inner97:0.06049,((((((sample-85:40.63889,sample-79:40.36111)Inner18:2.67318,(sample-34:41.67500,(sample-61:41.34740,sample-29:40.65260)Inner22:0.82500)Inner39:1.57682)Inner63:0.86737,(sample-28:42.59722,sample-26:42.40278)Inner45:1.94513)Inner78:0.65710,((sample-68:41.90893,sample-25:41.09107)Inner29:2.04375,(sample-50:42.40701,(sample-38:39.78646,sample-20:39.21354)Inner3:3.09299)Inner58:0.45625)Inner64:1.28040)Inner91:0.18081,(((sample-75:43.23395,(sample-63:42.24892,(sample-49:40.47632,sample-47:39.52368)Inner4:2.25108)Inner41:1.01605)Inner62:0.40142,(sample-67:40.70640,sample-22:41.29360)Inner13:2.78608)Inner65:1.37617,(((sample-73:40.43750,sample-42:40.56250)Inner15:2.78987,(sample-54:40.93373,sample-33:41.06627)Inner16:2.71013)Inner70:0.76270,((sample-95:41.60769,sample-43:41.39231)Inner34:1.04255,(sample-39:39.71809,sample-17:40.28191)Inner5:2.70745)Inner52:1.79980)Inner83:0.34258)Inner89:0.30845)Inner94:0.14628,(((sample-87:41.83004,(sample-48:41.19366,sample-19:40.80634)Inner28:0.66996)Inner42:2.31867,((sample-91:43.22596,(sample-81:42.31971,sample-30:42.68029)Inner47:0.77404)Inner60:0.92154,(sample-90:40.65854,sample-8:40.34146)Inner17:2.82846)Inner76:0.33758)Inner80:0.63334,(((sample-52:42.86528,(sample-71:41.14062,sample-16:41.85938)Inner27:1.63472)Inner54:1.13031,(sample-88:42.35491,(sample-93:39.14796,sample-13:38.85204)Inner1:3.14509)Inner43:1.93219)Inner74:0.91706,(((sample-83:40.94000,sample-70:41.06000)Inner24:2.54713,(sample-58:42.45098,(sample-32:40.81926,sample-15:41.18074)Inner25:1.04902)Inner48:1.32787)Inner68:0.77832,((sample-84:40.79281,sample-56:41.20719)Inner26:1.93092,(sample-18:42.71250,sample-2:42.28750)Inner49:0.81908)Inner61:1.22168)Inner79:0.55950)Inner92:0.07174)Inner93:0.17696)Inner96:0.08099,(((sample-96:40.31319,sample-66:39.68681)Inner8:3.27246,(sample-62:42.03226,sample-35:40.96774)Inner37:1.72754)Inner67:1.19815,((sample-31:42.10677,(sample-44:40.49425,sample-23:40.50575)Inner12:1.89323)Inner51:1.99544,(((sample-78:42.29891,sample-77:42.70109)Inner53:0.82760,(sample-94:40.98713,sample-65:41.01287)Inner31:2.17240)Inner69:0.84881,(sample-86:41.76705,(sample-37:41.45833,sample-14:41.54167)Inner30:0.73295)Inner44:2.08869)Inner82:0.34831)Inner87:0.14560)Inner88:0.30133)Inner98:0.00000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
sample-0 sample-1 sample-2 sample-3 sample-4 sample-5 sample-6 sample-7 sample-8 sample-9 | ||
sample-0 0 10 10 9 10 10 8 9 10 10 | ||
sample-1 10 0 9 9 8 7 9 7 9 9 | ||
sample-2 10 9 0 10 9 10 9 10 10 10 | ||
sample-3 9 9 10 0 10 10 8 10 9 8 | ||
sample-4 10 8 9 10 0 7 9 10 10 6 | ||
sample-5 10 7 10 10 7 0 10 8 9 10 | ||
sample-6 8 9 9 8 9 10 0 10 8 7 | ||
sample-7 9 7 10 10 10 8 10 0 9 9 | ||
sample-8 10 9 10 9 10 9 8 9 0 8 | ||
sample-9 10 9 10 8 6 10 7 9 8 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
((sample-8:4.42708,(sample-3:4.32812,(sample-6:3.42500,sample-0:4.57500)Inner4:0.17188)Inner5:0.32292)Inner6:0.17969,(sample-2:5.13281,(sample-7:3.87500,(sample-5:3.78571,sample-1:3.21429)Inner2:0.12500)Inner3:0.86719)Inner7:0.05469,(sample-9:2.87500,sample-4:3.12500)Inner1:1.32031)Inner8:0.00000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import csv | ||
import numpy as np | ||
|
||
import Bio.Phylo | ||
from Bio.Phylo.TreeConstruction import DistanceMatrix, DistanceTreeConstructor | ||
|
||
def usage(): | ||
print("usage: mentalist_tree <input.tsv>\n") | ||
|
||
def process_input_matrix(input_matrix): | ||
""" Converts an array-of-arrays containting sample IDs and distances | ||
into a BioPython DistanceMatrix object | ||
""" | ||
input_matrix.pop(0) | ||
sample_names = [row[0] for row in input_matrix] | ||
for row in input_matrix: | ||
row.pop(0) | ||
distance_matrix = [] | ||
for input_matrix_row in input_matrix: | ||
distance_matrix.append([int(i) for i in input_matrix_row]) | ||
""" np.tril() converts a matrix like this: [[0 1 2] | ||
[1 0 1] | ||
[2 1 0]] | ||
...into this: [[0 0 0] | ||
[1 0 0] | ||
[2 1 0]] | ||
...but what we need to pass to DistanceMatrix() is this: [[0] | ||
[1 0] | ||
[2 1 0]] | ||
...so that's what the (somewhat cryptic) code below does. | ||
""" | ||
distance_matrix = np.tril(np.array(distance_matrix)) | ||
num_rows = distance_matrix.shape[0] | ||
""" masking the distance matrix with tril_indices gives a linearized | ||
distance matrix [0 1 0 2 1 0] that we need to re-construct into [[0], [1, 0], [2, 1, 0]] | ||
""" | ||
lower_triangular_idx_mask = np.tril_indices(num_rows) | ||
linear_distance_matrix = distance_matrix[lower_triangular_idx_mask] | ||
distance_matrix = [] | ||
min = 0 | ||
max = 1 | ||
for i in range(num_rows): | ||
distance_matrix.append(linear_distance_matrix[min:max].tolist()) | ||
min = max | ||
max = max + (i + 2) | ||
distance_matrix = DistanceMatrix(names=sample_names, matrix=distance_matrix) | ||
return distance_matrix | ||
|
||
def main(): | ||
if len(sys.argv) < 2: | ||
usage() | ||
sys.exit(1) | ||
|
||
input_file = sys.argv[1] | ||
reader = csv.reader(open(input_file, "r"), delimiter="\t") | ||
input_matrix = list(reader) | ||
distance_matrix = process_input_matrix(input_matrix) | ||
constructor = DistanceTreeConstructor() | ||
tree = constructor.nj(distance_matrix) | ||
Bio.Phylo.write(tree, sys.stdout, 'newick') | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<tool id="mentalist_tree" name="MentaLiST Tree" version="0.1.8"> | ||
<requirements> | ||
<requirement type="package" version="1.70">biopython</requirement> | ||
</requirements> | ||
<command detect_errors="exit_code"><![CDATA[ | ||
$__tool_directory__/mentalist_tree | ||
'${input}' | ||
> '${output}' | ||
]]></command> | ||
<inputs> | ||
<param name="input" type="data" format="tabular" label="MentaLiST Distance Matrix" help=""/> | ||
</inputs> | ||
<outputs> | ||
<data name="output" format="txt"/> | ||
</outputs> | ||
<tests> | ||
<test> | ||
<param name="input" value="mentalist_tree/small_input_00.tsv" /> | ||
<output name="output" file="mentalist_tree/small_output_00.nwk" /> | ||
</test> | ||
<test> | ||
<param name="input" value="mentalist_tree/med_input_00.tsv" /> | ||
<output name="output" file="mentalitst_tree/med_output_00.nwk" /> | ||
</test> | ||
<test> | ||
<param name="input" value="mentalist_tree/large_input_00.tsv" /> | ||
<output name="output" file="mentalist_tree/large_output_00.nwk" /> | ||
</test> | ||
</tests> | ||
<help><![CDATA[ | ||
mentalist_distance <input.tsv> | ||
]]></help> | ||
<citations> | ||
</citations> | ||
</tool> |