Example #1
0
    def setUp(self):
        """Create MetadataMap objects that will be used in the tests."""
        # Create a map using the overview tutorial mapping file.
        self.overview_map_str = [
                "#SampleID\tBarcodeSequence\tTreatment\tDOB\tDescription",
                "PC.354\tAGCACGAGCCTA\tControl\t20061218\t354",
                "PC.355\tAACTCGTCGATG\tControl\t20061218\t355",
                "PC.356\tACAGACCACTCA\tControl\t20061126\t356",
                "PC.481\tACCAGCGACTAG\tControl\t20070314\t481",
                "PC.593\tAGCAGCACTTGT\tControl\t20071210\t593",
                "PC.607\tAACTGTGCGTAC\tFast\t20071112\t607",
                "PC.634\tACAGAGTCGGCT\tFast\t20080116\t634",
                "PC.635\tACCGCAGAGTCA\tFast\t20080116\t635",
                "PC.636\tACGGTGAGTGTC\tFast\t20080116\t636"]
        self.overview_map = MetadataMap(
            *parse_mapping_file_to_dict(self.overview_map_str))

        # Create the same overview tutorial map, but this time with some
        # comments.
        self.comment = "# Some comments about this mapping file"
        self.map_with_comments_str = self.overview_map_str[:]
        self.map_with_comments_str.insert(1, self.comment)
        self.map_with_comments = MetadataMap(*parse_mapping_file_to_dict(
            self.map_with_comments_str))

        # Create a MetadataMap object that has no metadata (i.e. no sample IDs,
        # so no metadata about samples).
        self.empty_map = MetadataMap({}, [])

        # Create a MetadataMap object that has samples (i.e. sample IDs) but
        # not associated metadata (i.e. no columns other than SampleID).
        self.no_metadata_str = ["#SampleID",
                                "PC.354",
                                "PC.355",
                                "PC.356",
                                "PC.481",
                                "PC.593",
                                "PC.607",
                                "PC.634",
                                "PC.635",
                                "PC.636"]
        self.no_metadata = MetadataMap(*parse_mapping_file_to_dict(
            self.no_metadata_str))

        # Create a MetadataMap object that has a category with only one value
        # throughout the entire column.
        self.single_value_str = ["#SampleID\tFoo",
                                "PC.354\tfoo",
                                "PC.355\tfoo",
                                "PC.356\tfoo",
                                "PC.481\tfoo",
                                "PC.593\tfoo",
                                "PC.607\tfoo",
                                "PC.634\tfoo",
                                "PC.635\tfoo",
                                "PC.636\tfoo"]
        self.single_value = MetadataMap(*parse_mapping_file_to_dict(
            self.single_value_str))
Example #2
0
    def setUp(self):
        """Create MetadataMap objects that will be used in the tests."""
        # Create a map using the overview tutorial mapping file.
        self.overview_map_str = [
            "#SampleID\tBarcodeSequence\tTreatment\tDOB\tDescription",
            "PC.354\tAGCACGAGCCTA\tControl\t20061218\t354",
            "PC.355\tAACTCGTCGATG\tControl\t20061218\t355",
            "PC.356\tACAGACCACTCA\tControl\t20061126\t356",
            "PC.481\tACCAGCGACTAG\tControl\t20070314\t481",
            "PC.593\tAGCAGCACTTGT\tControl\t20071210\t593",
            "PC.607\tAACTGTGCGTAC\tFast\t20071112\t607",
            "PC.634\tACAGAGTCGGCT\tFast\t20080116\t634",
            "PC.635\tACCGCAGAGTCA\tFast\t20080116\t635",
            "PC.636\tACGGTGAGTGTC\tFast\t20080116\t636"
        ]
        self.overview_map = MetadataMap(
            *parse_mapping_file_to_dict(self.overview_map_str))

        # Create the same overview tutorial map, but this time with some
        # comments.
        self.comment = "# Some comments about this mapping file"
        self.map_with_comments_str = self.overview_map_str[:]
        self.map_with_comments_str.insert(1, self.comment)
        self.map_with_comments = MetadataMap(
            *parse_mapping_file_to_dict(self.map_with_comments_str))

        # Create a MetadataMap object that has no metadata (i.e. no sample IDs,
        # so no metadata about samples).
        self.empty_map = MetadataMap({}, [])

        # Create a MetadataMap object that has samples (i.e. sample IDs) but
        # not associated metadata (i.e. no columns other than SampleID).
        self.no_metadata_str = [
            "#SampleID", "PC.354", "PC.355", "PC.356", "PC.481", "PC.593",
            "PC.607", "PC.634", "PC.635", "PC.636"
        ]
        self.no_metadata = MetadataMap(
            *parse_mapping_file_to_dict(self.no_metadata_str))

        # Create a MetadataMap object that has a category with only one value
        # throughout the entire column.
        self.single_value_str = [
            "#SampleID\tFoo", "PC.354\tfoo", "PC.355\tfoo", "PC.356\tfoo",
            "PC.481\tfoo", "PC.593\tfoo", "PC.607\tfoo", "PC.634\tfoo",
            "PC.635\tfoo", "PC.636\tfoo"
        ]
        self.single_value = MetadataMap(
            *parse_mapping_file_to_dict(self.single_value_str))
 def test_parse_mapping_file_to_dict(self):
     """parse_mapping_file functions as expected"""
     s1 = ["#sample\ta\tb", "#comment line to skip", "x \t y \t z ", " ", "#more skip", "i\tj\tk"]
     exp = ([["x", "y", "z"], ["i", "j", "k"]], ["sample", "a", "b"], ["comment line to skip", "more skip"])
     mapdict, comments = parse_mapping_file_to_dict(s1)
     expdict = {"x": {"a": "y", "b": "z"}, "i": {"a": "j", "b": "k"}}
     self.assertEqual(mapdict, expdict)
     self.assertEqual(comments, ["comment line to skip", "more skip"])
Example #4
0
 def test_parse_mapping_file_to_dict(self):
     """parse_mapping_file functions as expected"""
     s1 = ['#sample\ta\tb', '#comment line to skip',\
           'x \t y \t z ', ' ', '#more skip', 'i\tj\tk']
     exp = ([['x','y','z'],['i','j','k']],\
            ['sample','a','b'],\
            ['comment line to skip','more skip'])
     mapdict, comments = parse_mapping_file_to_dict(s1)
     expdict = {'x': {'a': 'y', 'b': 'z'}, 'i': {'a': 'j', 'b': 'k'}}
     self.assertEqual(mapdict, expdict)
     self.assertEqual(comments, ['comment line to skip', 'more skip'])
Example #5
0
    def parseMetadataMap(lines):
        """Parses a QIIME metadata mapping file into a MetadataMap object.

        This static method is basically a factory that reads in the given
        metadata mapping file contents and returns a MetadataMap instance. This
        method is provided for convenience.

        Arguments:
            lines - a list of strings representing the file contents of a QIIME
                metadata mapping file
        """
        return MetadataMap(*parse_mapping_file_to_dict(lines))
Example #6
0
    def parseMetadataMap(lines):
        """Parses a QIIME metadata mapping file into a MetadataMap object.

        This static method is basically a factory that reads in the given
        metadata mapping file contents and returns a MetadataMap instance. This
        method is provided for convenience.

        Arguments:
            lines - a list of strings representing the file contents of a QIIME
                metadata mapping file
        """
        return MetadataMap(*parse_mapping_file_to_dict(lines))