import os
import pandas as pd
import datetime
from timeit import default_timer as timer
import argparse

#Start timer
start = timer()
time = datetime.datetime.now().strftime("%Y-%m-%d: %H:%M")
print "Start running script at: {0}".format(time)

###Parse arguments
parser = argparse.ArgumentParser(description = "This script extracts the loci that were 'Callable' in all members in a parent-offspring trio These loci are extracted from bed files generated by GATKs CallableLoci.")
parser.add_argument("-f", "--FILELIST", default = "/hpc/cog_bioinf/cuppen/project_data/Freek_SNV/FilelistFreek.txt", help = "The file list")
parser.add_argument("-o", "--OUTPUT_PATH", default = "/hpc/cog_bioinf/cuppen/project_data/Freek_SNV", help = "The output path")
parser.add_argument("-w", "--OVERWRITE", default = "False", help = "Overwrite the results if they already exist.")
parser.add_argument("--SNPSIFT", default = "/hpc/local/CentOS7/cog_bioinf/snpEff_v4.1h/SnpSift.jar", help = "The location of the snpsift jar.")
args = parser.parse_args()

filelist = args.FILELIST
outdir = "{0}/Callableregion_NrMendelViols".format(args.OUTPUT_PATH)
snpsift = args.SNPSIFT

#Create the file paths.
folder = "{0}/Callableregion_NrMendelViols/TrueDenovo/SNVs".format(args.OUTPUT_PATH)
manualcheck = "{0}/Manualcheck".format(folder)
filteredonfreq = "{0}/Possibly_pathogenic/SNVs/Filteredonfreq".format(args.OUTPUT_PATH)

dffiles = pd.read_csv(filelist, sep = "\t", header = 0)
childrowsf = dffiles["Name"].str.contains("Child|child")
dffiles = dffiles[childrowsf]
dffiles["vcf"] = folder + "/" + dffiles["Sample"] + "_Truedenovo.vcf"
dffiles["vcf_f"] = filteredonfreq + "/" + dffiles["Sample"] + "_freqfilter.vcf"


#Filter the vcfs on gnomAD and GoNLv5 databases
for index, row in dffiles.iterrows():
	sample, vcf, vcf_f = row[["Sample", "vcf", "vcf_f"]].values.tolist()
	if os.path.isfile(vcf) and (not os.path.isfile(vcf_f) or args.OVERWRITE == "true"):
		command = """java -Xmx4G -jar {0} filter "!( gnomAD_AC > 1 ) & !( GoNLv5_AC > 1 ) & !( PON_COUNT > 1 )" {1} > {2}""".format(snpsift, vcf, vcf_f)
		os.system(command)
		print "Filtered out muts with a gnomAD or GoNLv5 allele count of more than 1 in sample: {0}".format(sample)
		
		
#End timer		
timeend = datetime.datetime.now().strftime("%Y-%m-%d: %H:%M")
print "Finished running script at: {0}".format(timeend)
end = timer()
execution_time = int(end - start)
execution_time = datetime.timedelta(seconds = execution_time)
print "Elapsed time: {0}".format(execution_time)


30a89a4beddbc5f0afc7fc214be9469f1e324340
import os
import pandas as pd
import datetime
from timeit import default_timer as timer
import argparse

#Start timer
start = timer()
time = datetime.datetime.now().strftime("%Y-%m-%d: %H:%M")
print "Start running script at: {0}".format(time)

###Parse arguments
parser = argparse.ArgumentParser(description = "This script extracts the loci that were 'Callable' in all members in a parent-offspring trio These loci are extracted from bed files generated by GATKs CallableLoci.")
parser.add_argument("-f", "--FILELIST", default = "/hpc/cog_bioinf/cuppen/project_data/Freek_SNV/FilelistFreek.txt", help = "The file list")
parser.add_argument("-o", "--OUTPUT_PATH", default = "/hpc/cog_bioinf/cuppen/project_data/Freek_SNV", help = "The output path")
parser.add_argument("-w", "--OVERWRITE", default = "False", help = "Overwrite the results if they already exist.")
parser.add_argument("--SNPSIFT", default = "/hpc/local/CentOS7/cog_bioinf/snpEff_v4.1h/SnpSift.jar", help = "The location of the snpsift jar.")
args = parser.parse_args()

filelist = args.FILELIST
outdir = "{0}/Callableregion_NrMendelViols".format(args.OUTPUT_PATH)
snpsift = args.SNPSIFT

#Create the file paths.
folder = "{0}/Callableregion_NrMendelViols/TrueDenovo/SNVs".format(args.OUTPUT_PATH)
manualcheck = "{0}/Manualcheck".format(folder)
filteredonfreq = "{0}/Possibly_pathogenic/SNVs/Filteredonfreq".format(args.OUTPUT_PATH)

dffiles = pd.read_csv(filelist, sep = "\t", header = 0)
childrowsf = dffiles["Name"].str.contains("Child|child")
dffiles = dffiles[childrowsf]
dffiles["vcf"] = folder + "/" + dffiles["Sample"] + "_Truedenovo.vcf"
dffiles["vcf_f"] = filteredonfreq + "/" + dffiles["Sample"] + "_freqfilter.vcf"


#Filter the vcfs on gnomAD and GoNLv5 databases
for index, row in dffiles.iterrows():
	sample, vcf, vcf_f = row[["Sample", "vcf", "vcf_f"]].values.tolist()
	if os.path.isfile(vcf) and (not os.path.isfile(vcf_f) or args.OVERWRITE == "true"):
		command = """java -Xmx4G -jar {0} filter "!( gnomAD_AC > 1 ) & !( GoNLv5_AC > 1 ) & !( PON_COUNT > 1 )" {1} > {2}""".format(snpsift, vcf, vcf_f)
		os.system(command)
		print "Filtered out muts with a gnomAD or GoNLv5 allele count of more than 1 in sample: {0}".format(sample)
		
		
#End timer		
timeend = datetime.datetime.now().strftime("%Y-%m-%d: %H:%M")
print "Finished running script at: {0}".format(timeend)
end = timer()
execution_time = int(end - start)
execution_time = datetime.timedelta(seconds = execution_time)
print "Elapsed time: {0}".format(execution_time)

