Exemple #1
0
    def check_salmon_quant(self, job_context, sample_dir):
        """Helper function that calls salmon._run_salmon and confirms
        strong correlation.
        """
        # Clean up if there were previous tests, but we still need that directory.
        shutil.rmtree(job_context['output_directory'], ignore_errors=True)
        os.makedirs(job_context["output_directory"], exist_ok=True)
        job_context = salmon._determine_index_length(job_context)
        job_context = salmon._find_or_download_index(job_context)

        # This is a brittle/hacky patch.
        # However I am unsure why the double_reads reads are
        # determined to be short but require a long index to be
        # processed successfully.
        if "test_experiment" in sample_dir:
            job_context["index_directory"] = job_context["index_directory"].replace("SHORT", "LONG")

        job_context = salmon._run_salmon(job_context)
        job_context = salmon.get_tximport_inputs(job_context)
        job_context = salmon.tximport(job_context)
        output_quant_filename = os.path.join(job_context['output_directory'], 'quant.sf')
        self.assertTrue(os.path.exists(output_quant_filename))

        # Confirm strong correlation between the new "quant.sf" and reference file
        ref_quant_filename = os.path.join(sample_dir, 'ref_files/quant.sf')
        self.assertTrue(strong_quant_correlation(ref_quant_filename, output_quant_filename))
Exemple #2
0
    def test_salmon_determine_index_length_double_read(self):
        """Test that the right length is calculated when the sample has two reads."""
        job, files = prepare_job()

        job_context = salmon._set_job_prefix({'original_files': files,
                                              'job_id': job})
        job_context = salmon._prepare_files(job_context)
        results = salmon._determine_index_length(job_context)

        self.assertEqual(results['index_length_raw'], 41)
        self.assertEqual(results['index_length'], 'short')
Exemple #3
0
    def test_success(self):
        """Tests the successful path of the module under test."""
        logger.info("STARTING SALMON SUCCESS TEST!!!!!!!!")
        # Set up test environment.
        batch, first_file, second_file = init_objects()
        _insert_salmon_index()
        # Change the batch/files to point to test-specific locations
        batch.platform_accession_code = "TEST"
        batch.save()
        first_file.internal_location = "TEST/SALMON"
        first_file.save()
        second_file.internal_location = "TEST/SALMON"
        second_file.save()

        processor_job = ProcessorJob.create_job_and_relationships(
            batches=[batch])
        processor_job.save()
        job_context = utils.start_job({
            "job": processor_job,
            "job_id": processor_job.id
        })
        job_context = salmon._set_job_prefix(job_context)

        # Ensure temp dir isn't leftover from a previous test.
        temp_dir = first_file.get_temp_dir(job_context["job_dir_prefix"])
        shutil.rmtree(temp_dir, ignore_errors=True)

        # One of the functions being tested:
        job_context = salmon._prepare_files(job_context)

        input_file_path = job_context["input_file_path"]
        self.assertIsInstance(input_file_path, str)
        self.assertTrue(os.path.isfile(input_file_path))
        input_file_path_2 = job_context["input_file_path_2"]
        self.assertIsInstance(input_file_path_2, str)
        self.assertTrue(os.path.isfile(input_file_path_2))
        output_directory_path = job_context["output_directory"]
        self.assertIsInstance(output_directory_path, str)
        self.assertTrue(os.path.isdir(output_directory_path))

        job_context = salmon._determine_index_length(job_context)

        # The 'kmer_size' key has been added to job_context with the
        # correct value.
        self.assertEqual(job_context["kmer_size"], "23")

        # Another function being tested
        job_context = salmon._download_index(job_context)

        self.assertTrue(job_context["success"])
        self.assertTrue("index_directory" in job_context)
        self.assertTrue(os.path.isdir(job_context["index_directory"]))
        self.assertEqual(9, len(os.listdir(job_context["index_directory"])))

        # Another function being tested
        job_context = salmon._run_salmon(job_context)

        self.assertTrue(job_context["success"])
        self.assertGreater(len(os.listdir(output_directory_path)), 1)

        # The last function to test
        job_context = salmon._zip_and_upload(job_context)

        self.assertTrue(job_context["success"])
        self.assertTrue(os.path.exists(first_file.get_processed_path()))

        # Clean up both input and output files
        first_file.remove_temp_directory()
        shutil.rmtree(first_file.get_processed_dir())
        logger.info("ENDING SALMON SUCCESS TEST!!!!!!!!")