<commit_before>import sys
import re
from string import maketrans

from .. utils import common as uc


def print_line(sample, region, location, type_var, removed,
               added, abnormal, normal, ratio, min_cov, min_exclu,
               variant, target, info, var_seq, ref_seq):
    line = "\t".join([sample, region, location, type_var, removed,
                      added, abnormal, normal, ratio, min_cov, min_exclu,
                      variant, target, info, var_seq, ref_seq])
    sys.stdout.write(line + "\n")


def print_vcf_header():
    header  = '##fileformat=VCFv4.1\n'
    header += '##INFO=<ID=TYPE,Number=A,Type=String,Description='
    header += '"The type of variant, either Insertion, ITD, I&I, Deletion, Substitution or Indel.">\n'
    header += '##INFO=<ID=TARGET,Number=A,Type=String,Description='
    header += '"Name of the sequencing that contains the mutation.">\n'
    header += '##INFO=<ID=RATIO,Number=A,Type=String,Description="Ratio of mutation to reference.">\n'
    header += '##INFO=<ID=MINCOV,Number=A,Type=String,Description='
    header += '"Minimum k-mer coverage of alternative allele.">\n'
    header += '##INFO=<ID=REMOVED,Number=A,Type=String,Description="Number of removed bases.">\n'
    header += '##INFO=<ID=ADDED,Number=A,Type=String,Description="Number of added bases.">\n'
    header += '#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n'
    sys.stdout.write(header)


def print_vcf_line(chro, loc, ref_var, alt_var, type_var, target, ratio, min_cov, rem, ad):
    line = "\t".join([chro, str(loc), ".", ref_var, alt_var, ".", ".",
                      "TYPE="+type_var+";TARGET="+target+";RATIO="+ratio+";MINCOV="+min_cov +
                      ";REMOVED="+str(rem)+";ADDED="+str(ad)])
    sys.stdout.write(line + "\n")


def init_ref_seq(arg_ref):
    if not arg_ref:
        sys.exit("ERROR: Target file is empty\n")

    # BE 1-based
    nts = []
    chro = None
    strand = None
    
    # CODE for multiple >LOC lines:
    for line in open(arg_ref, "r"):
        line = line.strip()
        nt = []
        # Parse attributes
        if line[0] == '>':
            # sanity check
            loc = line.split(" ")[0]
            if "chr" not in loc or ":" not in loc or "-" not in loc:
                sys.exit('ERROR: Fasta entries do not contain a correctly ' +
                         'formatted location: {}\n'.format(loc))
            <commit_msg>Allow absence of 'chr' in chromosome names<commit_after>import sys
import re
from string import maketrans

from .. utils import common as uc


def print_line(sample, region, location, type_var, removed,
               added, abnormal, normal, ratio, min_cov, min_exclu,
               variant, target, info, var_seq, ref_seq):
    line = "\t".join([sample, region, location, type_var, removed,
                      added, abnormal, normal, ratio, min_cov, min_exclu,
                      variant, target, info, var_seq, ref_seq])
    sys.stdout.write(line + "\n")


def print_vcf_header():
    header  = '##fileformat=VCFv4.1\n'
    header += '##INFO=<ID=TYPE,Number=A,Type=String,Description='
    header += '"The type of variant, either Insertion, ITD, I&I, Deletion, Substitution or Indel.">\n'
    header += '##INFO=<ID=TARGET,Number=A,Type=String,Description='
    header += '"Name of the sequencing that contains the mutation.">\n'
    header += '##INFO=<ID=RATIO,Number=A,Type=String,Description="Ratio of mutation to reference.">\n'
    header += '##INFO=<ID=MINCOV,Number=A,Type=String,Description='
    header += '"Minimum k-mer coverage of alternative allele.">\n'
    header += '##INFO=<ID=REMOVED,Number=A,Type=String,Description="Number of removed bases.">\n'
    header += '##INFO=<ID=ADDED,Number=A,Type=String,Description="Number of added bases.">\n'
    header += '#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n'
    sys.stdout.write(header)


def print_vcf_line(chro, loc, ref_var, alt_var, type_var, target, ratio, min_cov, rem, ad):
    line = "\t".join([chro, str(loc), ".", ref_var, alt_var, ".", ".",
                      "TYPE="+type_var+";TARGET="+target+";RATIO="+ratio+";MINCOV="+min_cov +
                      ";REMOVED="+str(rem)+";ADDED="+str(ad)])
    sys.stdout.write(line + "\n")


def init_ref_seq(arg_ref):
    if not arg_ref:
        sys.exit("ERROR: Target file is empty\n")

    # BE 1-based
    nts = []
    chro = None
    strand = None
    
    # CODE for multiple >LOC lines:
    for line in open(arg_ref, "r"):
        line = line.strip()
        nt = []
        # Parse attributes
        if line[0] == '>':
            # sanity check
            loc = line.split(" ")[0]
            if ":" not in loc or "-" not in loc:
                sys.exit('ERROR: Fasta entries do not contain a correctly ' +
                         'formatted location: {}\n'.format(loc))
            
{'fraction_non_alphanumeric': 0.1585793929382614, 'fraction_numerical': 0.0020648358455502788, 'mean_word_length': 2.8201892744479493, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 19, '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': '735694', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1575, 'n_words': 383}