<commit_before>#! /usr/bin/env python
"""
usage:
  vk phylo fasta <vcf>
  vk phylo tree (nj|upgma) [--plot] <vcf>

options:
  -h --help                   Show this screen.
  --version                   Show version.

"""
from docopt import docopt
import vk
from vcfkit import __version__
from utils.vcf import *
from subprocess import Popen, PIPE
from utils import check_program_exists
from clint.textui import colored, indent, puts_err
import os


def main(debug=None):
    args = docopt(__doc__,
                  argv=debug,
                  options_first=False,
                  version=__version__)
    module_path = os.path.split(os.path.realpath(__file__))[0]
    v = vcf(args["<vcf>"])
    samples = v.samples
    _ROOT = os.path.split(os.path.dirname(vk.__file__))[0]
    if args["fasta"] or args["tree"]:
        """
            Generate an aligned fasta from a VCF file.
        """
        seqs = {}
        for sample in samples:
            seqs[sample] = []
        for line in v:
            if line.is_snp:
                non_missing = [x.replace(".", "-") for x in line.gt_bases]
                sample_gt = zip(samples, [x[-1] for x in non_missing])
            for sample, gt in sample_gt:
                seqs[sample].append(gt)
        if not args["tree"]:
            for sample, seq in seqs.items():
                print(">" + sample)
                print(''.join(seq))
        elif args["tree"]:
            """
            Generate a phylogenetic tree using an aligned fasta with muscle.
            """

            # Check for muscle dependency
            check_program_exists("muscle")
            fasta = ""
            with indent(4):
                puts_err(colored.blue("\nGenerating Fasta\n"))
            for sample, seq in seqs.items():
                fasta += ">" + sample + "\n" + ''.join(seq) + "\n"
            tree_type = "upgma"  # default is upgma
            if args["nj"]:<commit_msg>Add ability to filter on region<commit_after>#! /usr/bin/env python
"""
usage:
  vk phylo fasta <vcf> [<region>]
  vk phylo tree (nj|upgma) [--plot] <vcf> [<region>]

options:
  -h --help                   Show this screen.
  --version                   Show version.

"""
from docopt import docopt
import vk
from vcfkit import __version__
from utils.vcf import *
from subprocess import Popen, PIPE
from utils import check_program_exists
from clint.textui import colored, indent, puts_err
import os


def main(debug=None):
    args = docopt(__doc__,
                  argv=debug,
                  options_first=False,
                  version=__version__)
    module_path = os.path.split(os.path.realpath(__file__))[0]
    v = vcf(args["<vcf>"])
    if args["<region>"]:
        variant_set = v(args["<region>"])
    else:
        variant_set = v
    samples = v.samples
    _ROOT = os.path.split(os.path.dirname(vk.__file__))[0]
    if args["fasta"] or args["tree"]:
        """
            Generate an aligned fasta from a VCF file.
        """
        seqs = {}
        for sample in samples:
            seqs[sample] = []
        for line in variant_set:
            if line.is_snp:
                non_missing = [x.replace(".", "-") for x in line.gt_bases]
                sample_gt = zip(samples, [x[-1] for x in non_missing])
            for sample, gt in sample_gt:
                seqs[sample].append(gt)
        if not args["tree"]:
            for sample, seq in seqs.items():
                print(">" + sample)
                print(''.join(seq))
        elif args["tree"]:
            """
            Generate a phylogenetic tree using an aligned fasta with muscle.
            """

            # Check for muscle dependency
            check_program_exists("muscle")
            fasta = ""
            with indent(4):
                puts_err(colored.blue("\nGenerating Fasta\n"))
            for sample, seq in seqs.items():
                fasta += ">" + sample + "\n" + ''.join(seq) + "\n"
            tree_type = "upgma"  # default is upgma
            if args["nj"]:
{'fraction_non_alphanumeric': 0.12273291925465839, 'fraction_numerical': 0.001987577639751553, 'mean_word_length': 1.7594242631939685, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5168194', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1199, 'n_words': 335}