def init_args(args): global new_state, behaviour i = 0 while i < len(args): if args[i] in ['-i', '--input']: f = fasta.read_from(args[i + 1]) i += 1 new_state['SEQUENCE'] = f[0].sequence elif args[i] in ['-f', '--fast']: behaviour["fast"] = True elif args[i] in ['-o', '--output']: i += 1 behaviour["output"] = open(args[i], 'w') elif args[i] in ['-h', '--help']: print "Query Primer3" print "by Damien Leroux <*****@*****.**>" print print "Usage: %s [-f,--fast] [-o,--output filename]", print "[configuration_key=value...]" % args[0] print "Configuration keys:" for (k, v) in filter(lambda x: ' ' not in x, state.items()): if v: print ' ', k.lower(), '(default %s)' % v else: print ' ', k.lower() sys.exit(0) else: key, value = args[i].split("=") key = key.upper() if ' ' not in key and key in state: new_state[key] = value else: print "I don't know nothing about a '%s', I do mean it." % key sys.exit(1) i += 1
def main(argv): lines = files.read_lines(argv[0]) tree = lines[0] strings = fasta.read_from(lines[1:]) z, L = phylogeny.small_parsimony(tree, strings) print z print '\n'.join('>%s\n%s' % (key, value) for key, value in L.iteritems())
def extract(filename): global fcount, ftotal fcount += 1 #print "\r%i/%i" % (fcount, ftotal), print "%i/%i" % (fcount, ftotal), exti = filename.rfind('.') ext = filename[exti:] path, query = os.path.split(filename[:exti]) fhits = fasta.read_from(filename) print filename, exti, ext, path, query if query in fhits: fquery = fasta.Fasta() fquery.add_seq(fhits[query]) fhits.remove(query) fhits.save_to(os.path.join(path, query + '-hits' + ext)) fquery.save_to(os.path.join(path, query + '-query' + ext))
def main(argv): lines = files.read_lines(argv[0]) tree = lines[0] strings = fasta.read_from(lines[1:]) output = [] for r in phylogeny.reverse_substitutions(tree, strings): path = r[0] position = r[1] original = strings[path[0].name][position] substituted = strings[path[1].name][position] reverted = strings[path[-1].name][position] output.append('%s %s %s %s->%s->%s' % (path[1].name, path[-1].name, position + 1, original, substituted, reverted)) print '\n'.join(output)
#!/usr/bin/env python from query_primer3 import query_primer3 import fasta import sys import re import os executable = True if len(sys.argv) < 2: print "Usage: %s multi_fasta PRIMER3_ARG=VALUE..." mfas = fasta.read_from(sys.argv[1]) primer3args = sys.argv[2:] bad_chr = re.compile("[^a-zA-Z0-9_-]") basedir, basename = os.path.split(sys.argv[1]) for i, s in enumerate(mfas): out = os.path.join(basedir, bad_chr.sub('_', s.header) + '.primer3') print '[%i/%i]' % (1 + i, len(mfas)), "Querying", s.header query_primer3(['SEQUENCE=' + s.sequence, '-o', out] + primer3args)