-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathget_id_Taxo.m
82 lines (73 loc) · 2.32 KB
/
get_id_Taxo.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
%% get_id_Taxo
% gets id of species name in the Taxonomicon
%%
function id_Taxo = get_id_Taxo(my_pet, open)
% created 2018/01/31 by Bas Kooijman
%% Syntax
% id_Taxo = <../get_id_Taxo.m *get_id_Taxo*>(my_pet, open)
%% Description
% Gets identifier for a species name in the Taxonomicon
%
% Input:
%
% * my_pet: character string with name of a taxon
% * open: optional boolean for opening in browser (default: 0)
%
% Output:
%
% * id_Taxo: character string of id in Taxonomicon
%% Remarks
% Outputs empty string if identification was not successful.
% Used in lineage_Taxo to get the lineage
%% Example of use
% id_Taxo = get_id_Taxo('Daphnia_magna', 1)
address = 'http://taxonomicon.taxonomy.nl/TaxonTree.aspx?id=';
if ~exist('open','var')
open = 0;
end
if ~isempty(strfind(my_pet, ' '));
my_pet = strrep(my_pet,' ','_');
end
try
url = urlread(['http://taxonomicon.taxonomy.nl/TaxonList.aspx?subject=Entity&by=ScientificName&search=', my_pet]);
ind = strfind(url,'TaxonName.aspx?id=');
if isempty(ind)
my_pet_syn = get_synonym(get_id_CoL(my_pet));
if isempty(my_pet_syn)
id_Taxo = '';
else
url = urlread(['http://taxonomicon.taxonomy.nl/TaxonList.aspx?subject=Entity&by=ScientificName&search=', my_pet_syn]);
ind = strfind(url,'TaxonName.aspx?id=');
if isempty(ind)
id_Taxo = '';
else
url(1:(17 + strfind(url,'TaxonName.aspx?id='))) = '';
id_Taxo = url(1:(strfind(url,'&') - 1));
end
end
else
url(1:(17 + strfind(url,'TaxonName.aspx?id='))) = '';
id_Taxo = url(1:(strfind(url,'&') - 1));
end
if isempty(id_Taxo)
nm = strsplit(my_pet,'_'); nm = nm{1};
url = urlread(['http://taxonomicon.taxonomy.nl/TaxonList.aspx?subject=Entity&by=ScientificName&search=', nm]);
ind = strfind(url,'TaxonName.aspx?id=');
if isempty(ind)
id_Taxo = ''; return
end
url(1:(17 + strfind(url,'TaxonName.aspx?id='))) = '';
id_Taxo = url(1:(strfind(url,'&') - 1));
end
if open
web([address, id_Taxo],'-browser');
end
catch
if ~isempty(strfind(my_pet, '_'))
fprintf('Warning from get_id_Taxo: species not found, now try genus\n');
my_pet = strsplit(my_pet, '_'); my_pet = my_pet{1}; id_Taxo = get_id_Taxo(my_pet); return
else
fprintf('Warning from get_id_Taxo: Unable to contact server or genus not found\n');
end
id_Taxo = [];
end