else: result = minimize(f, x0, bounds=bounds, args=(tree, seqs), method='SLSQP', options={'maxiter': maxit}) x = result.x pi = {'A': x[0], 'C': x[1], 'G': x[2], 'T': (1 - x[0] - x[1] - x[2])} gtr = { 'AC': x[3], 'AG': x[4], 'AT': x[5], 'CG': x[6], 'CT': x[7], 'GT': x[8] } return pi, gtr # main function if __name__ == "__main__": args = parseArgs() tree = dendropy.Tree.get(file=args.tree, schema='newick') seqs = parseFASTA(args.seqs) pi, R = MLGTR(tree, seqs, maxit=args.maxit) args.out.write(' '.join([str(pi[c]) for c in 'ACGT']) + '\n') args.out.write( str(R['CT']) + ' ' + str(R['AT']) + ' ' + str(R['GT']) + ' ' + str(R['AC']) + ' ' + str(R['CG']) + ' ' + str(R['AG']) + '\n')
help="Input FASTA File") parser.add_argument('-o', '--output', required=False, type=argparse.FileType('w'), default=sys.stdout, help="Output FASTA File") parser.add_argument('-p', '--indel', required=False, type=float, default=0.1, help="Indel Ratio") args = parser.parse_args() start_time = time.time() sys.stderr.write("User-specified indel rate: " + str(args.indel) + '\n') gap = indelToGap(args.indel) sys.stderr.write("Indel rate converted to gap rate: " + str(gap) + '\n') sys.stderr.write("Parsing input FASTA file...\n") seqs = parseFASTA(args.input) sys.stderr.write("Computing 2D dynamic programming matrix...\n") score, aln = pairAlign(seqs, gap) sys.stderr.write("Writing output alignment...\n") for ID in sorted(aln.keys()): args.output.write('>') args.output.write(ID) args.output.write('\n') args.output.write(aln[ID]) args.output.write('\n') sys.stderr.write("--- Completed in %s seconds ---" % (time.time() - start_time) + '\n')