def _populate_contigs(self, contig_id, header, cov, sequence):

<EOL>gc_kwargs = self._get_gc_content(sequence, len(sequence))<EOL>logger.debug("<STR_LIT>".format(gc_kwargs))<EOL>self.contigs[contig_id] = {<EOL>"<STR_LIT>": header,<EOL>"<STR_LIT>": sequence,<EOL>"<STR_LIT>": len(sequence),<EOL>"<STR_LIT>": cov,<EOL>**gc_kwargs<EOL>}<EOL>

Inserts data from a single contig into\
         :py:attr:`~Assembly.contigs`.

        By providing a contig id, the original header, the coverage that
        is parsed from the header and the sequence, this method will
        populate the :py:attr:`~Assembly.contigs` attribute.

        Parameters
        ----------
        contig_id : int
            Arbitrary unique contig identifier.
        header : str
            Original header of the current contig.
        cov : float
            The contig coverage, parsed from the fasta header
        sequence : str
            The complete sequence of the contig.


return sum(<EOL>[vals["<STR_LIT>"] for contig_id, vals in self.contigs.items()<EOL>if contig_id not in self.filtered_ids])<EOL>

Returns the length of the assembly, without the filtered contigs.

        Returns
        -------
        x : int
            Total length of the assembly.


cov = None<EOL>for i in header_str.split("<STR_LIT:_>")[::-<NUM_LIT:1>]:<EOL><INDENT>try:<EOL><INDENT>cov = float(i)<EOL>break<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>return cov<EOL>

Attempts to retrieve the coverage value from the header string.

        It splits the header by "_" and then screens the list backwards in
        search of the first float value. This will be interpreted as the
        coverage value. If it cannot find a float value, it returns None.
        This search methodology is based on the strings of assemblers
        like spades and skesa that put the mean kmer coverage for each
        contig in its corresponding fasta header.

        Parameters
        ----------
        header_str : str
            String

        Returns
        -------
        float or None
            The coverage value for the contig. None if it cannot find the
            value in the provide string.


<EOL>fail_sensitive = kwargs.get("<STR_LIT>", [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>"<EOL>])<EOL>logger.debug("<STR_LIT>".format(fail_sensitive))<EOL>must_pass = kwargs.get("<STR_LIT>", [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>"<EOL>])<EOL>logger.debug("<STR_LIT>".format(must_pass))<EOL>warning_fail_sensitive = kwargs.get("<STR_LIT>", [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>])<EOL>warning_must_pass = kwargs.get("<STR_LIT>", [<EOL>"<STR_LIT>"<EOL>])<EOL>summary_info = get_summary(summary_file)<EOL>health = True<EOL>failed = []<EOL>warning = []<EOL>for cat, test in summary_info.items():<EOL><INDENT>logger.debug("<STR_LIT>".format(cat, test))<EOL>if cat in fail_sensitive and test == "<STR_LIT>":<EOL><INDENT>health = False<EOL>failed.append("<STR_LIT>".format(cat, test))<EOL>logger.error("<STR_LIT>"<EOL>"<STR_LIT>".format(cat))<EOL><DEDENT>if cat in must_pass and test != "<STR_LIT>":<EOL><INDENT>health = False<EOL>failed.append("<STR_LIT>".format(cat, test))<EOL>logger.error("<STR_LIT>".format(<EOL>cat))<EOL><DEDENT>if cat in warning_fail_sensitive and test == "<STR_LIT>":<EOL><INDENT>warning.append("<STR_LIT>".format(cat))<EOL>logger.warning("<STR_LIT>"<EOL>"<STR_LIT>".format(cat))<EOL><DEDENT>if cat in warning_must_pass and test != "<STR_LIT>":<EOL><INDENT>warning.append("<STR_LIT>".format(cat))<EOL>logger.warning("<STR_LIT>"<EOL>"<STR_LIT>".format(cat))<EOL><DEDENT><DEDENT>return health, failed, warning<EOL>

Checks the health of a sample from the FastQC summary file.

    Parses the FastQC summary file and tests whether the sample is good
    or not. There are four categories that cannot fail, and two that
    must pass in order for the sample pass this check. If the sample fails
    the quality checks, a list with the failing categories is also returned.

    Categories that cannot fail::

        fail_sensitive = [
            "Per base sequence quality",
            "Overrepresented sequences",
            "Sequence Length Distribution",
            "Per sequence GC content"
        ]

    Categories that must pass::

        must_pass = [
            "Per base N content",
            "Adapter Content"
        ]

    Parameters
    ----------
    summary_file: str
        Path to FastQC summary file.

    Returns
    -------
    x : bool
        Returns ``True`` if the sample passes all tests. ``False`` if not.
    summary_info : list
        A list with the FastQC categories that failed the tests. Is empty
        if the sample passes all tests.


logger.debug("<STR_LIT>")<EOL>target_nuc_bias = "<STR_LIT>"<EOL>logger.debug("<STR_LIT>"<EOL>"<STR_LIT:{}>".format(target_nuc_bias))<EOL>gather = False<EOL>biased = []<EOL>with open(data_file) as fh:<EOL><INDENT>for line in fh:<EOL><INDENT>if line.startswith(target_nuc_bias):<EOL><INDENT>logger.debug("<STR_LIT>".format(line))<EOL>next(fh)<EOL>gather = True<EOL><DEDENT>elif line.startswith("<STR_LIT>") and gather:<EOL><INDENT>logger.debug("<STR_LIT>".format(line))<EOL>break<EOL><DEDENT>elif gather:<EOL><INDENT>g, a, t, c = [float(x) for x in line.strip().split()[<NUM_LIT:1>:]]<EOL>gc = (g + <NUM_LIT:0.1>) / (c + <NUM_LIT:0.1>)<EOL>at = (a + <NUM_LIT:0.1>) / (t + <NUM_LIT:0.1>)<EOL>if <NUM_LIT> <= gc <= <NUM_LIT> and <NUM_LIT> <= at <= <NUM_LIT>:<EOL><INDENT>biased.append(False)<EOL><DEDENT>else:<EOL><INDENT>biased.append(True)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>logger.debug("<STR_LIT>".format(biased))<EOL>biased_5end, biased_3end = biased[:int(len(biased)/<NUM_LIT:2>)],biased[int(len(biased)/<NUM_LIT:2>):][::-<NUM_LIT:1>]<EOL>logger.debug("<STR_LIT>")<EOL>trim_nt = [<NUM_LIT:0>, <NUM_LIT:0>]<EOL>trim_nt[<NUM_LIT:0>] = get_trim_index(biased_5end)<EOL>logger.debug("<STR_LIT>".format(trim_nt[<NUM_LIT:0>]))<EOL>trim_nt[<NUM_LIT:1>] = len(biased) - get_trim_index(biased_3end)<EOL>logger.debug("<STR_LIT>".format(trim_nt[<NUM_LIT:1>]))<EOL>return trim_nt<EOL>

Assess the optimal trim range for a given FastQC data file.

    This function will parse a single FastQC data file, namely the
    *'Per base sequence content'* category. It will retrieve the A/T and G/C
    content for each nucleotide position in the reads, and check whether the
    G/C and A/T proportions are between 80% and 120%. If they are, that
    nucleotide position is marked as biased for future removal.

    Parameters
    ----------
    data_file: str
        Path to FastQC data file.

    Returns
    -------
    trim_nt: list
        List containing the range with the best trimming positions for the
        corresponding FastQ file. The first element is the 5' end trim index
        and the second element is the 3' end trim index.


@MainWrapper<EOL>def main(sample_id, assembly_file, coverage_bp_file=None):

logger.info("<STR_LIT>")<EOL>assembly_obj = Assembly(assembly_file, sample_id)<EOL>logger.info("<STR_LIT>")<EOL>assembly_obj.get_summary_stats("<STR_LIT>".format(sample_id))<EOL>size_dist = [len(x) for x in assembly_obj.contigs.values()]<EOL>json_dic = {<EOL>"<STR_LIT>": [{<EOL>"<STR_LIT>": sample_id,<EOL>"<STR_LIT:data>": [<EOL>{"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:value>": assembly_obj.summary_info["<STR_LIT>"],<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": True},<EOL>{"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:value>": assembly_obj.summary_info["<STR_LIT>"],<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": True},<EOL>]<EOL>}],<EOL>"<STR_LIT>": [{<EOL>"<STR_LIT>": sample_id,<EOL>"<STR_LIT:data>": {<EOL>"<STR_LIT>": size_dist<EOL>}<EOL>}]<EOL>}<EOL>if coverage_bp_file:<EOL><INDENT>try:<EOL><INDENT>window = <NUM_LIT><EOL>gc_sliding_data = assembly_obj.get_gc_sliding(window=window)<EOL>cov_sliding_data =assembly_obj.get_coverage_sliding(coverage_bp_file,<EOL>window=window)<EOL>total_bp = sum(<EOL>[sum(x) for x in assembly_obj.contig_coverage.values()]<EOL>)<EOL>json_dic["<STR_LIT>"][<NUM_LIT:0>]["<STR_LIT:data>"]["<STR_LIT>"] = {<EOL>"<STR_LIT>": gc_sliding_data,<EOL>"<STR_LIT>": cov_sliding_data,<EOL>"<STR_LIT>": window,<EOL>"<STR_LIT>": assembly_obj._get_window_labels(window),<EOL>"<STR_LIT>": os.path.basename(assembly_file)<EOL>}<EOL>json_dic["<STR_LIT>"][<NUM_LIT:0>]["<STR_LIT:data>"]["<STR_LIT>"] = total_bp<EOL><DEDENT>except:<EOL><INDENT>logger.error("<STR_LIT>"<EOL>"<STR_LIT:{}>".format(traceback.format_exc()))<EOL><DEDENT><DEDENT>with open("<STR_LIT>", "<STR_LIT:w>") as json_report:<EOL><INDENT>json_report.write(json.dumps(json_dic, separators=("<STR_LIT:U+002C>", "<STR_LIT::>")))<EOL><DEDENT>with open("<STR_LIT>", "<STR_LIT:w>") as status_fh:<EOL><INDENT>status_fh.write("<STR_LIT>")<EOL><DEDENT>

Main executor of the assembly_report template.

    Parameters
    ----------
    sample_id : str
        Sample Identification string.
    assembly_file : str
        Path to assembly file in Fasta format.


contig_id = contig_str<EOL>try:<EOL><INDENT>contig_id = re.search("<STR_LIT>", contig_str).group(<NUM_LIT:1>)<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>contig_id = re.search("<STR_LIT>", contig_str).group(<NUM_LIT:1>)<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>return contig_id<EOL>

Tries to retrieve contig id. Returns the original string if it
        is unable to retrieve the id.

        Parameters
        ----------
        contig_str : str
            Full contig string (fasta header)

        Returns
        -------
        str
            Contig id


gc_res = []<EOL>complete_seq = "<STR_LIT>".join(self.contigs.values()).lower()<EOL>for i in range(<NUM_LIT:0>, len(complete_seq), window):<EOL><INDENT>seq_window = complete_seq[i:i + window]<EOL>gc_res.append(round(self._gc_prop(seq_window, len(seq_window)), <NUM_LIT:2>))<EOL><DEDENT>return gc_res<EOL>

Calculates a sliding window of the GC content for the assembly

        Returns
        -------
        gc_res : list
            List of GC proportion floats for each data point in the sliding
            window


@MainWrapper<EOL>def main(mash_output, hash_cutoff, sample_id, assembly_file):

input_f = open(mash_output, "<STR_LIT:r>")<EOL>master_dict = {}<EOL>for line in input_f:<EOL><INDENT>tab_split = line.split("<STR_LIT:\t>")<EOL>current_seq = tab_split[<NUM_LIT:1>].strip()<EOL>ref_accession = "<STR_LIT:_>".join(tab_split[<NUM_LIT:0>].strip().split("<STR_LIT:_>")[<NUM_LIT:0>:<NUM_LIT:3>])<EOL>mash_dist = tab_split[<NUM_LIT:2>].strip()<EOL>hashes_list = tab_split[-<NUM_LIT:1>].strip().split("<STR_LIT:/>")<EOL>perc_hashes = float(hashes_list[<NUM_LIT:0>]) / float(hashes_list[<NUM_LIT:1>])<EOL>if ref_accession in master_dict.keys():<EOL><INDENT>current_seq += "<STR_LIT>".format(master_dict[ref_accession][-<NUM_LIT:1>])<EOL><DEDENT>if perc_hashes > float(hash_cutoff):<EOL><INDENT>master_dict[ref_accession] = [<EOL>round(<NUM_LIT:1> - float(mash_dist), <NUM_LIT:2>),<EOL>round(perc_hashes, <NUM_LIT:2>),<EOL>current_seq<EOL>]<EOL><DEDENT><DEDENT>send_to_output(master_dict, mash_output, sample_id, assembly_file)<EOL>

Main function that allows to dump a mash dist txt file to a json file

Parameters
----------
mash_output: str
    A string with the input file.
hash_cutoff: str
    the percentage cutoff for the percentage of shared hashes between query
    and plasmid in database that is allowed for the plasmid to be reported
    to the results outputs
sample_id: str
    The name of the sample.


for fq in fastq:<EOL><INDENT>rp = os.path.realpath(fq)<EOL>logger.debug("<STR_LIT>".format(rp))<EOL>if re.match("<STR_LIT>", rp):<EOL><INDENT>os.remove(rp)<EOL><DEDENT><DEDENT>

Cleans the temporary fastq files. If they are symlinks, the link
source is removed

Parameters
----------
fastq : list
    List of fastq files.


@MainWrapper<EOL>def main(sample_id, fastq_pair, max_len, kmer, opts, clear, disable_rr):

logger.info("<STR_LIT>")<EOL>min_coverage, min_kmer_coverage = opts<EOL>logger.info("<STR_LIT>")<EOL>kmers = set_kmers(kmer, max_len)<EOL>logger.info("<STR_LIT>".format(kmers))<EOL>cli = [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>min_coverage,<EOL>"<STR_LIT>",<EOL>"<STR_LIT:.>"<EOL>]<EOL>if kmers:<EOL><INDENT>cli += ["<STR_LIT>".format("<STR_LIT:U+002C>".join([str(x) for x in kmers]))]<EOL><DEDENT>cli += [<EOL>"<STR_LIT>",<EOL>fastq_pair[<NUM_LIT:0>],<EOL>"<STR_LIT>",<EOL>fastq_pair[<NUM_LIT:1>]<EOL>]<EOL>if disable_rr == '<STR_LIT:true>':<EOL><INDENT>cli += ['<STR_LIT>']<EOL><DEDENT>logger.debug("<STR_LIT>".format(cli))<EOL>p = subprocess.Popen(cli, stdout=PIPE, stderr=PIPE)<EOL>stdout, stderr = p.communicate()<EOL>try:<EOL><INDENT>stderr = stderr.decode("<STR_LIT:utf8>")<EOL>stdout = stdout.decode("<STR_LIT:utf8>")<EOL><DEDENT>except (UnicodeDecodeError, AttributeError):<EOL><INDENT>stderr = str(stderr)<EOL>stdout = str(stdout)<EOL><DEDENT>logger.info("<STR_LIT>"<EOL>"<STR_LIT>".format(stdout))<EOL>logger.info("<STR_LIT>"<EOL>"<STR_LIT>".format(stderr))<EOL>logger.info("<STR_LIT>".format(<EOL>p.returncode))<EOL>with open("<STR_LIT>", "<STR_LIT:w>") as fh:<EOL><INDENT>if p.returncode != <NUM_LIT:0>:<EOL><INDENT>fh.write("<STR_LIT:error>")<EOL>sys.exit(p.returncode)<EOL><DEDENT>else:<EOL><INDENT>fh.write("<STR_LIT>")<EOL><DEDENT><DEDENT>if "<STR_LIT>" in fastq_pair[<NUM_LIT:0>]:<EOL><INDENT>sample_id += "<STR_LIT>"<EOL><DEDENT>info = __get_version_spades()<EOL>assembly_file = "<STR_LIT>".format(<EOL>sample_id, info["<STR_LIT:version>"].replace("<STR_LIT:.>", "<STR_LIT>"))<EOL>os.rename("<STR_LIT>", assembly_file)<EOL>logger.info("<STR_LIT>".format(assembly_file))<EOL>if clear == "<STR_LIT:true>" and os.path.exists(assembly_file):<EOL><INDENT>clean_up(fastq_pair)<EOL><DEDENT>

Main executor of the spades template.

    Parameters
    ----------
    sample_id : str
        Sample Identification string.
    fastq_pair : list
        Two element list containing the paired FastQ files.
    max_len : int
        Maximum read length. This value is determined in
        :py:class:`templates.integrity_coverage`
    kmer : str
        Can be either ``'auto'``, ``'default'`` or a
        sequence of space separated integers, ``'23, 45, 67'``.
    opts : List of options for spades execution. See above.
    clear : str
        Can be either 'true' or 'false'. If 'true', the input fastq files will
        be removed at the end of the run, IF they are in the working directory
    disable_rr : str
        Can either be 'true' or 'false'. If 'true', disables repeat resolution
        stage of assembling


def evaluate_min_coverage(coverage_opt, assembly_coverage, assembly_size):

if coverage_opt == "<STR_LIT>":<EOL><INDENT>min_coverage = (assembly_coverage / assembly_size) * <NUM_LIT><EOL>logger.info("<STR_LIT>"<EOL>"<STR_LIT:{}>".format(min_coverage))<EOL>if min_coverage < <NUM_LIT:10>:<EOL><INDENT>logger.info("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>min_coverage = <NUM_LIT:10><EOL><DEDENT><DEDENT>else:<EOL><INDENT>min_coverage = int(coverage_opt)<EOL>logger.info("<STR_LIT>".format(<EOL>min_coverage))<EOL><DEDENT>return min_coverage<EOL>

Evaluates the minimum coverage threshold from the value provided in
    the coverage_opt.

    Parameters
    ----------
    coverage_opt : str or int or float
        If set to "auto" it will try to automatically determine the coverage
        to 1/3 of the assembly size, to a minimum value of 10. If it set
        to a int or float, the specified value will be used.
    assembly_coverage : int or float
        The average assembly coverage for a genome assembly. This value
        is retrieved by the `:py:func:parse_coverage_table` function.
    assembly_size : int
        The size of the genome assembly. This value is retrieved by the
        `py:func:get_assembly_size` function.

    Returns
    -------
    x: int
        Minimum coverage threshold.


def filter_assembly(assembly_file, minimum_coverage, coverage_info,<EOL>output_file):

<EOL>write_flag = False<EOL>with open(assembly_file) as fh, open(output_file, "<STR_LIT:w>") as out_fh:<EOL><INDENT>for line in fh:<EOL><INDENT>if line.startswith("<STR_LIT:>>"):<EOL><INDENT>write_flag = False<EOL>header = line.strip()[<NUM_LIT:1>:]<EOL>contig_cov = coverage_info[header]["<STR_LIT>"]<EOL>if contig_cov >= minimum_coverage:<EOL><INDENT>write_flag = True<EOL>out_fh.write(line)<EOL><DEDENT><DEDENT>elif write_flag:<EOL><INDENT>out_fh.write(line)<EOL><DEDENT><DEDENT><DEDENT>

Generates a filtered assembly file.

    This function generates a filtered assembly file based on an original
    assembly and a minimum coverage threshold.

    Parameters
    ----------
    assembly_file : str
        Path to original assembly file.
    minimum_coverage : int or float
        Minimum coverage required for a contig to pass the filter.
    coverage_info : OrderedDict or dict
        Dictionary containing the coverage information for each contig.
    output_file : str
        Path where the filtered assembly file will be generated.


<EOL>coverage_dict = OrderedDict()<EOL>total_cov = <NUM_LIT:0><EOL>with open(coverage_file) as fh:<EOL><INDENT>for line in fh:<EOL><INDENT>contig, cov = line.strip().split()<EOL>coverage_dict[contig] = {"<STR_LIT>": int(cov)}<EOL>total_cov += int(cov)<EOL>logger.debug("<STR_LIT>"<EOL>"<STR_LIT>".format(contig, cov))<EOL><DEDENT><DEDENT>return coverage_dict, total_cov<EOL>

Parses a file with coverage information into objects.

    This function parses a TSV file containing coverage results for
    all contigs in a given assembly and will build an ``OrderedDict``
    with the information about their coverage and length.  The length
    information is actually gathered from the contig header using a
    regular expression that assumes the usual header produced by Spades::

        contig_len = int(re.search("length_(.+?)_", line).group(1))

    Parameters
    ----------
    coverage_file : str
        Path to TSV file containing the coverage results.

    Returns
    -------
    coverage_dict : OrderedDict
        Contains the coverage and length information for each contig.
    total_size : int
        Total size of the assembly in base pairs.
    total_cov : int
        Sum of coverage values across all contigs.


logger.debug("<STR_LIT>".format(<EOL>output_file))<EOL>with open(output_file, "<STR_LIT:w>") as fh:<EOL><INDENT>for contig_id, vals in self.report.items():<EOL><INDENT>fh.write("<STR_LIT>".format(contig_id, vals))<EOL><DEDENT><DEDENT>

Writes a report with the test results for the current assembly

        Parameters
        ----------
        output_file : str
            Name of the output assembly file.


json_dic = dict((x, y) for x, y in zip(header, fields))<EOL>return json_dic<EOL>

Parameters
----------
fields

Returns
-------


template = OrderedDict([<EOL>("<STR_LIT>", <NUM_LIT:0>),<EOL>("<STR_LIT>", <NUM_LIT:0>),<EOL>("<STR_LIT>", <NUM_LIT:0>),<EOL>("<STR_LIT>", <NUM_LIT:0>),<EOL>("<STR_LIT>", <NUM_LIT:0>),<EOL>("<STR_LIT>", <NUM_LIT:0>)<EOL>])<EOL>with open(log_file) as fh:<EOL><INDENT>for line in fh:<EOL><INDENT>fields = [int(x) for x in line.strip().split()[-<NUM_LIT:4>:]]<EOL>if not fields[<NUM_LIT:0>]:<EOL><INDENT>template["<STR_LIT>"] += <NUM_LIT:1><EOL><DEDENT>template["<STR_LIT>"] += fields[<NUM_LIT:1>]<EOL>template["<STR_LIT>"] += fields[<NUM_LIT:3>]<EOL>template["<STR_LIT>"] += fields[<NUM_LIT:1>] + fields[<NUM_LIT:3>]<EOL>template["<STR_LIT>"] += fields[<NUM_LIT:0>]<EOL><DEDENT>total_len = template["<STR_LIT>"] + template["<STR_LIT>"]<EOL>if total_len:<EOL><INDENT>template["<STR_LIT>"] = round(<EOL>(template["<STR_LIT>"] / total_len) * <NUM_LIT:100>, <NUM_LIT:2>)<EOL><DEDENT>else:<EOL><INDENT>template["<STR_LIT>"] = <NUM_LIT:0><EOL><DEDENT><DEDENT>return template<EOL>

Retrieves some statistics from a single Trimmomatic log file.

    This function parses Trimmomatic's log file and stores some trimming
    statistics in an :py:class:`OrderedDict` object. This object contains
    the following keys:

        - ``clean_len``: Total length after trimming.
        - ``total_trim``: Total trimmed base pairs.
        - ``total_trim_perc``: Total trimmed base pairs in percentage.
        - ``5trim``: Total base pairs trimmed at 5' end.
        - ``3trim``: Total base pairs trimmed at 3' end.

    Parameters
    ----------
    log_file : str
        Path to trimmomatic log file.

    Returns
    -------
    x : :py:class:`OrderedDict`
        Object storing the trimming statistics.


default_adapters = [os.path.join(ADAPTERS_PATH, x) for x in<EOL>os.listdir(ADAPTERS_PATH)]<EOL>filepath = os.path.join(os.getcwd(), "<STR_LIT>")<EOL>with open(filepath, "<STR_LIT:w>") as fh,fileinput.input(default_adapters) as in_fh:<EOL><INDENT>for line in in_fh:<EOL><INDENT>fh.write("<STR_LIT>".format(line, "<STR_LIT>"))<EOL><DEDENT><DEDENT>return filepath<EOL>

Merges the default adapters file in the trimmomatic adapters directory

    Returns
    -------
    str
        Path with the merged adapters file.


logger.debug("<STR_LIT>".format(kmer_opt))<EOL>if kmer_opt == "<STR_LIT>":<EOL><INDENT>if max_read_len >= <NUM_LIT>:<EOL><INDENT>kmers = [<NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>]<EOL><DEDENT>else:<EOL><INDENT>kmers = [<NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>]<EOL><DEDENT>logger.debug("<STR_LIT>"<EOL>"<STR_LIT>".format(max_read_len, kmers))<EOL><DEDENT>elif len(kmer_opt.split()) > <NUM_LIT:1>:<EOL><INDENT>kmers = kmer_opt.split()<EOL>if kmers[<NUM_LIT:0>]<<NUM_LIT:15> or kmers[-<NUM_LIT:1>]><NUM_LIT:255> or is_odd(kmers):<EOL><INDENT>kmers = []<EOL>logger.debug("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>logger.debug("<STR_LIT>".format(kmers))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>kmers = []<EOL>logger.debug("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return kmers<EOL>

Returns a kmer list based on the provided kmer option and max read len.

    Parameters
    ----------
    kmer_opt : str
        The k-mer option. Can be either ``'auto'``, ``'default'`` or a
        sequence of space separated integers, ``'23, 45, 67'``.
    max_read_len : int
        The maximum read length of the current sample.

    Returns
    -------
    kmers : list
        List of k-mer values that will be provided to megahit.


@MainWrapper<EOL>def main(fastq_pair, adapter_file, cpus):

logger.info("<STR_LIT>")<EOL>if os.path.exists(adapter_file):<EOL><INDENT>logger.info("<STR_LIT>".format(adapter_file))<EOL>adapters = convert_adatpers(adapter_file)<EOL><DEDENT>else:<EOL><INDENT>logger.info("<STR_LIT>"<EOL>"<STR_LIT>".format(adapter_file))<EOL>adapters = None<EOL><DEDENT>cli = [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>str(cpus)<EOL>]<EOL>if adapters:<EOL><INDENT>cli += ["<STR_LIT>", "<STR_LIT:{}>".format(adapters)]<EOL><DEDENT>cli += fastq_pair<EOL>logger.debug("<STR_LIT>".format(cli))<EOL>p = subprocess.Popen(cli, stdout=PIPE, stderr=PIPE, shell=False)<EOL>stdout, stderr = p.communicate()<EOL>try:<EOL><INDENT>stderr = stderr.decode("<STR_LIT:utf8>")<EOL><DEDENT>except (UnicodeDecodeError, AttributeError):<EOL><INDENT>stderr = str(stderr)<EOL><DEDENT>logger.info("<STR_LIT>"<EOL>"<STR_LIT>".format(stdout))<EOL>logger.info("<STR_LIT>"<EOL>"<STR_LIT>".format(stderr))<EOL>logger.info("<STR_LIT>".format(<EOL>p.returncode))<EOL>logger.info("<STR_LIT>")<EOL>with open("<STR_LIT>", "<STR_LIT:w>") as status_fh:<EOL><INDENT>for fastq in fastq_pair:<EOL><INDENT>fpath = join(fastq.rsplit("<STR_LIT:.>", <NUM_LIT:2>)[<NUM_LIT:0>] + "<STR_LIT>",<EOL>"<STR_LIT>")<EOL>logger.debug("<STR_LIT>".format(fpath))<EOL>if not exists(fpath):<EOL><INDENT>logger.warning("<STR_LIT>".format(fpath))<EOL>status_fh.write("<STR_LIT>")<EOL>return<EOL><DEDENT>logger.debug("<STR_LIT>".format(fpath))<EOL>status_fh.write("<STR_LIT>")<EOL><DEDENT><DEDENT>logger.info("<STR_LIT>")<EOL>for i, fastq in enumerate(fastq_pair):<EOL><INDENT>fastqc_dir = fastq.rsplit("<STR_LIT:.>", <NUM_LIT:2>)[<NUM_LIT:0>] + "<STR_LIT>"<EOL>summary_file = join(fastqc_dir, "<STR_LIT>")<EOL>logger.debug("<STR_LIT>".format(summary_file))<EOL>fastqc_data_file = join(fastqc_dir, "<STR_LIT>")<EOL>logger.debug("<STR_LIT>".format(fastqc_data_file))<EOL>os.rename(fastqc_data_file, "<STR_LIT>".format(i + <NUM_LIT:1>))<EOL>os.rename(summary_file, "<STR_LIT>".format(i + <NUM_LIT:1>))<EOL><DEDENT>

Main executor of the fastq template.

    Parameters
    ----------
    fastq_pair : list
        Two element list containing the paired FastQ files.
    adapter_file : str
        Path to adapters file.
    cpus : int or str
        Number of cpu's that will be by FastQC.


@MainWrapper<EOL>def main(sample_id, assembly, min_size):

logger.info("<STR_LIT>")<EOL>f_open = open(assembly, "<STR_LIT>")<EOL>entry = (x[<NUM_LIT:1>] for x in groupby(f_open, lambda line: line[<NUM_LIT:0>] == "<STR_LIT:>>"))<EOL>success = <NUM_LIT:0><EOL>for header in entry:<EOL><INDENT>headerStr = header.__next__()[<NUM_LIT:1>:].strip()<EOL>seq = "<STR_LIT>".join(s.strip() for s in entry.__next__())<EOL>if len(seq) >= min_size:<EOL><INDENT>with open(sample_id + '<STR_LIT:_>' + headerStr.replace("<STR_LIT:U+0020>","<STR_LIT:_>").replace("<STR_LIT:=>","<STR_LIT:_>") + '<STR_LIT>', "<STR_LIT:w>") as output_file:<EOL><INDENT>output_file.write("<STR_LIT:>>" + sample_id + "<STR_LIT:_>" + headerStr.replace("<STR_LIT:U+0020>","<STR_LIT:_>").replace("<STR_LIT:=>","<STR_LIT:_>") + "<STR_LIT>" + seq + "<STR_LIT>")<EOL>success += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>f_open.close()<EOL>logger.info("<STR_LIT>".format(success))<EOL>

Main executor of the split_fasta template.

    Parameters
    ----------
    sample_id : str
        Sample Identification string.
    assembly : list
        Assembly file.
    min_size : int
        Minimum contig size.


json_dic = {"<STR_LIT>": []}<EOL>sample_dic = {}<EOL>sample_assembly_map = {}<EOL>for entry in self.storage.values():<EOL><INDENT>sample_id = re.match("<STR_LIT>", entry["<STR_LIT>"]).groups()[<NUM_LIT:0>]<EOL>if sample_id not in sample_dic:<EOL><INDENT>sample_dic[sample_id] = {}<EOL><DEDENT>contig_id = self._get_contig_id(entry["<STR_LIT>"])<EOL>database = entry["<STR_LIT>"]<EOL>if database not in sample_dic[sample_id]:<EOL><INDENT>sample_dic[sample_id][database] = []<EOL><DEDENT>if sample_id not in sample_assembly_map:<EOL><INDENT>sample_assembly_map[sample_id] = entry["<STR_LIT>"]<EOL><DEDENT>sample_dic[sample_id][database].append(<EOL>{"<STR_LIT>": contig_id,<EOL>"<STR_LIT>": entry["<STR_LIT>"],<EOL>"<STR_LIT>": entry["<STR_LIT>"].replace("<STR_LIT:'>", "<STR_LIT>"),<EOL>"<STR_LIT>": entry["<STR_LIT>"],<EOL>"<STR_LIT>": entry["<STR_LIT>"],<EOL>"<STR_LIT>": entry["<STR_LIT>"],<EOL>},<EOL>)<EOL><DEDENT>for sample, data in sample_dic.items():<EOL><INDENT>json_dic["<STR_LIT>"].append(<EOL>{<EOL>"<STR_LIT>": sample,<EOL>"<STR_LIT:data>": {"<STR_LIT>": data},<EOL>"<STR_LIT>": sample_assembly_map[sample]<EOL>}<EOL>)<EOL><DEDENT>return json_dic<EOL>

Generates the JSON report to plot the gene boxes

        Following the convention of the reports platform, this method returns
        a list of JSON/dict objects with the information about each entry in
        the abricate file. The information contained in this JSON is::

            {contig_id: <str>,
             seqRange: [<int>, <int>],
             gene: <str>,
             accession: <str>,
             coverage: <float>,
             identity: <float>
             }

        Note that the `seqRange` entry contains the position in the
        corresponding contig, not the absolute position in the whole assembly.

        Returns
        -------
        json_dic : list
            List of JSON/dict objects with the report data.


print("<STR_LIT>")<EOL>regexes = {<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': r"<STR_LIT>",<EOL>'<STR_LIT>': r"<STR_LIT>",<EOL>'<STR_LIT>': r"<STR_LIT>"<EOL>},<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': r"<STR_LIT>",<EOL>'<STR_LIT>': r"<STR_LIT>",<EOL>'<STR_LIT>': r"<STR_LIT>",<EOL>'<STR_LIT>': r"<STR_LIT>",<EOL>'<STR_LIT>': r"<STR_LIT>",<EOL>'<STR_LIT>': r"<STR_LIT>",<EOL>'<STR_LIT>': r"<STR_LIT>",<EOL>'<STR_LIT>': r"<STR_LIT>"<EOL>}<EOL>}<EOL>with open(bowtie_log, "<STR_LIT:r>") as f:<EOL><INDENT>for l in f:<EOL><INDENT>print(l)<EOL>total = re.search(r"<STR_LIT>", l)<EOL>print(total)<EOL>if total:<EOL><INDENT>print(total)<EOL>self.set_n_reads(total.group(<NUM_LIT:1>))<EOL><DEDENT>paired = re.search(r"<STR_LIT>", l)<EOL>if paired:<EOL><INDENT>paired_total = int(paired.group(<NUM_LIT:1>))<EOL>paired_numbers = {}<EOL>l = f.readline()<EOL>while l.startswith('<STR_LIT:U+0020>'):<EOL><INDENT>for k, r in regexes['<STR_LIT>'].items():<EOL><INDENT>match = re.search(r, l)<EOL>if match:<EOL><INDENT>paired_numbers[k] = int(match.group(<NUM_LIT:1>))<EOL><DEDENT><DEDENT>l = f.readline()<EOL><DEDENT>align_zero_times = paired_numbers['<STR_LIT>'] + paired_numbers['<STR_LIT>']<EOL>if align_zero_times:<EOL><INDENT>self.set_align_0x(align_zero_times)<EOL><DEDENT>align_one_time = paired_numbers['<STR_LIT>'] + paired_numbers['<STR_LIT>']<EOL>if align_one_time:<EOL><INDENT>self.set_align_1x(align_one_time)<EOL><DEDENT>align_more_than_one_time = paired_numbers['<STR_LIT>'] + paired_numbers['<STR_LIT>']<EOL>if align_more_than_one_time:<EOL><INDENT>self.set_align_mt1x(align_more_than_one_time)<EOL><DEDENT><DEDENT>overall = re.search(r"<STR_LIT>", l)<EOL>if overall:<EOL><INDENT>self.overall_rate = float(overall.group(<NUM_LIT:1>))<EOL><DEDENT><DEDENT><DEDENT>

Parse a bowtie log file.

        This is a bowtie log parsing method that populates the
        :py:attr:`self.n_reads, self.align_0x, self.align_1x, self.align_mt1x and self.overall_rate` attributes with
        data from the log file.

        Disclamer: THIS METHOD IS HORRIBLE BECAUSE THE BOWTIE LOG IS HORRIBLE.

        The insertion of data on the attribytes is done by the
        :py:meth:`set_attribute method.

        Parameters
        ----------
        bowtie_log : str
            Path to the boetie log file.


logger.info("<STR_LIT>")<EOL>warnings = []<EOL>fails = "<STR_LIT>"<EOL>bowtie_info = Bowtie(sample_id, bowite_log)<EOL>print(bowtie_info.overall_rate)<EOL>with open("<STR_LIT>", "<STR_LIT:w>") as json_report:<EOL><INDENT>json_dic = {<EOL>"<STR_LIT>": [{<EOL>"<STR_LIT>": sample_id,<EOL>"<STR_LIT:data>": [<EOL>{"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:value>": int(bowtie_info.n_reads),<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": False},<EOL>{"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:value>": int(bowtie_info.align_0x),<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": False},<EOL>{"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:value>": int(bowtie_info.align_1x),<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": False},<EOL>{"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:value>": int(bowtie_info.align_mt1x),<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": False},<EOL>{"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:value>": float(bowtie_info.overall_rate),<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": False}<EOL>]<EOL>}],<EOL>}<EOL>if warnings:<EOL><INDENT>json_dic["<STR_LIT>"] = [{<EOL>"<STR_LIT>": sample_id,<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:value>": warnings<EOL>}]<EOL><DEDENT>if fails:<EOL><INDENT>json_dic["<STR_LIT>"] = [{<EOL>"<STR_LIT>": sample_id,<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:value>": [fails]<EOL>}]<EOL><DEDENT>json_report.write(json.dumps(json_dic, separators=("<STR_LIT:U+002C>", "<STR_LIT::>")))<EOL><DEDENT>with open("<STR_LIT>", "<STR_LIT:w>") as status_fh:<EOL><INDENT>status_fh.write("<STR_LIT>")<EOL><DEDENT>

Main executor of the process_mapping template.

    Parameters
    ----------
    sample_id : str
        Sample Identification string.
    boetie_log: str
        Path to the log file generated by bowtie.


<EOL>depth_dic_coverage = {}<EOL>for line in depth_file:<EOL><INDENT>tab_split = line.split()  <EOL>reference = "<STR_LIT:_>".join(tab_split[<NUM_LIT:0>].strip().split("<STR_LIT:_>")[<NUM_LIT:0>:<NUM_LIT:3>])  <EOL>position = tab_split[<NUM_LIT:1>]<EOL>num_reads_align = float(tab_split[<NUM_LIT:2>].rstrip())<EOL>if reference not in depth_dic_coverage:<EOL><INDENT>depth_dic_coverage[reference] = {}<EOL><DEDENT>depth_dic_coverage[reference][position] = num_reads_align<EOL><DEDENT>logger.info("<STR_LIT>")<EOL>depth_file.close()<EOL>logger.debug("<STR_LIT>".format(<EOL>asizeof(depth_dic_coverage)/<NUM_LIT>))<EOL>return depth_dic_coverage<EOL>

Function that parse samtools depth file and creates 3 dictionaries that
will be useful to make the outputs of this script, both the tabular file
and the json file that may be imported by pATLAS

Parameters
----------
depth_file: textIO
    the path to depth file for each sample

Returns
-------
depth_dic_coverage: dict
        dictionary with the coverage per position for each plasmid


valid_encodings = []<EOL>valid_phred = []<EOL>for encoding, (phred, (emin, emax)) in RANGES.items():<EOL><INDENT>if rmin >= emin and rmax <= emax:<EOL><INDENT>valid_encodings.append(encoding)<EOL>valid_phred.append(phred)<EOL><DEDENT><DEDENT>return valid_encodings, valid_phred<EOL>

Returns the valid encodings for a given encoding range.

    The encoding ranges are stored in the :py:data:`RANGES` dictionary, with
    the encoding name as a string and a list as a value containing the
    phred score and a tuple with the encoding range. For a given encoding
    range provided via the two first arguments, this function will return
    all possible encodings and phred scores.

    Parameters
    ----------
    rmin : int
        Minimum Unicode code in range.
    rmax : int
        Maximum Unicode code in range.

    Returns
    -------
    valid_encodings : list
        List of all possible encodings for the provided range.
    valid_phred : list
        List of all possible phred scores.


version_storage = []<EOL>template_version = self.context.get("<STR_LIT>", None)<EOL>template_program = self.context.get("<STR_LIT>", None)<EOL>template_build = self.context.get("<STR_LIT>", None)<EOL>if template_version and template_program and template_build:<EOL><INDENT>if self.logger:<EOL><INDENT>self.logger.debug("<STR_LIT>"<EOL>"<STR_LIT:{}>".format(template_program,<EOL>template_version,<EOL>template_build))<EOL><DEDENT>version_storage.append({<EOL>"<STR_LIT>": template_program,<EOL>"<STR_LIT:version>": template_version,<EOL>"<STR_LIT>": template_build<EOL>})<EOL><DEDENT>for var, obj in self.context.items():<EOL><INDENT>if var.startswith("<STR_LIT>"):<EOL><INDENT>ver = obj()<EOL>version_storage.append(ver)<EOL>if self.logger:<EOL><INDENT>self.logger.debug("<STR_LIT>"<EOL>"<STR_LIT:{}>".format(ver))<EOL><DEDENT><DEDENT><DEDENT>with open("<STR_LIT>", "<STR_LIT:w>") as fh:<EOL><INDENT>fh.write(json.dumps(version_storage, separators=("<STR_LIT:U+002C>", "<STR_LIT::>")))<EOL><DEDENT>

Writes versions JSON for a template file

        This method creates the JSON file ``.versions`` based on the metadata
        and specific functions that are present in a given template script.

        It starts by fetching the template metadata, which can be specified
        via the ``__version__``, ``__template__`` and ``__build__``
        attributes. If all of these attributes exist, it starts to populate
        a JSON/dict array (Note that the absence of any one of them will
        prevent the version from being written).

        Then, it will search the
        template scope for functions that start with the substring
        ``__set_version`` (For example ``def __set_version_fastqc()`).
        These functions should gather the version of
        an arbitrary program and return a JSON/dict object with the following
        information::

            {
                "program": <program_name>,
                "version": <version>
                "build": <build>
            }

        This JSON/dict object is then written in the ``.versions`` file.


def _build_connections(self, process_list, ignore_dependencies,<EOL>auto_dependency):

logger.debug("<STR_LIT>")<EOL>logger.debug("<STR_LIT>")<EOL>logger.debug("<STR_LIT>")<EOL>logger.debug("<STR_LIT>".format(process_list))<EOL>for p, con in enumerate(process_list):<EOL><INDENT>logger.debug("<STR_LIT>".format(p, con))<EOL>in_lane = con["<STR_LIT:input>"]["<STR_LIT>"]<EOL>out_lane = con["<STR_LIT>"]["<STR_LIT>"]<EOL>logger.debug("<STR_LIT>".format(p, in_lane))<EOL>logger.debug("<STR_LIT>".format(p, out_lane))<EOL>if out_lane > self.lanes:<EOL><INDENT>self.lanes = out_lane<EOL><DEDENT>p_in_name, p_out_name, out_directives = self._get_process_names(<EOL>con, p)<EOL>if p_out_name not in self.process_map:<EOL><INDENT>logger.error(colored_print(<EOL>"<STR_LIT>"<EOL>.format(p_out_name), "<STR_LIT>"))<EOL>guess_process(p_out_name, self.process_map)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>out_process = self.process_map[p_out_name](template=p_out_name)<EOL>if out_directives:<EOL><INDENT>out_process.update_attributes(out_directives)<EOL><DEDENT>input_suf = "<STR_LIT>".format(in_lane, p)<EOL>output_suf = "<STR_LIT>".format(out_lane, p)<EOL>logger.debug("<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>p, input_suf, output_suf))<EOL>out_process.set_main_channel_names(input_suf, output_suf, out_lane)<EOL>if p_in_name != "<STR_LIT>":<EOL><INDENT>in_process = self.process_map[p_in_name](template=p_in_name)<EOL>logger.debug("<STR_LIT>"<EOL>"<STR_LIT>".format(p))<EOL>self._test_connection(in_process, out_process)<EOL>out_process.parent_lane = in_lane<EOL><DEDENT>else:<EOL><INDENT>out_process.parent_lane = None<EOL><DEDENT>logger.debug("<STR_LIT>".format(<EOL>p, out_process.parent_lane))<EOL>if in_lane != out_lane:<EOL><INDENT>logger.debug("<STR_LIT>"<EOL>"<STR_LIT>".format(p))<EOL>self._fork_tree[in_lane].append(out_lane)<EOL>try:<EOL><INDENT>parent_process = [<EOL>x for x in self.processes if x.lane == in_lane and<EOL>x.template == p_in_name<EOL>][<NUM_LIT:0>]<EOL>logger.debug(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(p, parent_process,<EOL>out_process.input_channel))<EOL>parent_process.update_main_forks(out_process.input_channel)<EOL><DEDENT>except IndexError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>else:<EOL><INDENT>parent_process = self.processes[-<NUM_LIT:1>]<EOL>if parent_process.lane and parent_process.lane != out_lane:<EOL><INDENT>parent_process = [x for x in self.processes[::-<NUM_LIT:1>]<EOL>if x.lane == out_lane][<NUM_LIT:0>]<EOL><DEDENT>if parent_process.output_channel:<EOL><INDENT>logger.debug(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>p, parent_process.output_channel))<EOL>out_process.input_channel = parent_process.output_channel<EOL><DEDENT><DEDENT>if out_process.dependencies and not ignore_dependencies:<EOL><INDENT>logger.debug("<STR_LIT>"<EOL>"<STR_LIT:{}>".format(p, p_out_name,<EOL>out_process.dependencies))<EOL>parent_lanes = self._get_fork_tree(out_lane)<EOL>for dep in out_process.dependencies:<EOL><INDENT>if not self._search_tree_backwards(dep, parent_lanes):<EOL><INDENT>if auto_dependency:<EOL><INDENT>self._add_dependency(<EOL>out_process, dep, in_lane, out_lane, p)<EOL><DEDENT>elif not self.export_parameters:<EOL><INDENT>logger.error(colored_print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(p_out_name, dep),<EOL>"<STR_LIT>"))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>self.processes.append(out_process)<EOL><DEDENT>logger.debug("<STR_LIT>".format(self.processes))<EOL>logger.debug("<STR_LIT>".format(self._fork_tree))<EOL>

Parses the process connections dictionaries into a process list

        This method is called upon instantiation of the NextflowGenerator
        class. Essentially, it sets the main input/output channel names of the
        processes so that they can be linked correctly.

        If a connection between two consecutive process is not possible due
        to a mismatch in the input/output types, it exits with an error.

        Returns
        -------


<EOL>if p.link_start:<EOL><INDENT>logger.debug("<STR_LIT>".format(<EOL>p.template, p.link_start))<EOL>for l in p.link_start:<EOL><INDENT>if l in self.secondary_channels:<EOL><INDENT>self.secondary_channels[l][p.lane] = {"<STR_LIT:p>": p, "<STR_LIT:end>": []}<EOL><DEDENT>else:<EOL><INDENT>self.secondary_channels[l] = {p.lane: {"<STR_LIT:p>": p, "<STR_LIT:end>": []}}<EOL><DEDENT><DEDENT><DEDENT>if p.link_end:<EOL><INDENT>logger.debug("<STR_LIT>".format(<EOL>p.template, p.link_end))<EOL>for l in p.link_end:<EOL><INDENT>parent_forks = self._get_fork_tree(p.lane)<EOL>if l["<STR_LIT>"].startswith("<STR_LIT>"):<EOL><INDENT>self._set_implicit_link(p, l)<EOL>continue<EOL><DEDENT>if l["<STR_LIT>"] not in self.secondary_channels:<EOL><INDENT>continue<EOL><DEDENT>for lane in parent_forks:<EOL><INDENT>if lane in self.secondary_channels[l["<STR_LIT>"]]:<EOL><INDENT>self.secondary_channels[<EOL>l["<STR_LIT>"]][lane]["<STR_LIT:end>"].append("<STR_LIT:{}>".format(<EOL>"<STR_LIT>".format(l["<STR_LIT>"], p.pid)))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>logger.debug("<STR_LIT>".format(<EOL>p.template, self.secondary_channels))<EOL>

Given a process, this method updates the
        :attr:`~Process.secondary_channels` attribute with the corresponding
        secondary inputs of that channel.

        The rationale of the secondary channels is the following:

            - Start storing any secondary emitting channels, by checking the
              `link_start` list attribute of each process. If there are
              channel names in the link start, it adds to the secondary
              channels dictionary.
            - Check for secondary receiving channels, by checking the
              `link_end` list attribute. If the link name starts with a
              `__` signature, it will created an implicit link with the last
              process with an output type after the signature. Otherwise,
              it will check is a corresponding link start already exists in
              the at least one process upstream of the pipeline and if so,
              it will update the ``secondary_channels`` attribute with the
              new link.

        Parameters
        ----------
        p : flowcraft.Process.Process


try:<EOL><INDENT>_p_in_name = con["<STR_LIT:input>"]["<STR_LIT>"]<EOL>p_in_name, _ = self._parse_process_name(_p_in_name)<EOL>logger.debug("<STR_LIT>".format(pid, p_in_name))<EOL>_p_out_name = con["<STR_LIT>"]["<STR_LIT>"]<EOL>p_out_name, out_directives = self._parse_process_name(<EOL>_p_out_name)<EOL>logger.debug("<STR_LIT>".format(pid, p_out_name))<EOL><DEDENT>except eh.ProcessError as ex:<EOL><INDENT>logger.error(colored_print(ex.value, "<STR_LIT>"))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>return p_in_name, p_out_name, out_directives<EOL>

Returns the input/output process names and output process directives

        Parameters
        ----------
        con : dict
            Dictionary with the connection information between two processes.

        Returns
        -------
        input_name : str
            Name of the input process
        output_name : str
            Name of the output process
        output_directives : dict
            Parsed directives from the output process


if p.extra_input:<EOL><INDENT>logger.debug("<STR_LIT>".format(<EOL>p.template, p.extra_input))<EOL>if p.extra_input == "<STR_LIT:default>":<EOL><INDENT>if p.input_type in self.main_raw_inputs:<EOL><INDENT>logger.error(colored_print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(p.input_type, p.template), "<STR_LIT>"))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>param = p.input_type<EOL><DEDENT>else:<EOL><INDENT>param = p.extra_input<EOL><DEDENT>dest_channel = "<STR_LIT>".format(p.template, p.pid)<EOL>if param not in self.extra_inputs:<EOL><INDENT>self.extra_inputs[param] = {<EOL>"<STR_LIT>": p.input_type,<EOL>"<STR_LIT>": [dest_channel]<EOL>}<EOL><DEDENT>else:<EOL><INDENT>if self.extra_inputs[param]["<STR_LIT>"] != p.input_type:<EOL><INDENT>logger.error(colored_print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>p.input_type, p.template,<EOL>self.extra_inputs[param]["<STR_LIT>"]),<EOL>"<STR_LIT>"))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>self.extra_inputs[param]["<STR_LIT>"].append(dest_channel)<EOL><DEDENT>logger.debug("<STR_LIT>"<EOL>"<STR_LIT>".format(p.template, param,<EOL>self.extra_inputs[param]))<EOL>p.update_main_input(<EOL>"<STR_LIT>".format(p.input_channel, dest_channel)<EOL>)<EOL><DEDENT>

Given a process, this method updates the
        :attr:`~Process.extra_inputs` attribute with the corresponding extra
        inputs of that process

        Parameters
        ----------
        p : flowcraft.Process.Process


dict_viz = {<EOL>"<STR_LIT:name>": "<STR_LIT:root>",<EOL>"<STR_LIT>": []<EOL>}<EOL>last_of_us = {}<EOL>f_tree = self._fork_tree if self._fork_tree else {<NUM_LIT:1>: [<NUM_LIT:1>]}<EOL>for x, (k, v) in enumerate(f_tree.items()):<EOL><INDENT>for p in self.processes[<NUM_LIT:1>:]:<EOL><INDENT>if x == <NUM_LIT:0> and p.lane not in [k] + v:<EOL><INDENT>continue<EOL><DEDENT>if x > <NUM_LIT:0> and p.lane not in v:<EOL><INDENT>continue<EOL><DEDENT>if not p.parent_lane:<EOL><INDENT>lst = dict_viz["<STR_LIT>"]<EOL><DEDENT>else:<EOL><INDENT>lst = last_of_us[p.parent_lane]<EOL><DEDENT>tooltip = {<EOL>"<STR_LIT:name>": "<STR_LIT>".format(p.template, p.pid),<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": p.pid,<EOL>"<STR_LIT:input>": p.input_type,<EOL>"<STR_LIT>": p.output_type if p.output_type else "<STR_LIT:None>",<EOL>"<STR_LIT>": p.lane,<EOL>},<EOL>"<STR_LIT>": []<EOL>}<EOL>dir_var = "<STR_LIT>"<EOL>for k2, v2 in p.directives.items():<EOL><INDENT>dir_var += k2<EOL>for d in v2:<EOL><INDENT>try:<EOL><INDENT>directive = v2[d].replace("<STR_LIT:'>", "<STR_LIT>").replace('<STR_LIT:">', '<STR_LIT>')if isinstance(v2[d], str) else v2[d]<EOL>dir_var += "<STR_LIT>".format(d, directive)<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>if dir_var:<EOL><INDENT>tooltip["<STR_LIT>"]["<STR_LIT>"] = dir_var<EOL><DEDENT>else:<EOL><INDENT>tooltip["<STR_LIT>"]["<STR_LIT>"] = "<STR_LIT>"<EOL><DEDENT>lst.append(tooltip)<EOL>last_of_us[p.lane] = lst[-<NUM_LIT:1>]["<STR_LIT>"]<EOL><DEDENT><DEDENT>self.dag_to_file(dict_viz)<EOL>with open(os.path.join(dirname(self.nf_file),<EOL>"<STR_LIT>"), "<STR_LIT:w>") as fh:<EOL><INDENT>fh.write(json.dumps(self._fork_tree))<EOL><DEDENT>return self._render_config("<STR_LIT>", {"<STR_LIT:data>": dict_viz})<EOL>

Write pipeline attributes to json

        This function writes the pipeline and their attributes to a json file,
        that is intended to be read by resources/pipeline_graph.html to render
        a graphical output showing the DAG.


<EOL>dict_of_parsed = {}<EOL>terminal_width = shutil.get_terminal_size().columns - <NUM_LIT:3><EOL>center_string = "<STR_LIT>"<EOL>tags_list = [<EOL>[<EOL>"<STR_LIT:=>" * int(terminal_width / <NUM_LIT:4>),<EOL>"<STR_LIT>".format(<EOL>"<STR_LIT:=>" * int(((terminal_width/<NUM_LIT:2> - len(center_string)) / <NUM_LIT:2>)),<EOL>center_string)<EOL>,<EOL>"<STR_LIT>".format("<STR_LIT:=>" * int(terminal_width / <NUM_LIT:4>))<EOL>],<EOL>["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>[<EOL>"<STR_LIT:=>" * int(terminal_width / <NUM_LIT:4>),<EOL>"<STR_LIT:=>" * int(terminal_width / <NUM_LIT:2>),<EOL>"<STR_LIT:=>" * int(terminal_width / <NUM_LIT:4>)<EOL>]<EOL>]<EOL>for p in self.processes[<NUM_LIT:1>:]:<EOL><INDENT>template = p.template<EOL>if template in dict_of_parsed:<EOL><INDENT>continue<EOL><DEDENT>dict_of_parsed[template] = {<EOL>"<STR_LIT>": []<EOL>}<EOL>for directives in p.directives.values():<EOL><INDENT>try:<EOL><INDENT>repo = directives["<STR_LIT>"]<EOL>default_version = directives["<STR_LIT:version>"]<EOL><DEDENT>except KeyError:<EOL><INDENT>repo = "<STR_LIT>"<EOL>default_version = "<STR_LIT>"<EOL><DEDENT>repo_version = repo + default_version<EOL>if repo_version not in dict_of_parsed[template]["<STR_LIT>"]:<EOL><INDENT>r = requests.get(<EOL>"<STR_LIT>"<EOL>.format(repo)<EOL>)<EOL>if r.status_code != <NUM_LIT>:<EOL><INDENT>r_content = json.loads(r.content)["<STR_LIT>"]<EOL>for version in r_content:<EOL><INDENT>printed_version = (version["<STR_LIT:name>"] + "<STR_LIT:*>")if version["<STR_LIT:name>"] == default_versionelse version["<STR_LIT:name>"]<EOL>tags_list.append([template, repo, printed_version])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>tags_list.append([template, repo, "<STR_LIT>"])<EOL><DEDENT><DEDENT>dict_of_parsed[template]["<STR_LIT>"].append(repo_version)<EOL><DEDENT><DEDENT>for x, entry in enumerate(tags_list):<EOL><INDENT>color = "<STR_LIT>" if x < <NUM_LIT:3> else("<STR_LIT>" if x % <NUM_LIT:2> != <NUM_LIT:0> else "<STR_LIT>")<EOL>final_width = [<EOL>int(terminal_width/<NUM_LIT:4>),<EOL>int(terminal_width/<NUM_LIT:2>),<EOL>int(terminal_width/<NUM_LIT:4>)<EOL>]<EOL>sys.stdout.write(<EOL>colored_print("<STR_LIT>".format(<EOL>*entry, *final_width), color)<EOL>)<EOL><DEDENT>sys.stdout.write("<STR_LIT>".format("<STR_LIT>",<EOL>terminal_width + <NUM_LIT:3>))<EOL>

Export all dockerhub tags associated with each component given by
the -t flag.


params_json = {}<EOL>for p in self.processes[<NUM_LIT:1>:]:<EOL><INDENT>params_json[p.template] = p.params<EOL><DEDENT>sys.stdout.write(json.dumps(params_json))<EOL>

Export pipeline params as a JSON to stdout

        This run mode iterates over the pipeline processes and exports the
        params dictionary of each component as a JSON to stdout.


Main pipeline builder

        This method is responsible for building the
        :py:attr:`NextflowGenerator.template` attribute that will contain
        the nextflow code of the pipeline.

        First it builds the header, then sets the main channels, the
        secondary inputs, secondary channels and finally the
        status channels. When the pipeline is built, is writes the code
        to a nextflow file.


def dag_to_file(self, dict_viz, output_file="<STR_LIT>"):

outfile_dag = open(os.path.join(dirname(self.nf_file), output_file)<EOL>, "<STR_LIT:w>")<EOL>outfile_dag.write(json.dumps(dict_viz))<EOL>outfile_dag.close()<EOL>

Writes dag to output file

        Parameters
        ----------
        dict_viz: dict
            Tree like dictionary that is used to export tree data of processes
            to html file and here for the dotfile .treeDag.json


if not os.path.exists(self.trace_file):<EOL><INDENT>raise eh.InspectionError("<STR_LIT>"<EOL>"<STR_LIT>".format(self.trace_file))<EOL><DEDENT>if not os.path.exists(self.log_file):<EOL><INDENT>raise eh.InspectionError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>

Checks whetner the trace and log files are available


def _cpu_load_parser(self, cpus, cpu_per, t):

try:<EOL><INDENT>_cpus = float(cpus)<EOL>_cpu_per = float(cpu_per.replace("<STR_LIT:U+002C>", "<STR_LIT:.>").replace("<STR_LIT:%>", "<STR_LIT>"))<EOL>hours = self._hms(t) / <NUM_LIT> / <NUM_LIT><EOL>return ((_cpu_per / (<NUM_LIT:100> * _cpus)) * _cpus) * hours<EOL><DEDENT>except ValueError:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>

Parses the cpu load from the number of cpus and its usage
        percentage and returnsde cpu/hour measure

        Parameters
        ----------
        cpus : str
            Number of cpus allocated.
        cpu_per : str
            Percentage of cpu load measured (e.g.: 200,5%).
        t : str
            The time string can be something like '20s', '1m30s' or '300ms'.


<EOL>pipeline_path = get_nextflow_filepath(self.log_file)<EOL>pipeline_hash = hashlib.md5()<EOL>with open(pipeline_path, "<STR_LIT:rb>") as fh:<EOL><INDENT>for chunk in iter(lambda: fh.read(<NUM_LIT>), b"<STR_LIT>"):<EOL><INDENT>pipeline_hash.update(chunk)<EOL><DEDENT><DEDENT>workdir = self.workdir.encode("<STR_LIT:utf8>")<EOL>hostname = socket.gethostname().encode("<STR_LIT:utf8>")<EOL>hardware_addr = str(uuid.getnode()).encode("<STR_LIT:utf8>")<EOL>dir_hash = hashlib.md5(workdir + hostname + hardware_addr)<EOL>return pipeline_hash.hexdigest() + dir_hash.hexdigest()<EOL>


if direction == "<STR_LIT:left>" and self.padding != <NUM_LIT:0>:<EOL><INDENT>self.padding -= <NUM_LIT:1><EOL><DEDENT>if direction == "<STR_LIT:right>" andself.screen.getmaxyx()[<NUM_LIT:1>] + self.padding < self.max_width:<EOL><INDENT>self.padding += <NUM_LIT:1><EOL><DEDENT>


This function is bound to the SIGINT signal (like ctrl+c) to graciously
    exit the program and reset the curses options.


if direction == "<STR_LIT>" and self.top_line != <NUM_LIT:0>:<EOL><INDENT>self.top_line -= <NUM_LIT:1><EOL><DEDENT>elif direction == "<STR_LIT>" andself.screen.getmaxyx()[<NUM_LIT:0>] + self.top_line<= self.content_lines + <NUM_LIT:3>:<EOL><INDENT>self.top_line += <NUM_LIT:1><EOL><DEDENT>


try:<EOL><INDENT>self.log_parser()<EOL><DEDENT>except (FileNotFoundError, StopIteration) as e:<EOL><INDENT>logger.debug("<STR_LIT>" + str(sys.exc_info()[<NUM_LIT:0>]))<EOL>self.log_retry += <NUM_LIT:1><EOL>if self.log_retry == self.MAX_RETRIES:<EOL><INDENT>raise e<EOL><DEDENT><DEDENT>try:<EOL><INDENT>self.trace_parser()<EOL><DEDENT>except (FileNotFoundError, StopIteration) as e:<EOL><INDENT>logger.debug("<STR_LIT>" + str(sys.exc_info()[<NUM_LIT:0>]))<EOL>self.trace_retry += <NUM_LIT:1><EOL>if self.trace_retry == self.MAX_RETRIES:<EOL><INDENT>raise e<EOL><DEDENT><DEDENT>

Wrapper method that calls the appropriate main updating methods of
        the inspection.

        It is meant to be used inside a loop (like while), so that it can
        continuously update the class attributes from the trace and log files.
        It already implements checks to parse these files only when they
        change, and they ignore entries that have been previously processes.


def _update_tag_status(self, process, vals):

good_status = ["<STR_LIT>", "<STR_LIT>"]<EOL>for v in list(vals)[::-<NUM_LIT:1>]:<EOL><INDENT>p = self.processes[process]<EOL>tag = v["<STR_LIT>"]<EOL>if tag in p["<STR_LIT>"]:<EOL><INDENT>p["<STR_LIT>"].remove(tag)<EOL>if v["<STR_LIT:status>"] in good_status:<EOL><INDENT>p["<STR_LIT>"].add(tag)<EOL><DEDENT>elif v["<STR_LIT:status>"] == "<STR_LIT>":<EOL><INDENT>if not v["<STR_LIT>"]:<EOL><INDENT>v["<STR_LIT>"] = "<STR_LIT>"<EOL><DEDENT>self.process_tags[process][tag]["<STR_LIT>"] =self._retrieve_log(join(v["<STR_LIT>"], "<STR_LIT>"))<EOL>p["<STR_LIT>"].add(tag)<EOL><DEDENT><DEDENT>elif tag in p["<STR_LIT>"]:<EOL><INDENT>if v["<STR_LIT:status>"] in good_status:<EOL><INDENT>p["<STR_LIT>"].remove(tag)<EOL>p["<STR_LIT>"].remove(tag)<EOL>del self.process_tags[process][tag]["<STR_LIT>"]<EOL><DEDENT>elif self.run_status == "<STR_LIT>":<EOL><INDENT>p["<STR_LIT>"].remove(tag)<EOL><DEDENT><DEDENT>elif v["<STR_LIT:status>"] in good_status:<EOL><INDENT>p["<STR_LIT>"].add(tag)<EOL><DEDENT>if v["<STR_LIT:status>"] not in good_status:<EOL><INDENT>if v["<STR_LIT>"] in list(p["<STR_LIT>"]) + list(p["<STR_LIT>"]):<EOL><INDENT>vals.remove(v)<EOL><DEDENT><DEDENT><DEDENT>return vals<EOL>

Updates the 'submitted', 'finished', 'failed' and 'retry' status
        of each process/tag combination.

        Process/tag combinations provided to this method already appear on
        the trace file, so their submission status is updated based on their
        execution status from nextflow.

        For instance, if a tag is successfully
        complete, it is moved from the 'submitted' to the 'finished' list.
        If not, it is moved to the 'failed' list.

        Parameters
        ----------
        process : str
            Name of the current process. Must be present in attr:`processes`
        vals : list
            List of tags for this process that have been gathered in the
            trace file.


with open(self.log_file) as fh:<EOL><INDENT>last_lines = fh.readlines()[-n:]<EOL><DEDENT>return last_lines<EOL>

Returns a list with the last ``n`` lines of the nextflow log file

        Parameters
        ----------
        n : int
            Number of last lines from the log file

        Returns
        -------
        list
            List of strings with the nextflow log


try:<EOL><INDENT>dag_file = open(os.path.join(self.workdir, "<STR_LIT>"))<EOL>dag_json = json.load(dag_file)<EOL><DEDENT>except (FileNotFoundError, json.decoder.JSONDecodeError):<EOL><INDENT>logger.warning(colored_print(<EOL>"<STR_LIT>",<EOL>"<STR_LIT>"))<EOL>dag_json = {}<EOL><DEDENT>return dag_json<EOL>

Function that opens the dotfile named .treeDag.json in the current
        working directory

        Returns
        -------
        Returns a dictionary with the dag object to be used in the post
        instance available through the method _establish_connection


good_status = ["<STR_LIT>", "<STR_LIT>"]<EOL>for process, vals in self.trace_info.items():<EOL><INDENT>vals = self._update_tag_status(process, vals)<EOL>self._update_process_resources(process, vals)<EOL>self.process_stats[process] = {}<EOL>inst = self.process_stats[process]<EOL>inst["<STR_LIT>"] = "<STR_LIT:{}>".format(<EOL>len([x for x in vals if x["<STR_LIT:status>"] in good_status]))<EOL>try:<EOL><INDENT>time_array = [self._hms(x["<STR_LIT>"]) for x in vals]<EOL>mean_time = round(sum(time_array) / len(time_array), <NUM_LIT:1>)<EOL>mean_time_str = strftime('<STR_LIT>', gmtime(mean_time))<EOL>inst["<STR_LIT>"] = mean_time_str<EOL><DEDENT>except KeyError:<EOL><INDENT>inst["<STR_LIT>"] = "<STR_LIT:->"<EOL><DEDENT>try:<EOL><INDENT>cpu_hours = [self._cpu_load_parser(<EOL>x["<STR_LIT>"], x["<STR_LIT>"], x["<STR_LIT>"]) for x in vals]<EOL>inst["<STR_LIT>"] = round(sum(cpu_hours), <NUM_LIT:2>)<EOL><DEDENT>except KeyError:<EOL><INDENT>inst["<STR_LIT>"] = "<STR_LIT:->"<EOL><DEDENT>inst["<STR_LIT>"], inst["<STR_LIT>"] =self._assess_resource_warnings(process, vals)<EOL>try:<EOL><INDENT>rss_values = [self._size_coverter(x["<STR_LIT>"]) for x in vals<EOL>if x["<STR_LIT>"] != "<STR_LIT:->"]<EOL>if rss_values:<EOL><INDENT>max_rss = round(max(rss_values))<EOL>rss_str = self._size_compress(max_rss)<EOL><DEDENT>else:<EOL><INDENT>rss_str = "<STR_LIT:->"<EOL><DEDENT>inst["<STR_LIT>"] = rss_str<EOL><DEDENT>except KeyError:<EOL><INDENT>inst["<STR_LIT>"] = "<STR_LIT:->"<EOL><DEDENT>try:<EOL><INDENT>rchar_values = [self._size_coverter(x["<STR_LIT>"]) for x in vals<EOL>if x["<STR_LIT>"] != "<STR_LIT:->"]<EOL>if rchar_values:<EOL><INDENT>avg_rchar = round(sum(rchar_values) / len(rchar_values))<EOL>rchar_str = self._size_compress(avg_rchar)<EOL><DEDENT>else:<EOL><INDENT>rchar_str = "<STR_LIT:->"<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>rchar_str = "<STR_LIT:->"<EOL><DEDENT>inst["<STR_LIT>"] = rchar_str<EOL>try:<EOL><INDENT>wchar_values = [self._size_coverter(x["<STR_LIT>"]) for x in vals<EOL>if x["<STR_LIT>"] != "<STR_LIT:->"]<EOL>if wchar_values:<EOL><INDENT>avg_wchar = round(sum(wchar_values) / len(wchar_values))<EOL>wchar_str = self._size_compress(avg_wchar)<EOL><DEDENT>else:<EOL><INDENT>wchar_str = "<STR_LIT:->"<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>wchar_str = "<STR_LIT:->"<EOL><DEDENT>inst["<STR_LIT>"] = wchar_str<EOL><DEDENT>

Updates the process stats with the information from the processes

        This method is called at the end of each static parsing of the nextflow
        trace file. It re-populates the :attr:`process_stats` dictionary
        with the new stat metrics.


logger.debug(<EOL>"<STR_LIT>".format(lane_list))<EOL>res = []<EOL>lane += <NUM_LIT:1><EOL>for l in lane_list:<EOL><INDENT>res.extend(linear_connection(l, lane))<EOL>lane += <NUM_LIT:1><EOL><DEDENT>return res<EOL>

Parameters
----------
lane_list : list
    Each element should correspond to a list of processes for a given lane
lane : int
    Lane counter before the fork start

Returns
-------
res : list
    List of dictionaries with the links between processes


if FORK_TOKEN + FORK_TOKEN in p_string:<EOL><INDENT>raise SanityError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>

This function checks if there is a starting process after the beginning of
each fork. It checks for duplicated start tokens ['(('].

Parameters
----------
p_string: str
     String with the definition of the pipeline, e.g.::
         'processA processB processC(ProcessD | ProcessE)'


<EOL>for index, val in enumerate(pipeline_links):<EOL><INDENT>if val["<STR_LIT:input>"]["<STR_LIT>"] != "<STR_LIT>":<EOL><INDENT>val["<STR_LIT:input>"]["<STR_LIT>"] = identifiers_to_tags[<EOL>val["<STR_LIT:input>"]["<STR_LIT>"]]<EOL><DEDENT>if val["<STR_LIT>"]["<STR_LIT>"] != "<STR_LIT>":<EOL><INDENT>val["<STR_LIT>"]["<STR_LIT>"] = identifiers_to_tags[<EOL>val["<STR_LIT>"]["<STR_LIT>"]]<EOL><DEDENT><DEDENT>return pipeline_links<EOL>

Removes unique identifiers and add the original process names to the
    already parsed pipelines

    Parameters
    ----------
    identifiers_to_tags : dict
        Match between unique process identifiers and process names
    pipeline_links: list
        Parsed pipeline list with unique identifiers

    Returns
    -------
    list
        Pipeline list with original identifiers


if p_string.count(FORK_TOKEN) != p_string.count(CLOSE_TOKEN):<EOL><INDENT>dict_values = {<EOL>FORK_TOKEN: p_string.count(FORK_TOKEN),<EOL>CLOSE_TOKEN: p_string.count(CLOSE_TOKEN)<EOL>}<EOL>max_bracket = max(dict_values, key=dict_values.get)<EOL>raise SanityError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>str(abs(<EOL>p_string.count(FORK_TOKEN) - p_string.count(CLOSE_TOKEN))),<EOL>max_bracket))<EOL><DEDENT>

This function performs a check for different number of '(' and ')'
characters, which indicates that some forks are poorly constructed.

Parameters
----------
p_string: str
     String with the definition of the pipeline, e.g.::
         'processA processB processC(ProcessD | ProcessE)'


if re.search('<STR_LIT>'.format(CLOSE_TOKEN), p_string):<EOL><INDENT>raise SanityError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>

This function checks if there are processes after the close token. It
searches for everything that isn't "|" or ")" after a ")" token.

Parameters
----------
p_string: str
     String with the definition of the pipeline, e.g.::
         'processA processB processC(ProcessD | ProcessE)'


n = <NUM_LIT:1>  <EOL>while n:<EOL><INDENT>text, n = re.subn(r'<STR_LIT>', '<STR_LIT>', text)<EOL><DEDENT>return text<EOL>

Recursively removes nested brackets

    This function is used to remove nested brackets from fork strings using
    regular expressions

    Parameters
    ----------
    text: str
        The string that contains brackets with inner forks to be removed

    Returns
    -------
    text: str
        the string with only the processes that are not in inner forks, thus
        the processes that belong to a given fork.


self._context = {**self._context, "<STR_LIT>": param_id}<EOL>

Sets the param_id for the process, which will be used to render
        the template.

        Parameters
        ----------
        param_id : str
            The :attr:`param_id` attribute of the process.


<EOL>size_stamp = os.path.getsize(self.log_file)<EOL>self.trace_retry = <NUM_LIT:0><EOL>if size_stamp and size_stamp == self.log_sizestamp:<EOL><INDENT>return<EOL><DEDENT>else:<EOL><INDENT>logger.debug("<STR_LIT>".format(size_stamp))<EOL>self.log_sizestamp = size_stamp<EOL><DEDENT>self._update_pipeline_status()<EOL>

Parses nextflow log file and updates the run status


try:<EOL><INDENT>first_hash, second_hash = hash_str.split("<STR_LIT:/>")<EOL>first_hash_path = join(abspath("<STR_LIT>"), first_hash)<EOL>for l in os.listdir(first_hash_path):<EOL><INDENT>if l.startswith(second_hash):<EOL><INDENT>return join(first_hash_path, l)<EOL><DEDENT><DEDENT><DEDENT>except FileNotFoundError:<EOL><INDENT>return None<EOL><DEDENT>

Expands the hash string of a process (ae/1dasjdm) into a full
        working directory

        Parameters
        ----------
        hash_str : str
            Nextflow process hash with the beggining of the work directory

        Returns
        -------
        str
            Path to working directory of the hash string


logger.debug("<STR_LIT>"<EOL>"<STR_LIT>".format(self.broadcast_address))<EOL>try:<EOL><INDENT>with open("<STR_LIT>") as fh:<EOL><INDENT>metadata = [json.load(fh)]<EOL><DEDENT><DEDENT>except:<EOL><INDENT>metadata = []<EOL><DEDENT>start_json = {<EOL>"<STR_LIT:data>": {"<STR_LIT>": metadata}<EOL>}<EOL>try:<EOL><INDENT>requests.post(<EOL>self.broadcast_address,<EOL>json={"<STR_LIT>": report_id, "<STR_LIT>": start_json,<EOL>"<STR_LIT:status>": self.status_info}<EOL>)<EOL><DEDENT>except requests.exceptions.ConnectionError:<EOL><INDENT>logger.error(colored_print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>", "<STR_LIT>"))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>

Sends a POST request to initialize the live reports

        Parameters
        ----------
        report_id : str
            Hash of the report JSON as retrieved from :func:`~_get_report_hash`


if self.watch:<EOL><INDENT>pipeline_path = get_nextflow_filepath(self.log_file)<EOL>pipeline_hash = hashlib.md5()<EOL>with open(pipeline_path, "<STR_LIT:rb>") as fh:<EOL><INDENT>for chunk in iter(lambda: fh.read(<NUM_LIT>), b"<STR_LIT>"):<EOL><INDENT>pipeline_hash.update(chunk)<EOL><DEDENT><DEDENT>workdir = os.getcwd().encode("<STR_LIT:utf8>")<EOL>hostname = socket.gethostname().encode("<STR_LIT:utf8>")<EOL>hardware_addr = str(uuid.getnode()).encode("<STR_LIT:utf8>")<EOL>dir_hash = hashlib.md5(workdir + hostname + hardware_addr)<EOL>return pipeline_hash.hexdigest() + dir_hash.hexdigest()<EOL><DEDENT>else:<EOL><INDENT>with open(self.report_file) as fh:<EOL><INDENT>report_json = json.loads(fh.read())<EOL><DEDENT>metadata = report_json["<STR_LIT:data>"]["<STR_LIT>"][<NUM_LIT:0>]["<STR_LIT>"]<EOL>try:<EOL><INDENT>report_id = metadata["<STR_LIT>"] + metadata["<STR_LIT>"]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise eh.ReportError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return report_id<EOL><DEDENT>


def build_downstream(self, process_descriptions, task, all_tasks,<EOL>task_pipeline,<EOL>count_forks, total_tasks, forks):

if task in process_descriptions:<EOL><INDENT>if process_descriptions[task][<NUM_LIT:2>] is not None:<EOL><INDENT>if len(process_descriptions[task][<NUM_LIT:2>].split("<STR_LIT:|>")) > <NUM_LIT:1>:<EOL><INDENT>local_forks = process_descriptions[task][<NUM_LIT:2>].split("<STR_LIT:|>")<EOL>for local_fork in local_forks:<EOL><INDENT>if local_fork in total_tasks:<EOL><INDENT>count_forks += <NUM_LIT:1><EOL>task_pipeline.append(process_descriptions[task][<NUM_LIT:2>])<EOL>self.define_pipeline_string(<EOL>process_descriptions,<EOL>local_fork,<EOL>False,<EOL>True,<EOL>count_forks,<EOL>total_tasks,<EOL>forks<EOL>)<EOL><DEDENT><DEDENT>return task_pipeline<EOL><DEDENT>else:<EOL><INDENT>if process_descriptions[task][<NUM_LIT:2>] in total_tasks:<EOL><INDENT>task_pipeline.append(process_descriptions[task][<NUM_LIT:2>].split("<STR_LIT:|>")[<NUM_LIT:0>])<EOL>self.build_downstream(<EOL>process_descriptions,<EOL>process_descriptions[task][<NUM_LIT:2>].split("<STR_LIT:|>")[<NUM_LIT:0>],<EOL>all_tasks,<EOL>task_pipeline,<EOL>count_forks,<EOL>total_tasks,<EOL>forks<EOL>)<EOL><DEDENT>return task_pipeline<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return task_pipeline<EOL><DEDENT><DEDENT>

Builds the downstream pipeline of the current process

        Checks for the downstream processes to the current process and
        adds them to the current pipeline fragment.

        Parameters
        ----------
        process_descriptions : dict
            Information of processes input, output and if is forkable
        task : str
            Current process
        all_tasks : list
            A list of all provided processes
        task_pipeline : list
            Current pipeline fragment
        count_forks : int
            Current number of forks
        total_tasks : str
            All space separated processes
        forks : list
            Current forks
        Returns
        -------
        list : resulting pipeline fragment


logger.info(colored_print(<EOL>"<STR_LIT>",<EOL>"<STR_LIT>"))<EOL>prefix = "<STR_LIT>".format(recipes.__name__)<EOL>for importer, modname, _ in pkgutil.iter_modules(recipes.__path__, prefix):<EOL><INDENT>_module = importer.find_module(modname).load_module(modname)<EOL>_recipe_classes = [cls for cls in _module.__dict__.values() if<EOL>isinstance(cls, type)]<EOL>for cls in _recipe_classes:<EOL><INDENT>recipe_cls = cls()<EOL>if hasattr(recipe_cls, "<STR_LIT:name>"):<EOL><INDENT>logger.info(colored_print("<STR_LIT>".format(recipe_cls.name), "<STR_LIT>"))<EOL>if full:<EOL><INDENT>logger.info(colored_print("<STR_LIT>".format(recipe_cls.__doc__), "<STR_LIT>"))<EOL>logger.info(colored_print("<STR_LIT>".format(recipe_cls.pipeline_str), "<STR_LIT>"))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>sys.exit(<NUM_LIT:0>)<EOL>

Method that iterates over all available recipes and prints their
    information to the standard output

    Parameters
    ----------
    full : bool
        If true, it will provide the pipeline string along with the recipe name


def define_pipeline_string(self, process_descriptions, tasks,<EOL>check_upstream,<EOL>check_downstream, count_forks, total_tasks,<EOL>forks):

tasks_array = tasks.split()<EOL>for task_unsplit in tasks_array:<EOL><INDENT>task = task_unsplit.split("<STR_LIT:=>")[<NUM_LIT:0>]<EOL>if task not in process_descriptions.keys():<EOL><INDENT>logger.error(<EOL>colored_print(<EOL>"<STR_LIT>".format(task),<EOL>"<STR_LIT>"<EOL>)<EOL>)<EOL>sys.exit()<EOL><DEDENT>else:<EOL><INDENT>process_split = task_unsplit.split("<STR_LIT:=>")<EOL>if len(process_split) > <NUM_LIT:1>:<EOL><INDENT>self.process_to_id[process_split[<NUM_LIT:0>]] = process_split[<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if not bool([x for x in forks if task in x]) and not bool([y for y in forks if process_descriptions[task][<NUM_LIT:2>] in y]):<EOL><INDENT>task_pipeline = []<EOL>if task in process_descriptions:<EOL><INDENT>if check_upstream:<EOL><INDENT>task_pipeline = self.build_upstream(<EOL>process_descriptions,<EOL>task,<EOL>tasks_array,<EOL>task_pipeline,<EOL>count_forks,<EOL>total_tasks,<EOL>forks<EOL>)<EOL><DEDENT>task_pipeline.append(task)<EOL>if check_downstream:<EOL><INDENT>task_pipeline = self.build_downstream(<EOL>process_descriptions,<EOL>task,<EOL>tasks_array,<EOL>task_pipeline,<EOL>count_forks,<EOL>total_tasks,<EOL>forks<EOL>)<EOL><DEDENT><DEDENT>forks.append(list(OrderedDict.fromkeys(task_pipeline)))<EOL><DEDENT>elif bool([y for y in forks if process_descriptions[task][<NUM_LIT:2>] in y]):<EOL><INDENT>for fork in forks:<EOL><INDENT>if task not in fork:<EOL><INDENT>try:<EOL><INDENT>dependent_index = fork.index(process_descriptions[task][<NUM_LIT:2>])<EOL>fork.insert(dependent_index, task)<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>for i in range(<NUM_LIT:0>, len(forks)):<EOL><INDENT>for j in range(<NUM_LIT:0>, len(forks[i])):<EOL><INDENT>try:<EOL><INDENT>if len(forks[i][j].split("<STR_LIT:|>")) > <NUM_LIT:1>:<EOL><INDENT>forks[i][j] = forks[i][j].split("<STR_LIT:|>")<EOL>tmp_fork = []<EOL>for s in forks[i][j]:<EOL><INDENT>if s in total_tasks:<EOL><INDENT>tmp_fork.append(s)<EOL><DEDENT><DEDENT>forks[i][j] = tmp_fork<EOL><DEDENT><DEDENT>except AttributeError as e:<EOL><INDENT>continue<EOL><DEDENT><DEDENT><DEDENT>return forks<EOL>

Builds the possible forks and connections between the provided
        processes

        This method loops through all the provided tasks and builds the
        upstream and downstream pipeline if required. It then returns all
        possible forks than need to be merged à posteriori`

        Parameters
        ----------
        process_descriptions : dict
            Information of processes input, output and if is forkable
        tasks : str
            Space separated processes
        check_upstream : bool
            If is to build the upstream pipeline of the current task
        check_downstream : bool
            If is to build the downstream pipeline of the current task
        count_forks : int
            Number of current forks
        total_tasks : str
            All space separated processes
        forks : list
            Current forks

        Returns
        -------
        list : List with all the possible pipeline forks


if "<STR_LIT:(>" in pipeline_string or "<STR_LIT:)>" in pipeline_string or "<STR_LIT:|>" inpipeline_string:<EOL><INDENT>logger.error(<EOL>colored_print("<STR_LIT>", "<STR_LIT>")<EOL>)<EOL>return False<EOL><DEDENT>return True<EOL>

Validate pipeline string

        Validates the pipeline string by searching for forbidden characters

        Parameters
        ----------
        pipeline_string : str
            STring with the processes provided

        Returns
        -------


msg_type = msg.__class__.__name__.lower()<EOL>key_fmt = msg.profile + "<STR_LIT:_>" + msg_type<EOL>if isinstance(msg._auth, (MutableSequence, tuple)):<EOL><INDENT>cfg.pwd[key_fmt] = "<STR_LIT>".join(msg._auth)<EOL><DEDENT>else:<EOL><INDENT>cfg.pwd[key_fmt] = msg._auth<EOL><DEDENT>

Updates the profile's auth entry with values set by the user.
This will overwrite existing values.

Args:
    :msg: (Message class) an instance of a message class.
    :cfg: (jsonconfig.Config) config instance.


if msg.profile not in cfg.data:<EOL><INDENT>raise UnknownProfileError(msg.profile)<EOL><DEDENT>

Verifies the profile name exists in the config.json file.

Args:
    :msg: (Message class) an instance of a message class.
    :cfg: (jsonconfig.Config) config instance.


def configure_profile(msg_type, profile_name, data, auth):

with jsonconfig.Config("<STR_LIT>", indent=<NUM_LIT:4>) as cfg:<EOL><INDENT>write_data(msg_type, profile_name, data, cfg)<EOL>write_auth(msg_type, profile_name, auth, cfg)<EOL><DEDENT>print("<STR_LIT>" + profile_name + "<STR_LIT>")<EOL>print("<STR_LIT>" + cfg.filename)<EOL>

Create the profile entry.

Args:
    :msg_type: (str) message type to create config entry.
    :profile_name: (str) name of the profile entry
    :data: (dict) dict values for the 'settings'
    :auth: (dict) auth parameters


self.message["<STR_LIT>"] = self.chat_id<EOL>self.message["<STR_LIT:text>"] = "<STR_LIT>"<EOL>if self.from_:<EOL><INDENT>self.message["<STR_LIT:text>"] += "<STR_LIT>" + self.from_ + "<STR_LIT:\n>"<EOL><DEDENT>if self.subject:<EOL><INDENT>self.message["<STR_LIT:text>"] += "<STR_LIT>" + self.subject + "<STR_LIT:\n>"<EOL><DEDENT>self.message["<STR_LIT:text>"] += self.body<EOL>self.message.update(self.params)<EOL>


if username is not None:<EOL><INDENT>chats = requests.get(self.base_url + "<STR_LIT>").json()<EOL>user = username.split("<STR_LIT:@>")[-<NUM_LIT:1>]<EOL>for chat in chats["<STR_LIT:result>"]:<EOL><INDENT>if chat["<STR_LIT:message>"]["<STR_LIT>"]["<STR_LIT:username>"] == user:<EOL><INDENT>return chat["<STR_LIT:message>"]["<STR_LIT>"]["<STR_LIT:id>"]<EOL><DEDENT><DEDENT><DEDENT>

Lookup chat_id of username if chat_id is unknown via API call.


class_name = type(self).__name__<EOL>output = "<STR_LIT>".format(class_name)<EOL>for attr in self:<EOL><INDENT>if attr == "<STR_LIT>":<EOL><INDENT>output += "<STR_LIT>"<EOL><DEDENT>elif attr == "<STR_LIT:body>":<EOL><INDENT>output += "<STR_LIT>".format(attr, reprlib.repr(getattr(self, attr)))<EOL><DEDENT>else:<EOL><INDENT>output += "<STR_LIT>".format(attr, getattr(self, attr))<EOL><DEDENT><DEDENT>output += "<STR_LIT:)>"<EOL>return output<EOL>

repr(self) in debugging format with auth attr obfuscated.


self._generate_email()<EOL>if self.verbose:<EOL><INDENT>print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(timestamp())<EOL>)<EOL><DEDENT>recipients = []<EOL>for i in (self.to, self.cc, self.bcc):<EOL><INDENT>if i:<EOL><INDENT>if isinstance(i, MutableSequence):<EOL><INDENT>recipients += i<EOL><DEDENT>else:<EOL><INDENT>recipients.append(i)<EOL><DEDENT><DEDENT><DEDENT>session = self._get_session()<EOL>if self.verbose:<EOL><INDENT>print(timestamp(), "<STR_LIT>")<EOL><DEDENT>session.sendmail(self.from_, recipients, self.message.as_string())<EOL>session.quit()<EOL>if self.verbose:<EOL><INDENT>print(timestamp(), "<STR_LIT>")<EOL><DEDENT>if self.verbose:<EOL><INDENT>print(<EOL>timestamp(),<EOL>type(self).__name__ + "<STR_LIT>",<EOL>self.__str__(indentation="<STR_LIT>"),<EOL>)<EOL><DEDENT>print("<STR_LIT>")<EOL>

Send the message.
First, a message is constructed, then a session with the email
servers is created, finally the message is sent and the session
is stopped.


if self.port in (<NUM_LIT>, "<STR_LIT>"):<EOL><INDENT>session = self._get_ssl()<EOL><DEDENT>elif self.port in (<NUM_LIT>, "<STR_LIT>"):<EOL><INDENT>session = self._get_tls()<EOL><DEDENT>try:<EOL><INDENT>session.login(self.from_, self._auth)<EOL><DEDENT>except SMTPResponseException as e:<EOL><INDENT>raise MessageSendError(e.smtp_error.decode("<STR_LIT>"))<EOL><DEDENT>return session<EOL>


return smtplib.SMTP_SSL(<EOL>self.server, self.port, context=ssl.create_default_context()<EOL>)<EOL>


if self.body:<EOL><INDENT>b = MIMEText("<STR_LIT:text>", "<STR_LIT>")<EOL>b.set_payload(self.body)<EOL>self.message.attach(b)<EOL><DEDENT>


print(Email(**args)) method.
           Indentation value can be overridden in the function call.
           The default is new line


@main.command("<STR_LIT>")<EOL>@click.argument("<STR_LIT>", type=click.STRING, required=False)<EOL>@click.argument("<STR_LIT:body>", type=click.STRING, default="<STR_LIT>", required=False)<EOL>@option("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", help="<STR_LIT>")<EOL>@option("<STR_LIT>", "<STR_LIT>", multiple=True, help="<STR_LIT>")<EOL>@option("<STR_LIT>", "<STR_LIT>", help="<STR_LIT>")<EOL>@option(<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>multiple=True,<EOL>help="<STR_LIT>",<EOL>)<EOL>@option("<STR_LIT>", "<STR_LIT>", is_flag=True, help="<STR_LIT>")<EOL>@option(<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>is_flag=True,<EOL>help="<STR_LIT>",<EOL>)<EOL>@click.pass_context<EOL>def main_whatsapp(ctx, **kwds):

send_message("<STR_LIT>", kwds)<EOL>

Send WhatsApp text message via the Twilio API.

    * [PROFILE]: Pre-configured user profile.

    * [BODY]:    Message body text.

    * Example: messages whatsapp myWhatsAppProfile 'hello from whatsapp' -t '+12223334444' --verbose


url = (<EOL>"<STR_LIT>"<EOL>+ self._auth[<NUM_LIT:0>]<EOL>+ "<STR_LIT>"<EOL>)<EOL>data = {<EOL>"<STR_LIT>": self.from_,<EOL>"<STR_LIT>": self.to,<EOL>"<STR_LIT>": self.body,<EOL>"<STR_LIT>": self.attachments,<EOL>}<EOL>if self.verbose:<EOL><INDENT>print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(timestamp())<EOL>)<EOL><DEDENT>try:<EOL><INDENT>resp = requests.post(url, data=data, auth=(self._auth[<NUM_LIT:0>], self._auth[<NUM_LIT:1>]))<EOL>resp.raise_for_status()<EOL><DEDENT>except requests.exceptions.RequestException as e:<EOL><INDENT>exc = "<STR_LIT>".format(e, resp.json()["<STR_LIT:message>"])<EOL>raise MessageSendError(exc)<EOL><DEDENT>self.sid = resp.json()["<STR_LIT>"]<EOL>if self.verbose:<EOL><INDENT>print(<EOL>timestamp(),<EOL>type(self).__name__ + "<STR_LIT>",<EOL>self.__str__(indentation="<STR_LIT>"),<EOL>"<STR_LIT>",<EOL>resp.status_code,<EOL>)<EOL><DEDENT>print("<STR_LIT>")<EOL>return resp<EOL>

Send the SMS/MMS message.
Set self.sid to return code of message.


self._construct_message()<EOL>if self.verbose:<EOL><INDENT>print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(timestamp())<EOL>)<EOL><DEDENT>if encoding == "<STR_LIT>":<EOL><INDENT>resp = requests.post(self.url, json=self.message)<EOL><DEDENT>elif encoding == "<STR_LIT:url>":<EOL><INDENT>resp = requests.post(self.url, data=self.message)<EOL><DEDENT>try:<EOL><INDENT>resp.raise_for_status()<EOL>if resp.history and resp.history[<NUM_LIT:0>].status_code >= <NUM_LIT>:<EOL><INDENT>raise MessageSendError("<STR_LIT>")<EOL><DEDENT>elif "<STR_LIT>" in resp.text:<EOL><INDENT>raise MessageSendError("<STR_LIT>")<EOL><DEDENT><DEDENT>except (requests.exceptions.HTTPError, MessageSendError) as e:<EOL><INDENT>raise MessageSendError(e)<EOL><DEDENT>if self.verbose:<EOL><INDENT>print(<EOL>timestamp(),<EOL>type(self).__name__,<EOL>"<STR_LIT>",<EOL>self.__str__(indentation="<STR_LIT>"),<EOL>"<STR_LIT>",<EOL>resp.status_code,<EOL>)<EOL><DEDENT>print("<STR_LIT>")<EOL>

Send the message via HTTP POST, default is json-encoded.


self.message = {"<STR_LIT>": self._auth, "<STR_LIT>": self.channel}<EOL>super()._construct_message()<EOL>

Set the message token/channel, then call the bas class constructor.


def send(msg_type, send_async=False, *args, **kwargs):

message = message_factory(msg_type, *args, **kwargs)<EOL>try:<EOL><INDENT>if send_async:<EOL><INDENT>message.send_async()<EOL><DEDENT>else:<EOL><INDENT>message.send()<EOL><DEDENT><DEDENT>except MessageSendError as e:<EOL><INDENT>err_exit("<STR_LIT>", e)<EOL><DEDENT>

Constructs a message class and sends the message.
Defaults to sending synchronously.  Set send_async=True to send
asynchronously.

Args:
    :msg_type: (str) the type of message to send, i.e. 'Email'
    :send_async: (bool) default is False, set True to send asynchronously.
    :kwargs: (dict) keywords arguments that are required for the
        various message types.  See docstrings for each type.
        i.e. help(messages.Email), help(messages.Twilio), etc.

Example:
    >>> kwargs = {
              from_: 'me@here.com',
              to: 'you@there.com',
              auth: 'yourPassword',
              subject: 'Email Subject',
              body: 'Your message to send',
              attachments: ['filepath1', 'filepath2'],
        }
    >>> messages.send('email', **kwargs)
    Message sent...


def check_valid(msg_type, attr, value, func, exec_info):

if value is not None:<EOL><INDENT>if isinstance(value, MutableSequence):<EOL><INDENT>for v in value:<EOL><INDENT>if not func(v):<EOL><INDENT>raise InvalidMessageInputError(msg_type, attr, value, exec_info)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if not func(value):<EOL><INDENT>raise InvalidMessageInputError(msg_type, attr, value, exec_info)<EOL><DEDENT><DEDENT><DEDENT>

Checker function all validate_* functions below will call.
Raises InvalidMessageInputError if input is not valid as per
given func.


check_valid("<STR_LIT>", attr, value, validus.isurl, "<STR_LIT:url>")<EOL>


if attr in ("<STR_LIT>", "<STR_LIT:to>"):<EOL><INDENT>if value is not None and "<STR_LIT>" in value:<EOL><INDENT>value = value.split("<STR_LIT>")[-<NUM_LIT:1>]<EOL><DEDENT>check_valid(<EOL>"<STR_LIT>",<EOL>attr,<EOL>value,<EOL>validus.isint,<EOL>"<STR_LIT>",<EOL>)<EOL><DEDENT>elif attr in ("<STR_LIT>"):<EOL><INDENT>check_valid("<STR_LIT>", attr, value, validus.isurl, "<STR_LIT:url>")<EOL><DEDENT>


if attr in ("<STR_LIT>", "<STR_LIT:to>"):<EOL><INDENT>check_valid("<STR_LIT>", attr, value, validus.isphone, "<STR_LIT>")<EOL><DEDENT>elif attr in ("<STR_LIT>"):<EOL><INDENT>check_valid("<STR_LIT>", attr, value, validus.isurl, "<STR_LIT:url>")<EOL><DEDENT>


def verbatim_tags(parser, token, endtagname):

text_and_nodes = []<EOL>while <NUM_LIT:1>:<EOL><INDENT>token = parser.tokens.pop(<NUM_LIT:0>)<EOL>if token.contents == endtagname:<EOL><INDENT>break<EOL><DEDENT>if token.token_type == template.base.TOKEN_VAR:<EOL><INDENT>text_and_nodes.append('<STR_LIT>')<EOL>text_and_nodes.append(token.contents)<EOL><DEDENT>elif token.token_type == template.base.TOKEN_TEXT:<EOL><INDENT>text_and_nodes.append(token.contents)<EOL><DEDENT>elif token.token_type == template.base.TOKEN_BLOCK:<EOL><INDENT>try:<EOL><INDENT>command = token.contents.split()[<NUM_LIT:0>]<EOL><DEDENT>except IndexError:<EOL><INDENT>parser.empty_block_tag(token)<EOL><DEDENT>try:<EOL><INDENT>compile_func = parser.tags[command]<EOL><DEDENT>except KeyError:<EOL><INDENT>parser.invalid_block_tag(token, command, None)<EOL><DEDENT>try:<EOL><INDENT>node = compile_func(parser, token)<EOL><DEDENT>except template.TemplateSyntaxError as e:<EOL><INDENT>if not parser.compile_function_error(token, e):<EOL><INDENT>raise<EOL><DEDENT><DEDENT>text_and_nodes.append(node)<EOL><DEDENT>if token.token_type == template.base.TOKEN_VAR:<EOL><INDENT>text_and_nodes.append('<STR_LIT>')<EOL><DEDENT><DEDENT>return text_and_nodes<EOL>

Javascript templates (jquery, handlebars.js, mustache.js) use constructs like:

::

    {{if condition}} print something{{/if}}

This, of course, completely screws up Django templates,
because Django thinks {{ and }} means something.

The following code preserves {{ }} tokens.

This version of verbatim template tag allows you to use tags
like url {% url name %}. {% trans "foo" %} or {% csrf_token %} within.


if None in nsmap:<EOL><INDENT>default_url = nsmap[None]<EOL>prefix = None<EOL>for key, val in nsmap.iteritems():<EOL><INDENT>if val == default_url and key is not None:<EOL><INDENT>prefix = key<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>".format(<EOL>url=default_url<EOL>)<EOL>)<EOL><DEDENT>return prefix<EOL><DEDENT>raise ValueError("<STR_LIT>")<EOL>

XML doc may have several prefix:namespace_url pairs, can also specify
a namespace_url as default, tags in that namespace don't need a prefix
NOTE:
we rely on default namespace also present in prefixed form, I'm not sure if
this is an XML certainty or a quirk of the eBay WSDLs

in our case the WSDL contains:
    <wsdl:documentation>
        <Version>1.0.0</Version>
    </wsdl:documentation>
...but our query needs to give a prefix to the path of `Version` so we need
to determine the default namespace of the doc, find the matching prefix and
return it


vc_el = schema_el<EOL>while True:<EOL><INDENT>vc_el = vc_el.getprevious()<EOL>if vc_el is None:<EOL><INDENT>break<EOL><DEDENT>if vc_el.tag is etree.Comment:<EOL><INDENT>match = VERSION_COMMENT.search(vc_el.text)<EOL>if match:<EOL><INDENT>try:<EOL><INDENT>return match.group(<NUM_LIT:1>)<EOL><DEDENT>except IndexError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT><DEDENT>raise VersionNotFound('<STR_LIT>')<EOL>

returns: API version number <str>
raises: <VersionNotFound>

NOTE:
relies on presence of comment tags in the XSD, which are currently present
for both ebaySvc.xsd (TradingAPI) and ShoppingService.xsd (ShoppingAPI)


path = os.path.expanduser("<STR_LIT>")<EOL>if not os.path.exists(path):<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>with open(path) as f:<EOL><INDENT>token = f.read().strip()<EOL><DEDENT>headers = {<EOL>'<STR_LIT>': '<STR_LIT>'.format(token),<EOL>}<EOL>return headers<EOL>

Make the authentication headers needed to use the Appveyor API.


dirname = os.path.dirname(filename)<EOL>if dirname and not os.path.exists(dirname):<EOL><INDENT>os.makedirs(dirname)<EOL><DEDENT>

Make sure the directories exist for `filename`.


return args[<NUM_LIT:0>](*args[<NUM_LIT:1>:])<EOL>

args is a tuple where the first argument is a callable.

eg::

    apply_with_return_error((func, 1, 2, 3)) - this will call func(1, 2, 3)


def debug_storage(storage, base_info=False, chars=True, runs=False):

import codecs<EOL>import locale<EOL>import sys<EOL>if six.PY2:<EOL><INDENT>stderr = codecs.getwriter(locale.getpreferredencoding())(sys.stderr)<EOL><DEDENT>else:<EOL><INDENT>stderr = sys.stderr<EOL><DEDENT>caller = inspect.stack()[<NUM_LIT:1>][<NUM_LIT:3>]<EOL>stderr.write('<STR_LIT>' % caller)<EOL>if base_info:<EOL><INDENT>stderr.write(u'<STR_LIT>' % storage['<STR_LIT>'])<EOL>stderr.write(u'<STR_LIT>' % storage['<STR_LIT>'])<EOL><DEDENT>if runs:<EOL><INDENT>stderr.write(u'<STR_LIT>' % list(storage['<STR_LIT>']))<EOL><DEDENT>if chars:<EOL><INDENT>output = u'<STR_LIT>'<EOL>for _ch in storage['<STR_LIT>']:<EOL><INDENT>if _ch != '<STR_LIT:\n>':<EOL><INDENT>output += _ch['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>output += '<STR_LIT:C>'<EOL><DEDENT><DEDENT>stderr.write(output + u'<STR_LIT:\n>')<EOL>output = u'<STR_LIT>' % u'<STR_LIT>'.join(<EOL>[six.text_type(_ch['<STR_LIT>']) for _ch in storage['<STR_LIT>']])<EOL>stderr.write(output)<EOL>_types = [_ch['<STR_LIT:type>'].ljust(<NUM_LIT:3>) for _ch in storage['<STR_LIT>']]<EOL>for i in range(<NUM_LIT:3>):<EOL><INDENT>if i:<EOL><INDENT>output = u'<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>output = u'<STR_LIT>'<EOL><DEDENT>stderr.write(output % u'<STR_LIT>'.join([_t[i] for _t in _types]))<EOL><DEDENT><DEDENT>

Display debug information for the storage


return {<EOL>'<STR_LIT>': None,<EOL>'<STR_LIT>': None,<EOL>'<STR_LIT>': [],<EOL>'<STR_LIT>': deque(),<EOL>}<EOL>

Return an empty storage skeleton, usable for testing


<EOL>for _ch in storage['<STR_LIT>']:<EOL><INDENT>unichar = _ch['<STR_LIT>']<EOL>if mirrored(unichar) and_embedding_direction(_ch['<STR_LIT>']) == '<STR_LIT:R>':<EOL><INDENT>_ch['<STR_LIT>'] = MIRRORED.get(unichar, unichar)<EOL><DEDENT><DEDENT>if debug:<EOL><INDENT>debug_storage(storage)<EOL><DEDENT>

Applies L4: mirroring

    See: http://unicode.org/reports/tr9/#L4


for run in storage['<STR_LIT>']:<EOL><INDENT>start, length = run['<STR_LIT:start>'], run['<STR_LIT>']<EOL>chars = [{'<STR_LIT:type>': run['<STR_LIT>']}] + storage['<STR_LIT>'][start:start+length] +[{'<STR_LIT:type>': run['<STR_LIT>']}]<EOL>total_chars = len(chars)<EOL>seq_start = None<EOL>for idx in range(total_chars):<EOL><INDENT>_ch = chars[idx]<EOL>if _ch['<STR_LIT:type>'] in ('<STR_LIT:B>', '<STR_LIT:S>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if seq_start is None:<EOL><INDENT>seq_start = idx<EOL>prev_bidi_type = chars[idx-<NUM_LIT:1>]['<STR_LIT:type>']<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if seq_start is not None:<EOL><INDENT>next_bidi_type = chars[idx]['<STR_LIT:type>']<EOL>if prev_bidi_type in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>prev_bidi_type = '<STR_LIT:R>'<EOL><DEDENT>if next_bidi_type in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>next_bidi_type = '<STR_LIT:R>'<EOL><DEDENT>for seq_idx in range(seq_start, idx):<EOL><INDENT>if prev_bidi_type == next_bidi_type:<EOL><INDENT>chars[seq_idx]['<STR_LIT:type>'] = prev_bidi_type<EOL><DEDENT>else:<EOL><INDENT>chars[seq_idx]['<STR_LIT:type>'] =_embedding_direction(chars[seq_idx]['<STR_LIT>'])<EOL><DEDENT><DEDENT>seq_start = None<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if debug:<EOL><INDENT>debug_storage(storage)<EOL><DEDENT>

Resolving neutral types. Implements N1 and N2

    See: http://unicode.org/reports/tr9/#Resolving_Neutral_Types


def _encode_fields(self, xfield, yfield, time_unit=None,<EOL>scale=Scale(zero=False)):

if scale is None:<EOL><INDENT>scale = Scale()<EOL><DEDENT>xfieldtype = xfield[<NUM_LIT:1>]<EOL>yfieldtype = yfield[<NUM_LIT:1>]<EOL>x_options = None<EOL>if len(xfield) > <NUM_LIT:2>:<EOL><INDENT>x_options = xfield[<NUM_LIT:2>]<EOL><DEDENT>y_options = None<EOL>if len(yfield) > <NUM_LIT:2>:<EOL><INDENT>y_options = yfield[<NUM_LIT:2>]<EOL><DEDENT>if time_unit is not None:<EOL><INDENT>if x_options is None:<EOL><INDENT>xencode = X(xfieldtype, timeUnit=time_unit)<EOL><DEDENT>else:<EOL><INDENT>xencode = X(<EOL>xfieldtype,<EOL>axis=Axis(**x_options),<EOL>timeUnit=time_unit,<EOL>scale=scale<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if x_options is None:<EOL><INDENT>xencode = X(xfieldtype)<EOL><DEDENT>else:<EOL><INDENT>xencode = X(<EOL>xfieldtype,<EOL>axis=Axis(**x_options),<EOL>scale=scale<EOL>)<EOL><DEDENT><DEDENT>if y_options is None:<EOL><INDENT>yencode = Y(yfieldtype, scale=scale)<EOL><DEDENT>else:<EOL><INDENT>yencode = Y(<EOL>yfieldtype,<EOL>axis=Axis(**y_options),<EOL>scale=scale<EOL>)<EOL><DEDENT>return xencode, yencode<EOL>


def gen(self, slug, name, dataobj, xfield, yfield, time_unit=None,<EOL>chart_type="<STR_LIT>", width=<NUM_LIT>,<EOL>height=<NUM_LIT>, color=Color(), size=Size(),<EOL>scale=Scale(zero=False), shape=Shape(), filepath=None,<EOL>html_before="<STR_LIT>", html_after="<STR_LIT>"):

chart_obj = self.serialize(dataobj, xfield, yfield, time_unit,<EOL>chart_type, width, height, color, size, scale, shape)<EOL>html = self.html(slug, name, chart_obj, filepath,<EOL>html_before, html_after)<EOL>return html<EOL>

Generates an html chart from either a pandas dataframe, a dictionnary,
a list or an Altair Data object and optionally write it to a file


if os.environ['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>return<EOL><DEDENT>from flask_security import SQLAlchemyUserDatastore, Security<EOL>account_module_name, account_class_name = os.environ[<EOL>'<STR_LIT>'].rsplit('<STR_LIT:.>', <NUM_LIT:1>)<EOL>account_module = importlib.import_module(account_module_name)<EOL>account_class = getattr(account_module, account_class_name)<EOL>role_module_name, role_class_name = os.environ[<EOL>'<STR_LIT>'].rsplit('<STR_LIT:.>', <NUM_LIT:1>)<EOL>role_module = importlib.import_module(role_module_name)<EOL>role_class = getattr(role_module, role_class_name)<EOL>r = True if os.environ[<EOL>'<STR_LIT>'] != '<STR_LIT>' else False<EOL>Security(app,<EOL>SQLAlchemyUserDatastore(<EOL>app.db, account_class, role_class),<EOL>register_blueprint=r)<EOL>pass<EOL>

尝试使用内置方式构建账户


from celery import Task<EOL>tasks_txt = os.path.join(os.path.dirname(entry_file), '<STR_LIT>',<EOL>'<STR_LIT>')<EOL>if not os.path.exists(tasks_txt):<EOL><INDENT>import sys<EOL>print('<STR_LIT>' % tasks_txt)<EOL>sys.exit(-<NUM_LIT:1>)<EOL><DEDENT>class ContextTask(Task):<EOL><INDENT>abstract = True<EOL>def __call__(self, *args, **kwargs):<EOL><INDENT>with app.app_context():<EOL><INDENT>return super().__call__(*args, **kwargs)<EOL><DEDENT><DEDENT><DEDENT>app.celery.config_from_object(app.config, namespace='<STR_LIT>')<EOL>app.celery.Task = ContextTask<EOL>with app.app_context():<EOL><INDENT>with open(tasks_txt, '<STR_LIT:r>') as f:<EOL><INDENT>for line in f:<EOL><INDENT>mod = line.strip('<STR_LIT:\n>')<EOL>if mod:<EOL><INDENT>importlib.import_module(mod + '<STR_LIT>')<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL>

装载任务，解决celery无法自动装载的问题


def write_file(fobj, opts=None, data=None, eopts=None):

lines = []<EOL>lines.append("<STR_LIT>")<EOL>if opts:<EOL><INDENT>lines.append("<STR_LIT>" + "<STR_LIT:U+0020>".join(opts))<EOL><DEDENT>if eopts:<EOL><INDENT>lines.append("<STR_LIT>" + eopts)<EOL><DEDENT>if not data:<EOL><INDENT>data = [[<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:1>]]<EOL><DEDENT>for row in data:<EOL><INDENT>lines.append("<STR_LIT:U+0020>".join([str(item) for item in row]))<EOL><DEDENT>lines = [item + "<STR_LIT:\n>" for item in lines]<EOL>fobj.writelines(lines)<EOL>


with open(<EOL>os.path.join(os.environ["<STR_LIT>"], "<STR_LIT>"), "<STR_LIT:a>" if append else "<STR_LIT:w>"<EOL>) as fobj:<EOL><INDENT>fobj.write("<STR_LIT>".format(line))<EOL><DEDENT>


mant, exp = peng.functions._to_eng_tuple(number)<EOL>return "<STR_LIT>".format(<EOL>mant=mant, exp_sign="<STR_LIT:->" if exp < <NUM_LIT:0> else "<STR_LIT:+>", exp=abs(exp)<EOL>)<EOL>

Return string with the number formatted in scientific notation.

This function does not have all the configurability of the public function
to_scientific_string, it is a convenience function to test _to_eng_tuple


wobj, fsample, finc = fft_wave()<EOL>npoints = len(wobj.indep_vector)<EOL>ret_indep_vector = barange(-fsample / <NUM_LIT>, +fsample / <NUM_LIT>, finc)<EOL>ret_dep_vector = fft(wobj.dep_vector, npoints)<EOL>return npoints, wobj, ret_indep_vector, ret_dep_vector<EOL>

FFT of waveform where independent axis is evenly spaced and a power of 2.


<EOL>indep_vector = np.array([<NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:3>]) if indep_vector is None else indep_vector<EOL>dep_vector = np.array([<NUM_LIT:6>, <NUM_LIT:5>, <NUM_LIT:4>]) if dep_vector is None else dep_vector<EOL>return peng.Waveform(<EOL>indep_vector=indep_vector,<EOL>dep_vector=dep_vector,<EOL>dep_name=dep_name,<EOL>indep_scale=indep_scale,<EOL>dep_scale="<STR_LIT>",<EOL>indep_units="<STR_LIT>",<EOL>dep_units=dep_units,<EOL>interp=interp,<EOL>)<EOL>

Return a waveform with fixed parameters and given name.


def _chunk_pars(freq_vector, data_matrix, pformat):

pformat = pformat.upper()<EOL>length = <NUM_LIT:4><EOL>for freq, data in zip(freq_vector, data_matrix):<EOL><INDENT>data = data.flatten()<EOL>for index in range(<NUM_LIT:0>, data.size, length):<EOL><INDENT>fpoint = [freq] if not index else [None]<EOL>cdata = data[index : index + length]<EOL>if pformat == "<STR_LIT>":<EOL><INDENT>vector1 = np.abs(cdata)<EOL>vector2 = np.rad2deg(np.angle(cdata))<EOL><DEDENT>elif pformat == "<STR_LIT>":<EOL><INDENT>vector1 = np.real(cdata)<EOL>vector2 = np.imag(cdata)<EOL><DEDENT>else:  <EOL><INDENT>vector1 = <NUM_LIT> * np.log10(np.abs(cdata))<EOL>vector2 = np.rad2deg(np.angle(cdata))<EOL><DEDENT>sep_data = np.array([])<EOL>for item1, item2 in zip(vector1, vector2):<EOL><INDENT>sep_data = np.concatenate((sep_data, np.array([item1, item2])))<EOL><DEDENT>ret = np.concatenate((np.array(fpoint), sep_data))<EOL>yield ret<EOL><DEDENT><DEDENT>

Chunk input data into valid Touchstone file rows.


if isinstance(obj, dict) and (not obj):<EOL><INDENT>return None<EOL><DEDENT>if (not isinstance(obj, dict)) or (<EOL>isinstance(obj, dict)<EOL>and (sorted(obj.keys()) != sorted(["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]))<EOL>):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if not (isinstance(obj["<STR_LIT>"], int) and (obj["<STR_LIT>"] > <NUM_LIT:0>)):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if _check_increasing_real_numpy_vector(obj["<STR_LIT>"]):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if _check_real_numpy_vector(obj["<STR_LIT>"]):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if _check_number_numpy_vector(obj["<STR_LIT>"]):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if not (<EOL>isinstance(obj["<STR_LIT>"], np.ndarray)<EOL>and (len(obj["<STR_LIT>"].shape) == <NUM_LIT:1>)<EOL>and (obj["<STR_LIT>"].shape[<NUM_LIT:0>] > <NUM_LIT:0>)<EOL>and np.all(obj["<STR_LIT>"] >= <NUM_LIT:0>)<EOL>):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>sizes = [obj["<STR_LIT>"].size, obj["<STR_LIT>"].size, obj["<STR_LIT>"].size, obj["<STR_LIT>"].size]<EOL>if set(sizes) != set([obj["<STR_LIT>"]]):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>return None<EOL>

r"""
    Validate if an object is an :ref:`TouchstoneNoiseData` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


try:<EOL><INDENT>obj = obj.rstrip()<EOL>float(obj[:-<NUM_LIT:1>] if obj[-<NUM_LIT:1>] in _SUFFIX_TUPLE else obj)<EOL>return None<EOL><DEDENT>except (AttributeError, IndexError, ValueError):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>

r"""
    Validate if an object is an :ref:`EngineeringNotationNumber` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


if (not isinstance(obj, dict)) or (<EOL>isinstance(obj, dict)<EOL>and (sorted(obj.keys()) != sorted(["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]))<EOL>):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if not (<EOL>(obj["<STR_LIT>"].lower() in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"])<EOL>and (obj["<STR_LIT>"].lower() in ["<STR_LIT:s>", "<STR_LIT:y>", "<STR_LIT:z>", "<STR_LIT:h>", "<STR_LIT:g>"])<EOL>and (obj["<STR_LIT>"].lower() in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"])<EOL>and isinstance(obj["<STR_LIT>"], float)<EOL>and (obj["<STR_LIT>"] >= <NUM_LIT:0>)<EOL>):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>

r"""
    Validate if an object is an :ref:`TouchstoneOptions` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None