# Path: q2_types/ordination/_format.py
# class OrdinationFormat(model.TextFileFormat):
#     def sniff(self):
#         sniffer = skbio.io.io_registry.get_sniffer('ordination')
#         return sniffer(str(self))[0]
# 
# class ProcrustesStatisticsFmt(model.TextFileFormat):
#     METADATA_COLUMNS = {
#         'true M^2 value',
#         'p-value for true M^2 value',
#         'number of Monte Carlo permutations',
#     }
# 
#     def validate(self, level):
#         try:
#             md = qiime2.Metadata.load(str(self))
#         except qiime2.metadata.MetadataFileError as md_exc:
#             raise ValidationError(md_exc) from md_exc
# 
#         for column in sorted(self.METADATA_COLUMNS):
#             try:
#                 md.get_column(column)
#             except ValueError as md_exc:
#                 raise ValidationError(md_exc) from md_exc


import unittest
import skbio
import pandas as pd
import pandas.testing as pdt
import qiime2
from q2_types.ordination import OrdinationFormat, ProcrustesStatisticsFmt
from qiime2.plugin.testing import TestPluginBase
        columns = ['Axis %d' % i for i in range(1, 9)]
        self.assertEqual(columns, list(obs.columns))

    def test_df_to_procrustes_m2_stats_fmt(self):
        input_df = pd.DataFrame({'true M^2 value': [1],
                                 'p-value for true M^2 value': [0.2],
                                 'number of Monte Carlo permutations': [300]},
                                index=pd.Index(['results'], name='id'))

        exp = ['id\ttrue M^2 value\tp-value for true M^2 value\t'
               'number of Monte Carlo permutations\n',
               '#q2:types\tnumeric\tnumeric\tnumeric\n',
               'results\t1\t0.2\t300\n']

        transformer = self.get_transformer(pd.DataFrame,
                                           ProcrustesStatisticsFmt)
        fmt = transformer(input_df)
        with open(str(fmt), 'r') as fh:
            obs = fh.readlines()

        self.assertEqual(exp, obs)

    def test_procrustes_m2_stats_fmt_to_df(self):
        filepath = self.get_data_path('m2stats-999-permus.tsv')
        input_fmt = ProcrustesStatisticsFmt(filepath, mode='r')
        exp = pd.DataFrame({'true M^2 value': [0.0789623748362618],
                            'p-value for true M^2 value': [0.001],
                            'number of Monte Carlo permutations': [999]},
                           index=pd.Index(['results'], name='id'))


# Path: q2_types/ordination/_format.py
# class OrdinationFormat(model.TextFileFormat):
#     def sniff(self):
#         sniffer = skbio.io.io_registry.get_sniffer('ordination')
#         return sniffer(str(self))[0]
# 
# class ProcrustesStatisticsFmt(model.TextFileFormat):
#     METADATA_COLUMNS = {
#         'true M^2 value',
#         'p-value for true M^2 value',
#         'number of Monte Carlo permutations',
#     }
# 
#     def validate(self, level):
#         try:
#             md = qiime2.Metadata.load(str(self))
#         except qiime2.metadata.MetadataFileError as md_exc:
#             raise ValidationError(md_exc) from md_exc
# 
#         for column in sorted(self.METADATA_COLUMNS):
#             try:
#                 md.get_column(column)
#             except ValueError as md_exc:
#                 raise ValidationError(md_exc) from md_exc


# Path: q2_types/ordination/tests/test_transformer.py
import unittest
import skbio
import pandas as pd
import pandas.testing as pdt
import qiime2
from q2_types.ordination import OrdinationFormat, ProcrustesStatisticsFmt
from qiime2.plugin.testing import TestPluginBase

        columns = ['Axis %d' % i for i in range(1, 9)]
        self.assertEqual(columns, list(obs.columns))

    def test_df_to_procrustes_m2_stats_fmt(self):
        input_df = pd.DataFrame({'true M^2 value': [1],
                                 'p-value for true M^2 value': [0.2],
                                 'number of Monte Carlo permutations': [300]},
                                index=pd.Index(['results'], name='id'))

        exp = ['id\ttrue M^2 value\tp-value for true M^2 value\t'
               'number of Monte Carlo permutations\n',
               '#q2:types\tnumeric\tnumeric\tnumeric\n',
               'results\t1\t0.2\t300\n']

        transformer = self.get_transformer(pd.DataFrame,
                                           ProcrustesStatisticsFmt)
        fmt = transformer(input_df)
        with open(str(fmt), 'r') as fh:
            obs = fh.readlines()

        self.assertEqual(exp, obs)

    def test_procrustes_m2_stats_fmt_to_df(self):
        filepath = self.get_data_path('m2stats-999-permus.tsv')
        input_fmt = ProcrustesStatisticsFmt(filepath, mode='r')
        exp = pd.DataFrame({'true M^2 value': [0.0789623748362618],
                            'p-value for true M^2 value': [0.001],
                            'number of Monte Carlo permutations': [999]},
                           index=pd.Index(['results'], name='id'))


        transformer = self.get_transformer(ProcrustesStatisticsFmt,