gc.filePrep(divfilename, main_header) gc.filePrep(uniqfilename, uniq_header) logfilename = os.path.join(outdir, "gwct.log") gc.filePrep(logfilename, "") sp = 65 gc.printWrite( logfilename, "# =======================================================================" ) gc.printWrite(logfilename, "#\t\tGWCT: Genome-Wide Convergence Tester") gc.printWrite(logfilename, "#\t\t\t" + gc.getDateTime()) gc.printWrite( logfilename, gc.spacedOut("# INPUT | Using ancestral reconstructions in:", sp) + indir) if orig_targets != "": orig_targets = [t.split(",") for t in orig_targets.split(" ")] gc.printWrite( logfilename, gc.spacedOut("# INFO | Target species:", sp) + str(orig_targets)) elif pairwise == 1: pw_dir = outdir + "pairwise-tips/" pw_dir = os.path.join(outdir, "pairwise-tips") gc.printWrite( logfilename, "# INFO | Performing pairwise comparisons of TIP branches") elif pairwise == 2: pw_dir = os.path.join(outdir, "pairwise-all") gc.printWrite( logfilename,
print "# " + gwctcore.getTime() + " | Creating main output directory:\t" + script_outdir; os.system("mkdir " + script_outdir); logfilename = os.path.join(script_outdir, "gwct.log"); logfile = open(logfilename, "w"); logfile.write(""); logfile.close(); uniq_header = "#\tChromosome\tGeneID\tAlignLen\tPosition\tBackgroundAlleles\tTargetAlleles\n"; l = 1; sp = 65; gwctcore.logCheck(l, logfilename, "# ======================================================================="); gwctcore.logCheck(l, logfilename, "#\tGWCT: Genome-Wide Convergence Tester -- Unique substitutions"); gwctcore.logCheck(l, logfilename, "#\t\t\t" + gwctcore.getDateTime()); gwctcore.logCheck(l, logfilename, gwctcore.spacedOut("# INPUT | Using sequences in:", sp) + indir); gwctcore.logCheck(l, logfilename, gwctcore.spacedOut("# INPUT | Target species:", sp) + ",".join(targets)); gwctcore.logCheck(l, logfilename, gwctcore.spacedOut("# OUTPUT | Output directory created within input directory:", sp) + script_outdir); gwctcore.logCheck(l, logfilename, "# ---------------------------------------------"); gwctcore.logCheck(2, logfilename, uniq_header); ################################ print "# " + gwctcore.getTime() + " | Counting unique substitutions...."; filelist = os.listdir(indir); numfiles = len(filelist); numbars = 0; donepercent = []; i = 0; numsubs = 0; numgenes = 0;
print gwctcore.getTime() + " | Creating main output directory:\t" + script_outdir; os.system("mkdir " + script_outdir); logfilename = os.path.join(script_outdir, "gwct.log"); logfile = open(logfilename, "w"); logfile.write(""); logfile.close(); main_header = "# Chromosome\tGeneID\tAlignLen\tPosition\tAncAlleles\tTargetAlleles\n"; uniq_header = "# Chromosome\tGeneID\tAlignLen\tPosition\tBackgroundAlleles\tTargetAlleles\n"; l = 1; sp = 65; gwctcore.logCheck(l, logfilename, "# ======================================================================="); gwctcore.logCheck(l, logfilename, "#\t\tGWCT: Genome-Wide Convergence Tester"); gwctcore.logCheck(l, logfilename, "#\t\t\t" + gwctcore.getDateTime()); gwctcore.logCheck(l, logfilename, gwctcore.spacedOut("# INPUT | Using ancestral reconstructions in:", sp) + indir); if orig_targets != "": orig_targets = orig_targets.split(" "); for t in xrange(len(orig_targets)): if orig_targets[t].find(",") != -1: orig_targets[t] = orig_targets[t].split(","); if prob_thresh == 0: convfilename = os.path.join(script_outdir, "conv_sites.txt"); divfilename = os.path.join(script_outdir, "div_sites.txt"); elif prob_thresh != 0: convfilename = os.path.join(script_outdir, "conv_sites_" + str(prob_thresh) + ".txt"); divfilename = os.path.join(script_outdir, "div_sites_" + str(prob_thresh) + ".txt"); gwctcore.filePrep(convfilename, main_header); gwctcore.filePrep(divfilename, main_header); gwctcore.logCheck(l, logfilename, gwctcore.spacedOut("# INFO | Target species:", sp) + str(orig_targets)); if unique == 1:
indir, path, treefile, prune, v, output = optParse(); # Get input options. file_flag = 0; outdir = gc.defaultOut(output, indir, "-gwct-codeml"); print "+ Creating main output directory:\t" + outdir; os.system("mkdir " + outdir); codemldir = os.path.join(outdir, "codeml-out"); ancdir = os.path.join(outdir, "anc-seqs-fa"); logfilename = os.path.join(outdir, "gwct-codeml.log"); # Set output file and directory info. gc.printWrite(logfilename, "Program call: " + " ".join(sys.argv)); pad = 50; print gc.spacedOut(gc.getTime() + " | Creating main output directory:", pad) + outdir; os.system("mkdir " + outdir); gc.printWrite(logfilename, "======================================================================="); gc.printWrite(logfilename, "\tRunning codeml to reconstruct ancestral sequences"); gc.printWrite(logfilename, "\t\t\t" + gc.getDateTime()); gc.printWrite(logfilename, gc.spacedOut("Input directory (-i):", pad) + indir); gc.printWrite(logfilename, gc.spacedOut("PAML path (-p):", pad) + path); if treefile != "": gc.printWrite(logfilename, gc.spacedOut("Tree file (-t):", pad) + treefile); else: gc.printWrite(logfilename, gc.spacedOut("No tree file specified (-t):", pad) + "codeml will infer a tree for each gene."); if prune: gc.printWrite(logfilename, gc.spacedOut("--prune set", pad) + "Pruning the tree for each gene."); # if seqtype == 'codon': # gc.printWrite(logfilename, gc.spacedOut("INFO | Seqtype set to:", pad) + "codons"); # if seqtype == 'aa':
logfile.close() uniq_header = "#\tChromosome\tGeneID\tAlignLen\tPosition\tBackgroundAlleles\tTargetAlleles\n" l = 1 sp = 65 gwctcore.logCheck( l, logfilename, "# =======================================================================" ) gwctcore.logCheck( l, logfilename, "#\tGWCT: Genome-Wide Convergence Tester -- Unique substitutions") gwctcore.logCheck(l, logfilename, "#\t\t\t" + gwctcore.getDateTime()) gwctcore.logCheck( l, logfilename, gwctcore.spacedOut("# INPUT | Using sequences in:", sp) + indir) gwctcore.logCheck( l, logfilename, gwctcore.spacedOut("# INPUT | Target species:", sp) + ",".join(targets)) gwctcore.logCheck( l, logfilename, gwctcore.spacedOut( "# OUTPUT | Output directory created within input directory:", sp) + script_outdir) gwctcore.logCheck(l, logfilename, "# ---------------------------------------------") gwctcore.logCheck(2, logfilename, uniq_header) ################################ print "# " + gwctcore.getTime() + " | Counting unique substitutions...." filelist = os.listdir(indir)
logfile.write("") logfile.close() main_header = "# Chromosome\tGeneID\tAlignLen\tPosition\tAncAlleles\tTargetAlleles\n" uniq_header = "# Chromosome\tGeneID\tAlignLen\tPosition\tBackgroundAlleles\tTargetAlleles\n" l = 1 sp = 65 gwctcore.logCheck( l, logfilename, "# =======================================================================" ) gwctcore.logCheck(l, logfilename, "#\t\tGWCT: Genome-Wide Convergence Tester") gwctcore.logCheck(l, logfilename, "#\t\t\t" + gwctcore.getDateTime()) gwctcore.logCheck( l, logfilename, gwctcore.spacedOut("# INPUT | Using ancestral reconstructions in:", sp) + indir) if orig_targets != "": orig_targets = orig_targets.split(" ") for t in xrange(len(orig_targets)): if orig_targets[t].find(",") != -1: orig_targets[t] = orig_targets[t].split(",") if prob_thresh == 0: convfilename = os.path.join(script_outdir, "conv_sites.txt") divfilename = os.path.join(script_outdir, "div_sites.txt") elif prob_thresh != 0: convfilename = os.path.join(script_outdir, "conv_sites_" + str(prob_thresh) + ".txt") divfilename = os.path.join(script_outdir, "div_sites_" + str(prob_thresh) + ".txt") gwctcore.filePrep(convfilename, main_header)