This repository has been archived by the owner on Dec 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlineage_CoL.m
62 lines (48 loc) · 1.81 KB
/
lineage_CoL.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
%% lineage_CoL
% gets lineage of a species in Catolog of Life
%%
function [lineage rank id_CoL] = lineage_CoL(my_pet)
% created 2018/01/05 by Bas Kooijman
%% Syntax
% [lineage rank id_CoL] = <../lineage_CoL.m *lineage_CoL*>(my_pet)
%% Description
% Gets lineage of species from the Catolog of Life: kingdom, phylum, class, order, family, genus, species.
% To this end, the identifier for the accepted taxon name in CoL is obtained with <get_id_CoL.html *get_id_CoL*>
%
% Input:
%
% * my_pet: character string with name of an entry
%
% Output:
%
% * lineage: (n,1) cell array with lineage
% * rank: (n,1) cell array with ranks
% * id_CoL: identifier for species in CoL
%% Remarks
% <lineage.html *lineage*> gives a similar result for AmP entries
%% Example of use
% lineage_CoL('Daphnia_magna')
[id_CoL my_pet] = get_id_CoL(my_pet);
if isempty(id_CoL)
lineage = []; rank = [];
return
end
url = urlread(['http://webservice.catalogueoflife.org/col/webservice?id=', id_CoL, '&response=full']);
i_0 = 17 + strfind(url, '<classification>'); i_1 = strfind(url, '</classification>') - 1;
url = url(i_0:i_1); % substring between <classification>...</classification>
i_0 = 8 + strfind(url,'<taxon>'); i_1 = strfind(url,'</taxon>') - 1;
n = length(i_0); lineage = cell(n+1,1); rank = cell(n+1,1);
for i = 1:n % scan ranks
res_i = url(i_0(i):i_1(i)); % substring between <taxon>...</taxon>
j_0 = 6 + strfind(res_i,'<name>'); j_1 = strfind(res_i,'</name>') - 1;
nm = res_i(j_0:j_1); % substring between <name>...</name>
if ~strcmp(nm, 'Not assigned')
lineage(i) = {nm};
end
j_0 = 6 + strfind(res_i,'<rank>'); j_1 = strfind(res_i,'</rank>') - 1;
nm = res_i(j_0:j_1); % substring between <rank>...</rank>
if ~strcmp(nm, 'Not assigned')
rank(i) = {nm};
end
end
lineage(end) = {my_pet}; rank(end) = {'Species'};