Ejemplo n.º 1
0
                    metavar = "filename",
                    help = "[REQUIRED] outfile name",
                    required = True)
options = parser.parse_args()

#############################
# Import json formatted OTU #
#############################

import json
jsondata = open(options.biominputfile)
biom = json.load(jsondata)
jsondata.close()

from biom import Table
table = Table.from_json(biom)

print("")
print("Original OTU Table (without taxonomy)")
print("-------------------------------------")
print("")
print(table)
print("")

min_samplesize = int(min(table.sum(axis='sample')))
print("Subsampling to the smallest sample size: " + str(min_samplesize))

# Subsample
table_ss = table.subsample(min_samplesize)

# Output
    def setUpClass(cls):
        _table1 = [
            'a\ta\t1\t0.0\t0.5\t0.1', 'a\ta\t1\t1.0\t1.0\t0.2',
            'a\ta\t1\t2.0\t1.5\t0.2', 'a\tb\t1\t3.0\t2.0\t8.',
            'a\tb\t1\t4.0\t2.5\t9.', 'a\tb\t1\t5.0\t3.0\t10.',
            'b\ta\t1\t0.0\t2.0\t0.1', 'b\ta\t1\t1.0\t3.0\t0.3',
            'b\ta\t1\t2.0\t4.0\t0.1', 'b\tb\t1\t3.0\t5.0\t9.',
            'b\tb\t1\t4.0\t6.0\t11.', 'b\tb\t1\t5.0\t7.0\t10.'
        ]

        cls.table1 = pd.DataFrame(
            [(n.split('\t')) for n in _table1],
            columns=['group', 'dataset', 'level', 'x', 'y', 'c'],
            dtype=float)

        cls.table2 = """{"id": "None",
                          "format": "Biological Observation Matrix 1.0.0",
                          "format_url": "http:\/\/biom-format.org",
                          "type": "OTU table",
                          "generated_by": "greg",
                          "date": "2013-08-22T13:10:23.907145",
                          "matrix_type": "sparse",
                          "matrix_element_type": "float",
                          "shape": [
                            3,
                            4
                          ],
                          "data": [
                            [
                              0,
                              0,
                              1
                            ],
                            [
                              0,
                              1,
                              2
                            ],
                            [
                              0,
                              2,
                              3
                            ],
                            [
                              0,
                              3,
                              4
                            ],
                            [
                              1,
                              0,
                              2
                            ],
                            [
                              1,
                              1,
                              0
                            ],
                            [
                              1,
                              2,
                              7
                            ],
                            [
                              1,
                              3,
                              8
                            ],
                            [
                              2,
                              0,
                              9
                            ],
                            [
                              2,
                              1,
                              10
                            ],
                            [
                              2,
                              2,
                              11
                            ],
                            [
                              2,
                              3,
                              12
                            ]
                          ],
                          "rows": [
                            {
                              "id": "o1",
                              "metadata": {
                                "domain": "Archaea"
                              }
                            },
                            {
                              "id": "o2",
                              "metadata": {
                                "domain": "Bacteria"
                              }
                            },
                            {
                              "id": "o3",
                              "metadata": {
                                "domain": "Bacteria"
                              }
                            }
                          ],
                          "columns": [
                            {
                              "id": "s1",
                              "metadata": {
                                "method": "A",
                                "Sample": "A",
                                "parameters": "A"
                              }
                            },
                            {
                              "id": "s2",
                              "metadata": {
                                "method": "A",
                                "Sample": "A",
                                "parameters": "B"
                              }
                            },
                            {
                              "id": "s3",
                              "metadata": {
                                "method": "A",
                                "Sample": "A",
                                "parameters": "C"
                              }
                            },
                            {
                              "id": "s4",
                              "metadata": {
                                "method": "B",
                                "Sample": "A",
                                "parameters": "D"
                              }
                            }
                          ]
                        }"""
        # table 2
        # OTU ID	s1	s2	s3	s4
        # o1    1.0 2.0 3.0 4.0
        # o2    2.0 0.0 7.0 8.0
        # o3    9.0 10.0    11.0    12.0

        cls.tmpdir = mkdtemp()
        cls.table2 = Table.from_json(json.loads(cls.table2))
        write_biom_table(cls.table2, 'hdf5', join(cls.tmpdir, 'table2.biom'))
        cls.dm, cls.s_md = make_distance_matrix(join(cls.tmpdir,
                                                     'table2.biom'),
                                                method="braycurtis")
        cls.dist = per_method_distance(cls.dm,
                                       cls.s_md,
                                       group_by='method',
                                       standard='B',
                                       metric='distance',
                                       sample='Sample')
Ejemplo n.º 3
0
                    metavar="filename",
                    help="[REQUIRED] outfile name",
                    required=True)
options = parser.parse_args()

#############################
# Import json formatted OTU #
#############################

import json
jsondata = open(options.biominputfile)
biom = json.load(jsondata)
jsondata.close()

from biom import Table
table = Table.from_json(biom)

print("")
print("Original OTU Table (without taxonomy)")
print("-------------------------------------")
print("")
print(table)
print("")

min_samplesize = int(min(table.sum(axis='sample')))
print("Subsampling to the smallest sample size: " + str(min_samplesize))

# Subsample
table_ss = table.subsample(min_samplesize)

# Output
    def setUp(self):
        self.table1 = Table.from_json(json.load(StringIO(table1)))
        self.table2 = Table.from_json(json.load(StringIO(table2)))
        self.table3 = Table.from_json(json.load(StringIO(table3)))

        self.mock_result_table1 = pd.DataFrame.from_csv(StringIO(mock_result_table1))
Ejemplo n.º 5
0
    def setUp(self):
        _table1 = """{"id": "None",
                      "format": "Biological Observation Matrix 1.0.0",
                      "format_url": "http://biom-format.org",
                      "type": "OTU table",
                      "generated_by": "greg",
                      "date": "2013-08-22T13:10:23.907145",
                      "matrix_type": "sparse",
                      "matrix_element_type": "float",
                      "shape": [
                        3,
                        4
                      ],
                      "data": [
                        [
                          0,
                          0,
                          1
                        ],
                        [
                          0,
                          1,
                          2
                        ],
                        [
                          0,
                          2,
                          3
                        ],
                        [
                          0,
                          3,
                          4
                        ],
                        [
                          1,
                          0,
                          2
                        ],
                        [
                          1,
                          1,
                          0
                        ],
                        [
                          1,
                          2,
                          7
                        ],
                        [
                          1,
                          3,
                          8
                        ],
                        [
                          2,
                          0,
                          9
                        ],
                        [
                          2,
                          1,
                          10
                        ],
                        [
                          2,
                          2,
                          11
                        ],
                        [
                          2,
                          3,
                          12
                        ]
                      ],
                      "rows": [
                        {
                          "id": "k__Bacteria",
                          "metadata": {
                            "domain": "Bacteria"
                          }
                        },
                        {
                          "id": "k__Archaea",
                          "metadata": {
                            "domain": "Archaea"
                          }
                        },
                        {
                          "id": "k__[Fungi]",
                          "metadata": {
                            "domain": "[Fungi]"
                          }
                        }
                      ],
                      "columns": [
                        {
                          "id": "s1",
                          "metadata": {
                            "country": "Peru",
                            "pH": 4.2
                          }
                        },
                        {
                          "id": "s2",
                          "metadata": {
                            "country": "Peru",
                            "pH": 5.2
                          }
                        },
                        {
                          "id": "s3",
                          "metadata": {
                            "country": "Peru",
                            "pH": 5
                          }
                        },
                        {
                          "id": "s4",
                          "metadata": {
                            "country": "Peru",
                            "pH": 4.9
                          }
                        }
                      ]
                    }"""
        # table 1
        # OTU ID	   s1	s2	s3	s4
        # k__Archaea    1.0 2.0 3.0 4.0
        # k__Bacteria    2.0 0.0 7.0 8.0
        # k__[Fungi]    9.0 10.0    11.0    12.0

        self.table1 = Table.from_json(json.loads(_table1))
 def setUp(self):
     self.table1 = Table.from_json(json.load(StringIO(table1)))
     self.table2 = Table.from_json(json.load(StringIO(table2)))