<commit_before>
#############################
## Import required modules ##
#############################
""" 
- argparse, collections, csv, and sys are part of the standard Python library
- numpy, sympy, and cyvcf are easily installed via conda and pip
"""

import argparse
import collections
import csv
import sys
import numpy as np
import sympy
import cyvcf


########################################
## Import files from the command line ##
########################################
parser = argparse.ArgumentParser(description="This program calculates nucleotide"\
								" diversity separately for autosomes and sex-linked"\
								" chromosomes.  It requires, as input, a minimum of:"\
								" a VCF of polymorphic sites, a list of sex-linked contigs, and"\
								" bed files containing callable regions for each population.  It is assumed"\
								" that all filtering (both VCF and bed file) has been done elsewhere.")

#Print help/usage if no arguments are supplied
if len(sys.argv)==1:
	parser.print_usage()
	sys.exit(1)
	
# A function to check if bootstrap input is non-negative 
def check_negative(boot_int):
    value = int(boot_int)
    if value < 0:
         raise argparse.ArgumentTypeError("%s is an invalid value.  Input for --bootstrap must be nonnegative integer" % boot_int)
    return value
	
# Parse the command line
parser.add_argument("--vcf", required=True, 
					help="REQUIRED. Input VCF file.  Can be gzipped.")
parser.add_argument("--callable_regions", nargs="*", required=True, 
					help="REQUIRED. Bed files (no header) containing callable regions for each population (to accurately calculate pi). Order of files must correspond exactly to the order of the population lists")
parser.add_argument("--bootstrap", default=0, type=check_negative, 
					help="Default is 0. If n > 0, returns 95% confidence interval of distribution of n replicates with replacement")
parser.add_argument("--male_list", nargs="*", default=None, 
					help="Default is None (i.e., all females).  Provide file listing males. List males using exact names (capitalization, etc.) as found in the vcf file.  Allows script to properly handle X chromosomes")
parser.add_argument("--population_lists", nargs="*", default=None,
					help="Default is None. If None, script will treat all individuals as coming from the same population.  Else, will read files and treat all individuals in each file as coming from the same population.")
parser.add_argument("--autosomal_scaffolds", default=None,
					help="Default is None. Provide a file listing autosomal scaffolds (either in a single column, or horizontally in a single row separated by tabs).")
parser.add_argument("--x_linked_scaffolds", default=None,
					help="Default is None. Provide a file listing x-linked scaffolds (either in a single column, or horizontally in a single row separated by tabs).")
parser.add_argument("--scaffold_sites_filter", type=int, default=0,
					help="Default is 0.  Minimum number of callable sites for a scaffold/chromosome to be included in analyses.  Scaffold is removed if this minimum is not met in any individual.")
parser.add_argument("--min_cov", type=int, default=0,
					help="Default is 0.  Minimum read depth for a sample at a site for that genotype to be included.")
parser.add_argument("--QD", type=float, default=0,
					help="Default is 0. Minimum quality by depth (QD) value.")<commit_msg>added outfile flag to Anole_diversity script<commit_after>
#############################
## Import required modules ##
#############################
""" 
- argparse, collections, csv, and sys are part of the standard Python library
- numpy, sympy, and cyvcf are easily installed via conda and pip
"""

import argparse
import collections
import csv
import sys
import numpy as np
import sympy
import cyvcf


########################################
## Import files from the command line ##
########################################
parser = argparse.ArgumentParser(description="This program calculates nucleotide"\
								" diversity separately for autosomes and sex-linked"\
								" chromosomes.  It requires, as input, a minimum of:"\
								" a VCF of polymorphic sites, a list of sex-linked contigs, and"\
								" bed files containing callable regions for each population.  It is assumed"\
								" that all filtering (both VCF and bed file) has been done elsewhere.")

#Print help/usage if no arguments are supplied
if len(sys.argv)==1:
	parser.print_usage()
	sys.exit(1)
	
# A function to check if bootstrap input is non-negative 
def check_negative(boot_int):
    value = int(boot_int)
    if value < 0:
         raise argparse.ArgumentTypeError("%s is an invalid value.  Input for --bootstrap must be nonnegative integer" % boot_int)
    return value
	
# Parse the command line
parser.add_argument("--vcf", required=True, 
					help="REQUIRED. Input VCF file.  Can be gzipped.")
parser.add_argument("--outfile", required=True, 
					help="REQUIRED. Name of output file.  Will overwrite if exists.")
parser.add_argument("--callable_regions", nargs="*", required=True, 
					help="REQUIRED. Bed files (no header) containing callable regions for each population (to accurately calculate pi). Order of files must correspond exactly to the order of the population lists")
parser.add_argument("--bootstrap", default=0, type=check_negative, 
					help="Default is 0. If n > 0, returns 95% confidence interval of distribution of n replicates with replacement")
parser.add_argument("--male_list", nargs="*", default=None, 
					help="Default is None (i.e., all females).  Provide file listing males. List males using exact names (capitalization, etc.) as found in the vcf file.  Allows script to properly handle X chromosomes")
parser.add_argument("--population_lists", nargs="*", default=None,
					help="Default is None. If None, script will treat all individuals as coming from the same population.  Else, will read files and treat all individuals in each file as coming from the same population.")
parser.add_argument("--autosomal_scaffolds", default=None,
					help="Default is None. Provide a file listing autosomal scaffolds (either in a single column, or horizontally in a single row separated by tabs).")
parser.add_argument("--x_linked_scaffolds", default=None,
					help="Default is None. Provide a file listing x-linked scaffolds (either in a single column, or horizontally in a single row separated by tabs).")
parser.add_argument("--scaffold_sites_filter", type=int, default=0,
					help="Default is 0.  Minimum number of callable sites for a scaffold/chromosome to be included in analyses.  Scaffold is removed if this minimum is not met in any individual.")
parser.add_argument("--min_cov", type=int, default=0,
					help="Default is 0.  Minimum read depth for a sample at a site for that genotype to be included.")
parser.add_argument("--QD", type=float, default=0,
					help="Default is 0. Minimum quality by depth (QD) value.")
{'fraction_non_alphanumeric': 0.12753706635957968, 'fraction_numerical': 0.004030516769828703, 'mean_word_length': 4.369397217928903, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4421670', 'n_tokens_mistral': 2077, 'n_tokens_neox': 1795, 'n_words': 799}