Exemplo n.º 1
0
async def fetch_cache(cache_document: Dict[str, Any], cache_path: Path,
                      reads_path: Path, run_in_executor: FunctionExecutor):
    """Copy cached read files to the reads_path."""
    cached_read_paths = utils.make_read_paths(reads_dir_path=cache_path /
                                              cache_document["_id"],
                                              paired=cache_document["paired"])

    await copy_paths(
        {path: reads_path / path.name
         for path in cached_read_paths}.items(), run_in_executor)
Exemplo n.º 2
0
async def test_correct_fastqc(tmpdir, run_subprocess, run_in_executor,
                              data_regression, analysis_files):
    work_path = Path(tmpdir)
    run = fastqc(work_path, run_subprocess)

    await run_in_executor(shutil.copyfile,
                          analysis_files / "paired_small_1.fq.gz",
                          work_path / "reads_1.fq.gz")
    await run_in_executor(shutil.copyfile,
                          analysis_files / "paired_small_2.fq.gz",
                          work_path / "reads_2.fq.gz")

    out = await run(make_read_paths(work_path, True))

    data_regression.check(out)
Exemplo n.º 3
0
async def sample(sample_provider: AbstractSampleProvider,
                 work_path: Path) -> Sample:
    """
    The sample associated with the current job.

    Returns a :class:`.Sample` object.

    """
    read_path = work_path / "reads"
    read_path.mkdir()

    sample_ = await sample_provider.get()
    await sample_provider.download_reads(read_path, sample_.paired)
    sample_.reads_path = read_path
    sample_.read_paths = make_read_paths(read_path, sample_.paired)
    return sample_
Exemplo n.º 4
0
async def trimming_input_paths(
        analysis_args: analysis_info.AnalysisArguments,
        run_in_executor: FunctionExecutor) -> utils.ReadPaths:
    """Copy sample data to raw_path and read_paths and return the read_paths."""
    sample_paths = utils.make_read_paths(analysis_args.sample_path,
                                         analysis_args.paired)
    raw_read_paths = {
        path: analysis_args.raw_path / path.name
        for path in sample_paths
    }
    await copy_paths(raw_read_paths.items(), run_in_executor)

    await copy_paths(zip(sample_paths, analysis_args.read_paths),
                     run_in_executor)

    return analysis_args.read_paths
Exemplo n.º 5
0
    def __fixture__(data_path: Path, temp_path: Path,
                    analysis_info: AnalysisInfo) -> "AnalysisArguments":
        """Initialize directory structure for analysis workflows."""
        (sample_id, analysis_id, ref_id, index_id, sample,
         analysis_) = astuple(analysis_info)

        subtraction_id = analysis_["subtraction"]["id"].replace(" ",
                                                                "_").lower()
        subtraction_path = data_path / "subtractions" / subtraction_id / "reference"
        sample_path = data_path / "samples" / sample_id
        reads_path = temp_path / "reads"
        paired = sample["paired"]
        read_paths = utils.make_read_paths(reads_path, paired)

        temp_cache_path = temp_path / "cache"

        args = AnalysisArguments(
            path=sample_path / "analysis" / analysis_id,
            sample_path=sample_path,
            index_path=data_path / "references" / ref_id / index_id /
            "reference",
            reads_path=reads_path,
            read_paths=read_paths,
            subtraction_path=subtraction_path,
            raw_path=temp_path / "raw",
            temp_cache_path=temp_cache_path,
            temp_analysis_path=temp_path / analysis_id,
            paired=sample["paired"],
            read_count=int(sample["quality"]["count"]),
            sample_read_length=int(sample["quality"]["length"][1]),
            library_type=sample["library_type"],
            sample=sample,
            analysis=analysis_,
            sample_id=sample_id,
            analysis_id=analysis_id,
            ref_id=ref_id,
            index_id=index_id,
        )

        for path in [path for path in astuple(args) if isinstance(path, Path)]:
            path.mkdir(parents=True, exist_ok=True)

        return args
Exemplo n.º 6
0
    async def download_reads(self,
                             target_path: Path,
                             paired: bool = None) -> ReadPaths:
        if paired is None:
            sample = await self.get()
            paired = sample.paired

        async with self.http.get(
                f"{self.url}/reads/reads_1.fq.gz") as response:
            await read_file_from_response(response,
                                          target_path / "reads_1.fq.gz")

        if paired:
            async with self.http.get(
                    f"{self.url}/reads/reads_2.fq.gz") as response:
                await read_file_from_response(response,
                                              target_path / "reads_2.fq.gz")

        return make_read_paths(target_path, paired)
Exemplo n.º 7
0
async def parsed_fastqc(
        trimming_output: Tuple[Path, str],
        analysis_args: AnalysisArguments,
        number_of_processes: int,
) -> Dict[str, Any]:
    """
    The parsed output from fastqc.

    To be executed after the reads have been trimmed.
    """
    trimming_output_path, _ = trimming_output

    rename_trimming_results(trimming_output_path)

    read_paths = utils.make_read_paths(trimming_output_path, analysis_args.paired)

    fastqc_path = analysis_args.temp_cache_path/"fastqc"
    fastqc_path.mkdir()

    await fastqc.run_fastqc(number_of_processes, read_paths, fastqc_path)

    return fastqc.parse_fastqc(fastqc_path, analysis_args.sample_path)