def main(argv=sys.argv): # read options and remove options strings from argv (avoid option # names and arguments to be handled as file names by # fileinput.input(). options = Options(argv) if options['line_regexp']: p = re.compile('^' + options.args.pop(0) + '$') else: p = re.compile(options.args.pop(0)) sys.argv[1:] = options.args # organize the main job... # check function if options['inverse']: check = lambda p, header: p.search(header) is None else: check = lambda p, header: p.search(header) is not None # parse input for header, sequence in fasta.reader(fileinput.input()): if check(p, header): fasta.writer(header, sequence, sys.stdout) # return 0 if everything succeeded return 0
def main(argv=sys.argv): # read options and remove options strings from argv (avoid option # names and arguments to be handled as file names by # fileinput.input(). options = Options(argv) # organize the main job... sequences = list(fasta.reader(fileinput.input())) n = len(sequences) l = len(sequences[0][1]) # check that all sequences are of the same length if not all(len(sequence) for header, sequence in sequences): raise ValueError("All sequence are not of the same length.") # write nuc file header sys.stdout.write(" {} {}\n".format(n, l)) # write sequence lines for header, sequence in sequences: if len(header) > 30: raise ValueError("Sequence header length must not exceed 30") nuc_writer(header, sequence, sys.stdout) # return 0 if everything succeeded return 0
def main(argv=sys.argv): # read options and remove options strings from argv (avoid option # names and arguments to be handled as file names by # fileinput.input(). options = Options(argv) sys.argv[1:] = options.args # organize the main job... for name, sequence in fasta.reader(fileinput.input()): fasta.writer(name, sequence[options["slice"]], sys.stdout) # return 0 if everything succeeded return 0
def main(argv=sys.argv): # read options and remove options strings from argv (avoid option # names and arguments to be handled as file names by # fileinput.input(). options = Options(argv) sys.argv[1:] = options.args # organize the main job... # parse input for header, sequence in fasta.reader(fileinput.input()): sys.stdout.write("{}\t{}\n".format(header[1:], len(sequence))) # return 0 if everything succeeded return 0
def main(argv=sys.argv): # read options and remove options strings from argv (avoid option # names and arguments to be handled as file names by # fileinput.input(). options = Options(argv) # get the range r = fasta.read_range(options.args.pop(0)) sys.argv[1:] = options.args # organize the main job... for header, sequence in fasta.reader(fileinput.input()): new_sequence = sequence[r] fasta.writer(header, new_sequence, sys.stdout) # return 0 if everything succeeded return 0
def main(argv=sys.argv): # read options and remove options strings from argv (avoid option # names and arguments to be handled as file names by # fileinput.input(). options = Options(argv) # get conversion table with open(options.args.pop(0)) as f: d = get_correspondance_table(f) sys.argv[1:] = options.args # organize the main job... for header, sequence in fasta.reader(fileinput.input()): try: new_header = d[header] except KeyError: new_header = header fasta.writer(new_header, sequence, sys.stdout) # return 0 if everything succeeded return 0
def main(argv=sys.argv): # read options and remove options strings from argv (avoid option # names and arguments to be handled as file names by # fileinput.input(). options = Options(argv) # get conversion table with open(options.args.pop(0)) as f: s = get_list(f) sys.argv[1:] = options.args # organize the main job... for header, sequence in fasta.reader(fileinput.input()): x = header.split()[0] if options['short'] else header if x not in s: continue fasta.writer(header, sequence, sys.stdout) # return 0 if everything succeeded return 0