skbio.math.stats.ordination.OrdinationResults.from_file

classmethod OrdinationResults.from_file(ord_res_f)[source]

Load ordination results from text file.

Creates a OrdinationResults instance from serialized results stored as text.

ord_res_f must be a file-like object containing text.

The ord_res_f format should look like:

Eigvals<tab>2
0.096<tab>0.040

Proportion explained<tab>2
0.512<tab>0.488

Species<tab>3<tab>2
Species1<tab>0.408<tab>0.069
Species2<tab>-0.115<tab>-0.299
Species3<tab>-0.309<tab>0.187

Site<tab>3<tab>2
Site1<tab>-0.848<tab>0.882
Site2<tab>-0.220<tab>-1.344
Site3<tab>1.666<tab>0.470

Biplot<tab>4<tab>3
0.422<tab>-0.559<tab>-0.713
0.988<tab>0.150<tab>-0.011
-0.556<tab>0.817<tab>0.147
-0.404<tab>-0.905<tab>-0.127

Site constraints<tab>3<tab>2
Site1<tab>-0.848<tab>0.882
Site2<tab>-0.220<tab>-1.344
Site3<tab>1.666<tab>0.470

If a given result attribute is not present (e.g. Biplot), it should be still defined and declare its dimensions as 0:

Biplot<tab>0<tab>0
Parameters:

ord_res_f : iterable of str or str

Iterable of strings (e.g., open file handle, file-like object, list of strings, etc.) or a file path (a string) containing the serialized ordination results.

Returns:

OrdinationResults

Instance of type cls containing the parsed contents of ord_res_f.

Raises:

ValueError

if the shapes of the different sections of the file are not consistent

FileFormatError

if the format of the file is not recognized

Examples

Assume we have the following tab-delimited text file storing the ordination results:

Eigvals\t2
0.0961330159181\t0.0409418140138

Proportion explained\t0

Species\t3\t2
Species1\t0.408869425742\t0.0695518116298
Species2\t-0.1153860437\t-0.299767683538
Species3\t-0.309967102571\t0.187391917117

Site\t3\t2
Site1\t-0.848956053187\t0.882764759014
Site2\t-0.220458650578\t-1.34482000302
Site3\t1.66697179591\t0.470324389808

Biplot\t0\t0

Site constraints\t0\t0

Load the ordination results from the file:

>>> from StringIO import StringIO
>>> from skbio.math.stats.ordination import OrdinationResults
>>> or_f = StringIO("Eigvals\t2\n"
...                 "0.0961330159181\t0.0409418140138\n"
...                 "\n"
...                 "Proportion explained\t0\n"
...                 "\n"
...                 "Species\t3\t2\n"
...                 "Species1\t0.408869425742\t0.0695518116298\n"
...                 "Species2\t-0.1153860437\t-0.299767683538\n"
...                 "Species3\t-0.309967102571\t0.187391917117\n"
...                 "\n"
...                 "Site\t3\t2\n"
...                 "Site1\t-0.848956053187\t0.882764759014\n"
...                 "Site2\t-0.220458650578\t-1.34482000302\n"
...                 "Site3\t1.66697179591\t0.470324389808\n"
...                 "\n"
...                 "Biplot\t0\t0\n"
...                 "\n"
...                 "Site constraints\t0\t0\n")
>>> ord_res = OrdinationResults.from_file(or_f)