예제 #1
0
    def test_make_study_from_cmd(self):
        fh = StringIO(self.config1)
        load_study_from_cmd('*****@*****.**', 'newstudy', fh)
        sql = ("select study_id from qiita.study where email = %s and "
               "study_title = %s")
        study_id = self.conn_handler.execute_fetchone(sql, ('*****@*****.**',
                                                            'newstudy'))
        self.assertTrue(study_id is not None)

        fh2 = StringIO(self.config2)
        with self.assertRaises(configparser.NoOptionError):
            load_study_from_cmd('*****@*****.**', 'newstudy2', fh2)
예제 #2
0
 def setUp(self):
     self.dm = DistanceMatrix(
         [[0.0, 1.0, 2.0], [1.0, 0.0, 3.0], [2.0, 3.0, 0.0]],
         ['a', 'b', 'c'])
     self.grouping = [1, 2, 1]
     # Ordering of IDs shouldn't matter, nor should extra IDs.
     self.df = pd.read_csv(
         StringIO('ID,Group\nb,Group1\na,Group2\nc,Group1\nd,Group3'),
         index_col=0)
     self.df_missing_id = pd.read_csv(
         StringIO('ID,Group\nb,Group1\nc,Group1'), index_col=0)
     self.categorical_stats = CategoricalStats(self.dm, self.grouping)
     self.categorical_stats_from_df = CategoricalStats(self.dm,
                                                       self.df,
                                                       column='Group')
예제 #3
0
    def setUp(self):
        # Distance matrices with and without ties in the ranks, with 2 groups
        # of equal size.
        dm_ids = ['s1', 's2', 's3', 's4']
        grouping_equal = ['Control', 'Control', 'Fast', 'Fast']
        df = pd.read_csv(StringIO(
            'ID,Group\ns2,Control\ns3,Fast\ns4,Fast\ns5,Control\n'
            's1,Control'),
                         index_col=0)

        self.dm_ties = DistanceMatrix(
            [[0, 1, 1, 4], [1, 0, 3, 2], [1, 3, 0, 3], [4, 2, 3, 0]], dm_ids)

        self.dm_no_ties = DistanceMatrix(
            [[0, 1, 5, 4], [1, 0, 3, 2], [5, 3, 0, 3], [4, 2, 3, 0]], dm_ids)

        # Test with 3 groups of unequal size.
        grouping_unequal = [
            'Control', 'Treatment1', 'Treatment2', 'Treatment1', 'Control',
            'Control'
        ]

        self.dm_unequal = DistanceMatrix(
            [[0.0, 1.0, 0.1, 0.5678, 1.0, 1.0],
             [1.0, 0.0, 0.002, 0.42, 0.998, 0.0],
             [0.1, 0.002, 0.0, 1.0, 0.123, 1.0],
             [0.5678, 0.42, 1.0, 0.0, 0.123, 0.43],
             [1.0, 0.998, 0.123, 0.123, 0.0, 0.5],
             [1.0, 0.0, 1.0, 0.43, 0.5, 0.0]],
            ['s1', 's2', 's3', 's4', 's5', 's6'])

        self.permanova_ties = PERMANOVA(self.dm_ties, grouping_equal)
        self.permanova_no_ties = PERMANOVA(self.dm_no_ties, grouping_equal)
        self.permanova_ties_df = PERMANOVA(self.dm_ties, df, column='Group')
        self.permanova_unequal = PERMANOVA(self.dm_unequal, grouping_unequal)
예제 #4
0
    def test_round_trip_read_write(self):
        """Test reading, writing, and reading again works as expected."""
        for dm_f in self.dm_fs:
            # Read.
            dm1 = DissimilarityMatrix.from_file(dm_f)

            # Write.
            out_f = StringIO()
            dm1.to_file(out_f)
            out_f.seek(0)

            # Read.
            dm2 = DissimilarityMatrix.from_file(out_f)
            self.assertEqual(dm1, dm2)
예제 #5
0
 def test_to_file(self):
     """Should serialize a DissimilarityMatrix to file."""
     for dm_f_line, dm in zip(self.dm_f_lines, self.dms):
         for file_type in ('file like', 'file name'):
             if file_type == 'file like':
                 obs_f = StringIO()
                 dm.to_file(obs_f)
                 obs = obs_f.getvalue()
                 obs_f.close()
             elif file_type == 'file name':
                 with tempfile.NamedTemporaryFile('r+') as temp_file:
                     dm.to_file(temp_file.name)
                     temp_file.flush()
                     temp_file.seek(0)
                     obs = temp_file.read()
             self.assertEqual(obs, dm_f_line)
예제 #6
0
    def test_to_file(self):
        for scores, test_path in zip(self.scores, self.test_paths):
            for file_type in ('file like', 'file name'):
                if file_type == 'file like':
                    obs_f = StringIO()
                    scores.to_file(obs_f)
                    obs = obs_f.getvalue()
                    obs_f.close()
                elif file_type == 'file name':
                    with tempfile.NamedTemporaryFile('r+') as temp_file:
                        scores.to_file(temp_file.name)
                        temp_file.flush()
                        temp_file.seek(0)
                        obs = temp_file.read()

                with open(get_data_path(test_path), 'U') as f:
                    exp = f.read()

                yield npt.assert_equal, obs, exp
예제 #7
0
파일: base.py 프로젝트: sriki18/scikit-bio
    def summary(self, delimiter='\t'):
        """Return a formatted summary of results as a string.

        The string is formatted as delimited text.

        Parameters
        ----------
        delimiter : str, optional
            String to delimit fields by in formatted output. Default is tab
            (TSV).

        Returns
        -------
        str
            Delimited-text summary of results.

        """
        summary = StringIO()
        csv_writer = csv.writer(summary, delimiter=delimiter,
                                lineterminator='\n')
        csv_writer.writerow(self._format_header())
        csv_writer.writerow(self._format_data())
        return summary.getvalue()
예제 #8
0
 def test_from_file(self):
     """Parse a tree from a file"""
     t_io = StringIO("((a,b)c,(d,e)f)g;")
     t = TreeNode.from_file(t_io)
     self.assertEqual(list('abcdefg'), [n.name for n in t.postorder()])
예제 #9
0
    def setUp(self):
        self.bad_dm_fp = get_data_path('bad_dm.txt')
        self.dm_2x2_asym_fp = get_data_path('dm_2x2_asym.txt')
        self.dm_3x3_fp = get_data_path('dm_3x3.txt')

        fd = open(self.bad_dm_fp, 'U')
        self.bad_dm_f2_lines = ''.join(fd.readlines())
        fd.close()
        fd = open(self.dm_2x2_asym_fp, 'U')
        self.dm_2x2_asym_lines = ''.join(fd.readlines())
        fd.close()
        fd = open(self.dm_3x3_fp, 'U')
        self.dm_3x3_lines = ''.join(fd.readlines())
        fd.close()

        self.dm_1x1_data = [[0.0]]
        self.dm_1x1_f = StringIO(DM_1x1_F)

        self.dm_2x2_data = [[0.0, 0.123], [0.123, 0.0]]
        self.dm_2x2_f = StringIO(DM_2x2_F)

        self.dm_2x2_asym_data = [[0.0, 1.0], [-2.0, 0.0]]
        self.dm_2x2_asym_f = StringIO(self.dm_2x2_asym_lines)

        self.dm_3x3_data = [[0.0, 0.01, 4.2], [0.01, 0.0, 12.0],
                            [4.2, 12.0, 0.0]]
        self.dm_3x3_f = StringIO(self.dm_3x3_lines)
        self.dm_3x3_whitespace_f = StringIO('\n'.join(DM_3x3_WHITESPACE_F))

        self.bad_dm_f1 = StringIO(BAD_DM_F1)
        self.bad_dm_f2 = StringIO(self.bad_dm_f2_lines)
        self.bad_dm_f3 = StringIO(BAD_DM_F3)
        self.bad_dm_f4 = StringIO(BAD_DM_F4)
        self.bad_dm_f5 = StringIO(BAD_DM_F5)
        self.bad_dm_f6 = StringIO(BAD_DM_F6)
예제 #10
0
 def test_load_prep_template_from_cmd(self):
     """Correctly adds a sample template to the DB"""
     fh = StringIO(self.pt_contents)
     st = load_prep_template_from_cmd(fh, self.raw_data.id)
     self.assertEqual(st.id, self.raw_data.id)
예제 #11
0
 def test_StringIO(self):
     """StringIO (useful e.g. for testing) slips through."""
     f = StringIO("File contents")
     with open_file(f) as fh:
         self.assertTrue(fh is f)
예제 #12
0
 def test_is_string_or_bytes(self):
     self.assertTrue(_is_string_or_bytes('foo'))
     self.assertTrue(_is_string_or_bytes(u'foo'))
     self.assertTrue(_is_string_or_bytes(b'foo'))
     self.assertFalse(_is_string_or_bytes(StringIO('bar')))
     self.assertFalse(_is_string_or_bytes([1]))
예제 #13
0
 def setUp(self):
     self.fastqs = [StringIO(fastq1), StringIO(fastq2)]
예제 #14
0
    def setUp(self):
        self.fastas = [StringIO(fasta1), StringIO(fasta2), StringIO(fasta3)]
        self.quals = [StringIO(qual1), StringIO(qual2), StringIO(qual3)]

        self.bad_qual_val = [StringIO(qual1), StringIO(qual_bad_val),
                             StringIO(qual3)]
        self.bad_qual_id = [StringIO(qual1), StringIO(qual_bad_id),
                            StringIO(qual3)]
예제 #15
0
 def setUp(self):
     self.qseqs = [StringIO(qseq1), StringIO(qseq2)]