In [23]:
from skbio import read, SequenceCollection, local_pairwise_align_ssw
In [18]:
seqs = read("https://dl.dropboxusercontent.com/u/2868868/61_otus.fasta", into=SequenceCollection)
/Users/caporaso/.virtualenvs/skbio/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
/Users/caporaso/.virtualenvs/skbio/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
/Users/caporaso/.virtualenvs/skbio/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
/Users/caporaso/.virtualenvs/skbio/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
/Users/caporaso/.virtualenvs/skbio/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
In [29]:
def aligned_distance(seq1, seq2):
a = local_pairwise_align_ssw(seq1, seq2)
return a[0].distance(a[1])
In [32]:
seqs_distances = seqs.distances(aligned_distance)
---------------------------------------------------------------------------
BiologicalSequenceError Traceback (most recent call last)
<ipython-input-32-e794c3fde44c> in <module>()
----> 1 seqs_distances = seqs.distances(aligned_distance)
/Users/caporaso/Dropbox/code/scikit-bio/skbio/alignment/_alignment.pyc in distances(self, distance_fn)
335 ids.append(self_i.id)
336 for j in range(i):
--> 337 dm[i, j] = dm[j, i] = self_i.distance(self[j], distance_fn)
338 return DistanceMatrix(dm, ids)
339
/Users/caporaso/Dropbox/code/scikit-bio/skbio/sequence/_sequence.pyc in distance(self, other, distance_fn)
888 if len(self) != len(other):
889 raise BiologicalSequenceError(
--> 890 "Sequences do not have equal length. "
891 "Distance can only be computed between "
892 "BiologicalSequences of equal length.")
BiologicalSequenceError: Sequences do not have equal length. Distance can only be computed between BiologicalSequences of equal length.
In [30]:
for i in range(seqs.sequence_count()):
for j in range(i):
print i, j, aligned_distance(seqs[i], seqs[j])
1 0 0.634299138606
2 0 0.578715365239
2 1 0.571875
3 0 0.593582887701
3 1 0.604963112005
3 2 0.634089132134
4 0 0.473903966597
4 1 0.487316421896
4 2 0.453781512605
4 3 0.563598759049
5 0 0.667346938776
5 1 0.507853403141
5 2 0.351321585903
5 3 0.528
5 4 0.58904109589
6 0 0.410714285714
6 1 0.448732083793
6 2 0.377212389381
6 3 0.501831501832
6 4 0.354632587859
6 5 0.353556485356
7 0 0.550847457627
7 1 0.532403609516
7 2 0.540558510638
7 3 0.647754137116
7 4 0.457330415755
7 5 0.484460694698
7 6 0.308287292818
8 0 0.446991404011
8 1 0.529538131042
8 2 0.393852065322
8 3 0.515560165975
8 4 0.381679389313
8 5 0.233128834356
8 6 0.353870458136
8 7 0.414161008729
9 0 0.620253164557
9 1 0.61244813278
9 2 0.55737704918
9 3 0.63112164297
9 4 0.539705882353
9 5 0.519713261649
9 6 0.472160356347
9 7 0.545530492899
9 8 0.530655391121
10 0 0.630357142857
10 1 0.373949579832
10 2 0.680547293278
10 3 0.261538461538
10 4 0.223140495868
10 5 0.605769230769
10 6 0.163701067616
10 7 0.619551681196
10 8 0.572802197802
10 9 0.264957264957
11 0 0.642172523962
11 1 0.181818181818
11 2 0.578360655738
11 3 0.507067137809
11 4 0.291139240506
11 5 0.416370106762
11 6 0.449346405229
11 7 0.65496286293
11 8 0.563184079602
11 9 0.472375690608
11 10 0.283333333333
12 0 0.66507557677
12 1 0.406593406593
12 2 0.5825446898
12 3 0.470782800441
12 4 0.208633093525
12 5 0.318777292576
12 6 0.515864892528
12 7 0.570937231298
12 8 0.206572769953
12 9 0.35652173913
12 10 0.525876460768
12 11 0.477855477855
13 0 0.534134007585
13 1 0.520231213873
13 2 0.664131812421
13 3 0.409168081494
13 4 0.469539375929
13 5 0.354758961681
13 6 0.559957173448
13 7 0.5665374677
13 8 0.37
13 9 0.635390946502
13 10 0.590692124105
13 11 0.419237749546
13 12 0.561093247588
14 0 0.434343434343
14 1 0.402555910543
14 2 0.516539440204
14 3 0.301587301587
14 4 0.482456140351
14 5 0.475625823452
14 6 0.328185328185
14 7 0.593406593407
14 8 0.508474576271
14 9 0.348360655738
14 10 0.316062176166
14 11 0.515463917526
14 12 0.240310077519
14 13 0.475073313783
15 0 0.50259965338
15 1 0.338308457711
15 2 0.479048697622
15 3 0.503703703704
15 4 0.443243243243
15 5 0.489100817439
15 6 0.394321766562
15 7 0.462435233161
15 8 0.474537037037
15 9 0.354838709677
15 10 0.427536231884
15 11 0.528971962617
15 12 0.228070175439
15 13 0.494453248811
15 14 0.450754214729
16 0 0.471218206158
16 1 0.223529411765
16 2 0.544268406337
16 3 0.265060240964
16 4 0.509052183174
16 5 0.471172962227
16 6 0.308695652174
16 7 0.60147601476
16 8 0.505649717514
16 9 0.269662921348
16 10 0.34693877551
16 11 0.449050086356
16 12 0.2
16 13 0.448625180897
16 14 0.375771604938
16 15 0.39417989418
17 0 0.550354609929
17 1 0.394190871369
17 2 0.549751243781
17 3 0.189655172414
17 4 0.293269230769
17 5 0.509544787078
17 6 0.478827361564
17 7 0.378205128205
17 8 0.578488372093
17 9 0.388571428571
17 10 0.338541666667
17 11 0.252336448598
17 12 0.221153846154
17 13 0.302083333333
17 14 0.515756302521
17 15 0.558490566038
17 16 0.471191791634
18 0 0.527972027972
18 1 0.325301204819
18 2 0.392
18 3 0.410358565737
18 4 0.376425855513
18 5 0.422764227642
18 6 0.326923076923
18 7 0.677655677656
18 8 0.383064516129
18 9 0.309278350515
18 10 0.442748091603
18 11 0.454183266932
18 12 0.411290322581
18 13 0.349090909091
18 14 0.646201074444
18 15 0.592095977417
18 16 0.608507570296
18 17 0.467532467532
19 0 0.567635903919
19 1 0.231481481481
19 2 0.57200538358
19 3 0.282258064516
19 4 0.625937834941
19 5 0.55684754522
19 6 0.297520661157
19 7 0.373702422145
19 8 0.600493218249
19 9 0.340425531915
19 10 0.412162162162
19 11 0.233333333333
19 12 0.313636363636
19 13 0.55792276964
19 14 0.480690221857
19 15 0.510897994769
19 16 0.470454545455
19 17 0.568410462777
19 18 0.598024316109
20 0 0.416955017301
20 1 0.273504273504
20 2 0.372294372294
20 3 0.269230769231
20 4 0.491349480969
20 5 0.439236111111
20 6 0.325396825397
20 7 0.382749326146
20 8 0.44578313253
20 9 0.280373831776
20 10 0.368421052632
20 11 0.478873239437
20 12 0.351485148515
20 13 0.426804123711
20 14 0.518376722818
20 15 0.588591184097
20 16 0.423380726698
20 17 0.5712219812
20 18 0.390625
20 19 0.585197934596
21 0 0.452
21 1 0.238636363636
21 2 0.50099009901
21 3 0.364754098361
21 4 0.550387596899
21 5 0.472316384181
21 6 0.293375394322
21 7 0.575719649562
21 8 0.452488687783
21 9 0.39762611276
21 10 0.303317535545
21 11 0.477663230241
21 12 0.330578512397
21 13 0.554334554335
21 14 0.34219269103
21 15 0.389975550122
21 16 0.437365783822
21 17 0.469933184855
21 18 0.597376387487
21 19 0.438735177866
21 20 0.567660550459
In [33]:
seqs.distances?
In [ ]:
Content source: gregcaporaso/sketchbook
Similar notebooks: