def test_validate_SFF(self):
        prep_info = {"1.SKB2.640194": {"run_prefix": "GAX40"},
                     "1.SKM4.640180": {"run_prefix": "GAX40"},
                     "1.SKB3.640195": {"run_prefix": "GAX50"}}
        files = {'raw_sff': ['/path/to/GAX401.sff', '/path/to/GAX402.sff',
                             '/path/to/GAX501.sff']}
        job_id = self._create_template_and_job(prep_info, files, "SFF")
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, 'SFF')
        self.assertTrue(obs_success)
        filepaths = [('/path/to/GAX401.sff', 'raw_sff'),
                     ('/path/to/GAX402.sff', 'raw_sff'),
                     ('/path/to/GAX501.sff', 'raw_sff')]
        exp = [ArtifactInfo(None, "SFF", filepaths)]
        self.assertEqual(obs_ainfo, exp)
        self.assertEqual(obs_error, "")

        # let's test a failure
        files = {'raw_sff': ['/path/to/GAX401.sff', '/path/to/GAX402.sff']}
        job_id = self._create_template_and_job(prep_info, files, "SFF")
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, 'SFF')
        error = ("Error creating artifact. Offending files:\nraw_sff: The "
                 "following run prefixes in the prep information file do not "
                 "match any file: GAX50")
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertItemsEqual(obs_error, error)
    def test_validate_multiple_single_lane(self):
        prep_info = {
            "1.SKB2.640194": {
                "not_a_run_prefix": "prefix1"
            },
            "1.SKM4.640180": {
                "not_a_run_prefix": "prefix1"
            },
            "1.SKB3.640195": {
                "not_a_run_prefix": "prefix2"
            }
        }
        files = {
            'raw_forward_seqs': ['/path/to/prefix1.fastq'],
            'raw_barcodes': ['/path/to/prefix1_b.fastq']
        }
        atype = "FASTQ"
        job_id = self._create_template_and_job(prep_info, files, atype)

        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)

        self.assertTrue(obs_success)
        filepaths = [('/path/to/prefix1_b.fastq', 'raw_barcodes'),
                     ('/path/to/prefix1.fastq', 'raw_forward_seqs')]
        exp = [ArtifactInfo(None, atype, filepaths)]
        self.assertEqual(obs_ainfo, exp)
        self.assertEqual(obs_error, "")
    def test_validate_multiple(self):
        prep_info = {
            '1.SKB2.640194': {
                'run_prefix': 'prefix1'
            },
            '1.SKM4.640180': {
                'run_prefix': 'prefix1'
            },
            '1.SKB3.640195': {
                'run_prefix': 'prefix2'
            }
        }
        files = {
            'raw_forward_seqs':
            ['/path/to/prefix1.fastq', '/path/to/prefix2.fastq'],
            'raw_barcodes':
            ['/path/to/prefix1_b.fastq', '/path/to/prefix2_b.fastq']
        }
        atype = "FASTQ"
        job_id = self._create_template_and_job(prep_info, files, atype)

        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)

        self.assertTrue(obs_success)
        filepaths = [('/path/to/prefix1_b.fastq', 'raw_barcodes'),
                     ('/path/to/prefix2_b.fastq', 'raw_barcodes'),
                     ('/path/to/prefix1.fastq', 'raw_forward_seqs'),
                     ('/path/to/prefix2.fastq', 'raw_forward_seqs')]
        exp = [ArtifactInfo(None, "FASTQ", filepaths)]
        self.assertEqual(obs_ainfo, exp)
        self.assertEqual(obs_error, "")
    def test_validate_SFF(self):
        prep_info = {
            "1.SKB2.640194": {
                "run_prefix": "GAX40"
            },
            "1.SKM4.640180": {
                "run_prefix": "GAX40"
            },
            "1.SKB3.640195": {
                "run_prefix": "GAX50"
            }
        }
        files = {
            'raw_sff': [
                '/path/to/GAX401.sff', '/path/to/GAX402.sff',
                '/path/to/GAX501.sff'
            ]
        }
        job_id = self._create_template_and_job(prep_info, files, "SFF")
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, 'SFF')
        self.assertTrue(obs_success)
        filepaths = [('/path/to/GAX401.sff', 'raw_sff'),
                     ('/path/to/GAX402.sff', 'raw_sff'),
                     ('/path/to/GAX501.sff', 'raw_sff')]
        exp = [ArtifactInfo(None, "SFF", filepaths)]
        self.assertEqual(obs_ainfo, exp)
        self.assertEqual(obs_error, "")

        # let's test a failure
        files = {'raw_sff': ['/path/to/GAX401.sff', '/path/to/GAX402.sff']}
        job_id = self._create_template_and_job(prep_info, files, "SFF")
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, 'SFF')
        error = ("Error creating artifact. Offending files:\nraw_sff: The "
                 "following run prefixes in the prep information file do not "
                 "match any file: GAX50")
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertItemsEqual(obs_error, error)
    def test_validate_multiple_single_lane(self):
        prep_info = {"1.SKB2.640194": {"not_a_run_prefix": "prefix1"},
                     "1.SKM4.640180": {"not_a_run_prefix": "prefix1"},
                     "1.SKB3.640195": {"not_a_run_prefix": "prefix2"}}
        files = {'raw_forward_seqs': ['/path/to/prefix1.fastq'],
                 'raw_barcodes': ['/path/to/prefix1_b.fastq']}
        atype = "FASTQ"
        job_id = self._create_template_and_job(prep_info, files, atype)

        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)

        self.assertTrue(obs_success)
        filepaths = [
            ('/path/to/prefix1_b.fastq', 'raw_barcodes'),
            ('/path/to/prefix1.fastq', 'raw_forward_seqs')]
        exp = [ArtifactInfo(None, atype, filepaths)]
        self.assertEqual(obs_ainfo, exp)
        self.assertEqual(obs_error, "")
    def test_validate_multiple(self):
        prep_info = {
            '1.SKB2.640194': {'run_prefix': 'prefix1'},
            '1.SKM4.640180': {'run_prefix': 'prefix1'},
            '1.SKB3.640195': {'run_prefix': 'prefix2'}}
        files = {'raw_forward_seqs': ['/path/to/prefix1.fastq',
                                      '/path/to/prefix2.fastq'],
                 'raw_barcodes': ['/path/to/prefix1_b.fastq',
                                  '/path/to/prefix2_b.fastq']}
        atype = "FASTQ"
        job_id = self._create_template_and_job(prep_info, files, atype)

        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)

        self.assertTrue(obs_success)
        filepaths = [
            ('/path/to/prefix1_b.fastq', 'raw_barcodes'),
            ('/path/to/prefix2_b.fastq', 'raw_barcodes'),
            ('/path/to/prefix1.fastq', 'raw_forward_seqs'),
            ('/path/to/prefix2.fastq', 'raw_forward_seqs')]
        exp = [ArtifactInfo(None, "FASTQ", filepaths)]
        self.assertEqual(obs_ainfo, exp)
        self.assertEqual(obs_error, "")
    def test_validate_multiple_error(self):
        # Filepath type not supported
        prep_info = {"1.SKB2.640194": {"run_prefix": "prefix1"},
                     "1.SKM4.640180": {"run_prefix": "prefix1"},
                     "1.SKB3.640195": {"run_prefix": "prefix2"}}
        files = {'Unknown': ['/path/to/file1.fastq']}
        atype = "FASTQ"
        job_id = self._create_template_and_job(prep_info, files, atype)
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertEqual(obs_error,
                         "Filepath type(s) Unknown not supported by artifact "
                         "type FASTQ. Supported filepath types: raw_barcodes, "
                         "raw_forward_seqs, raw_reverse_seqs")

        # Number of provided files != Num run prefix values
        files = {'raw_forward_seqs': ['/path/to/file1.fastq'],
                 'raw_barcodes': ['/path/to/file1_b.fastq',
                                  '/path/to/file2_b.fastq',
                                  '/path/to/file3_b.fastq']}
        job_id = self._create_template_and_job(prep_info, files, atype)
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)
        error = ("Error creating artifact. Offending files:\nraw_forward_seqs:"
                 " The number of provided files (1) doesn't match the number "
                 "of run prefix values in the prep info (2): file1.fastq\n"
                 "raw_barcodes: The number of provided files (3) doesn't "
                 "match the number of run prefix values in the prep info (2): "
                 "file1_b.fastq, file2_b.fastq, file3_b.fastq")
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertItemsEqual(obs_error.split('\n'), error.split('\n'))

        # File doesn't match any run prefix
        files = {'raw_forward_seqs': ['/path/to/file1.fastq',
                                      '/path/to/prefix2.fastq'],
                 'raw_barcodes': ['/path/to/file1_b.fastq',
                                  '/path/to/prefix2_b.fastq']}
        job_id = self._create_template_and_job(prep_info, files, atype)
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)
        error = ("Error creating artifact. Offending files:\nraw_forward_seqs:"
                 " The provided files do not match the run prefix values in "
                 "the prep information: file1.fastq\n"
                 "raw_barcodes: The provided files do not match the run "
                 "prefix values in the prep information: file1_b.fastq")
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertItemsEqual(obs_error.split('\n'), error.split('\n'))

        # A required filepath type is missing
        files = {'raw_forward_seqs': ['/path/to/prefix1.fastq',
                                      '/path/to/prefix2.fastq'],
                 'raw_reverse_seqs': ['/path/to/prefix1_rev.fastq',
                                      '/path/to/prefix2_rev.fastq']}
        job_id = self._create_template_and_job(prep_info, files, atype)
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertEqual(obs_error,
                         "Missing required filepath type(s): raw_barcodes")

        # No run prefix and more than 1 lane
        prep_info = {"1.SKB2.640194": {"not_a_run_prefix": "prefix1"},
                     "1.SKM4.640180": {"not_a_run_prefix": "prefix1"},
                     "1.SKB3.640195": {"not_a_run_prefix": "prefix2"}}
        files = {'raw_forward_seqs': ['/path/to/prefix1.fastq',
                                      '/path/to/prefix2.fastq'],
                 'raw_barcodes': ['/path/to/prefix1_b.fastq',
                                  '/path/to/prefix2_b.fastq']}
        job_id = self._create_template_and_job(prep_info, files, atype)
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)
        error = ("Error creating artifact. Offending files:\nraw_forward_seqs:"
                 " Only one file per type is allowed. Please provide the "
                 "column 'run_prefix' if you need more than one file per "
                 "type: prefix1.fastq, prefix2.fastq\n"
                 "raw_barcodes: Only one file per type is allowed. Please "
                 "provide the column 'run_prefix' if you need more than one "
                 "file per type: prefix1_b.fastq, prefix2_b.fastq")
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertItemsEqual(obs_error.split('\n'), error.split('\n'))
    def test_validate_multiple_error(self):
        # Filepath type not supported
        prep_info = {
            "1.SKB2.640194": {
                "run_prefix": "prefix1"
            },
            "1.SKM4.640180": {
                "run_prefix": "prefix1"
            },
            "1.SKB3.640195": {
                "run_prefix": "prefix2"
            }
        }
        files = {'Unknown': ['/path/to/file1.fastq']}
        atype = "FASTQ"
        job_id = self._create_template_and_job(prep_info, files, atype)
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertEqual(
            obs_error, "Filepath type(s) Unknown not supported by artifact "
            "type FASTQ. Supported filepath types: raw_barcodes, "
            "raw_forward_seqs, raw_reverse_seqs")

        # Number of provided files != Num run prefix values
        files = {
            'raw_forward_seqs': ['/path/to/file1.fastq'],
            'raw_barcodes': [
                '/path/to/file1_b.fastq', '/path/to/file2_b.fastq',
                '/path/to/file3_b.fastq'
            ]
        }
        job_id = self._create_template_and_job(prep_info, files, atype)
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)
        error = ("Error creating artifact. Offending files:\nraw_forward_seqs:"
                 " The number of provided files (1) doesn't match the number "
                 "of run prefix values in the prep info (2): file1.fastq\n"
                 "raw_barcodes: The number of provided files (3) doesn't "
                 "match the number of run prefix values in the prep info (2): "
                 "file1_b.fastq, file2_b.fastq, file3_b.fastq")
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertItemsEqual(obs_error.split('\n'), error.split('\n'))

        # File doesn't match any run prefix
        files = {
            'raw_forward_seqs':
            ['/path/to/file1.fastq', '/path/to/prefix2.fastq'],
            'raw_barcodes':
            ['/path/to/file1_b.fastq', '/path/to/prefix2_b.fastq']
        }
        job_id = self._create_template_and_job(prep_info, files, atype)
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)
        error = ("Error creating artifact. Offending files:\nraw_forward_seqs:"
                 " The provided files do not match the run prefix values in "
                 "the prep information: file1.fastq\n"
                 "raw_barcodes: The provided files do not match the run "
                 "prefix values in the prep information: file1_b.fastq")
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertItemsEqual(obs_error.split('\n'), error.split('\n'))

        # A required filepath type is missing
        files = {
            'raw_forward_seqs':
            ['/path/to/prefix1.fastq', '/path/to/prefix2.fastq'],
            'raw_reverse_seqs':
            ['/path/to/prefix1_rev.fastq', '/path/to/prefix2_rev.fastq']
        }
        job_id = self._create_template_and_job(prep_info, files, atype)
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertEqual(obs_error,
                         "Missing required filepath type(s): raw_barcodes")

        # No run prefix and more than 1 lane
        prep_info = {
            "1.SKB2.640194": {
                "not_a_run_prefix": "prefix1"
            },
            "1.SKM4.640180": {
                "not_a_run_prefix": "prefix1"
            },
            "1.SKB3.640195": {
                "not_a_run_prefix": "prefix2"
            }
        }
        files = {
            'raw_forward_seqs':
            ['/path/to/prefix1.fastq', '/path/to/prefix2.fastq'],
            'raw_barcodes':
            ['/path/to/prefix1_b.fastq', '/path/to/prefix2_b.fastq']
        }
        job_id = self._create_template_and_job(prep_info, files, atype)
        obs_success, obs_ainfo, obs_error = _validate_multiple(
            self.qclient, job_id, prep_info, files, atype)
        error = ("Error creating artifact. Offending files:\nraw_forward_seqs:"
                 " Only one file per type is allowed. Please provide the "
                 "column 'run_prefix' if you need more than one file per "
                 "type: prefix1.fastq, prefix2.fastq\n"
                 "raw_barcodes: Only one file per type is allowed. Please "
                 "provide the column 'run_prefix' if you need more than one "
                 "file per type: prefix1_b.fastq, prefix2_b.fastq")
        self.assertFalse(obs_success)
        self.assertIsNone(obs_ainfo)
        self.assertItemsEqual(obs_error.split('\n'), error.split('\n'))