<commit_before>"""
The alignment pipeline.

We start with the .fastq files and the reference for a particular genome
and carry out the gauntlet of steps to perform alignments, alignment
cleaning, snv calling, and effect prediction.
"""

from datetime import datetime

from celery import chord
from celery import group
from celery import task
from django.conf import settings

from main.celery_util import assert_celery_running
from main.models import AlignmentGroup
from main.models import ReferenceGenome
from main.models import Dataset
from main.models import ExperimentSampleToAlignment
from pipeline.read_alignment import align_with_bwa_mem
from pipeline.variant_calling import find_variants_with_tool
from pipeline.variant_calling import VARIANT_TOOL_PARAMS_MAP
from pipeline.variant_calling.freebayes import merge_freebayes_parallel
from pipeline.variant_calling.freebayes import freebayes_regions


# List of variant callers to use. At time of writing, this was not hooked
# up to the ui and only used internally.
VARIANT_CALLING_OPTION__CALLER_OVERRIDE = 'enabled_variant_callers_override'


def run_pipeline(alignment_group_label, ref_genome, sample_list,
        skip_alignment=True, perform_variant_calling=True, alignment_options={},
        variant_calling_options={}):
    """Runs the entire bioinformatics pipeline, including alignment and
    variant calling.

    Steps:
        * Create AlignmentGroup if not created
        * get_or_create ExperimentSampleToAlignments and respective Datasets
        * Kick off alignments
        * When all alignments are done, kick off variant calling

    Args:
        alignment_group_label: Name for this alignment.
        ref_genome: ReferenceGenome instance
        sample_list: List of sample instances. Must belong to same project as
            ReferenceGenomes.
        skip_alignment: If True, skip alignment.
        perform_variant_calling: Whether to run variant calling.<commit_msg>skip_alignment should be False by default.<commit_after>"""
The alignment pipeline.

We start with the .fastq files and the reference for a particular genome
and carry out the gauntlet of steps to perform alignments, alignment
cleaning, snv calling, and effect prediction.
"""

from datetime import datetime

from celery import chord
from celery import group
from celery import task
from django.conf import settings

from main.celery_util import assert_celery_running
from main.models import AlignmentGroup
from main.models import ReferenceGenome
from main.models import Dataset
from main.models import ExperimentSampleToAlignment
from pipeline.read_alignment import align_with_bwa_mem
from pipeline.variant_calling import find_variants_with_tool
from pipeline.variant_calling import VARIANT_TOOL_PARAMS_MAP
from pipeline.variant_calling.freebayes import merge_freebayes_parallel
from pipeline.variant_calling.freebayes import freebayes_regions


# List of variant callers to use. At time of writing, this was not hooked
# up to the ui and only used internally.
VARIANT_CALLING_OPTION__CALLER_OVERRIDE = 'enabled_variant_callers_override'


def run_pipeline(alignment_group_label, ref_genome, sample_list,
        skip_alignment=False, perform_variant_calling=True, alignment_options={},
        variant_calling_options={}):
    """Runs the entire bioinformatics pipeline, including alignment and
    variant calling.

    Steps:
        * Create AlignmentGroup if not created
        * get_or_create ExperimentSampleToAlignments and respective Datasets
        * Kick off alignments
        * When all alignments are done, kick off variant calling

    Args:
        alignment_group_label: Name for this alignment.
        ref_genome: ReferenceGenome instance
        sample_list: List of sample instances. Must belong to same project as
            ReferenceGenomes.
        skip_alignment: If True, skip alignment.
        perform_variant_calling: Whether to run variant calling.
{'fraction_non_alphanumeric': 0.03889171326893747, 'fraction_numerical': 0.0, 'mean_word_length': 4.5974395448079655, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6635978', 'n_tokens_mistral': 1052, 'n_tokens_neox': 992, 'n_words': 386}