for seq_type in DNA, RNA: complement_table[seq_type] = string.maketrans( original_bases[seq_type], complement_bases[seq_type]) return complement_table # When called/imported, always set up the complement table complement_table = complement_table_setup() ### The actual complement function def complement(input_sequence, input=''): # if input type isn't given, detect RNA/DNA sequence type (default to DNA) if input == 'DNA': input_type = DNA elif input == 'RNA': input_type = RNA else: if input_sequence.count('U') > 0: input_type = RNA elif input_sequence.count('u') > 0: input_type = RNA else: input_type = DNA complement_seq = input_sequence.translate(complement_table[input_type]) return complement_seq ### If called directly, read, parse and complement the input. if __name__ == '__main__': import read_input, transform_sequence_input, parse_fasta input = read_input.read_input() for line in transform_sequence_input.transform_sequence_input( input, complement): parse_fasta.print_seq(line)
#! /usr/bin/env python """ This program takes one DNA sequence as an argument, prints the reverse-complement. Weronika Patena, nov2008 """ import complement ### The actual reverse-complement function: def reverse_complement(input_sequence,input_type=''): # use the complement function from the complement module complement_seq = complement.complement(input_sequence,input_type) # easy reverse method: full list slice with a step of -1 reverse_complement_seq = complement_seq[::-1] return reverse_complement_seq ### If called directly: # try reading the argument; if none given, read from stdin (which is what makes it work with pipes (echo ctcgag | script.py) and when called on a selection in vi and such). if __name__ == '__main__': import read_input,transform_sequence_input,parse_fasta # check if input is a list of files (i.e. if first arg is a valid filename - good enough) input = read_input.read_input() # transform_sequence_input takes an input AND the function to apply to it - in this case rev-compl for line in transform_sequence_input.transform_sequence_input(input,reverse_complement): parse_fasta.print_seq(line)
#! /usr/bin/env python """ This program takes one DNA sequence as an argument, prints the reverse. Weronika Patena, nov2008 """ ### The actual reverse function: def reverse(input_seq): reverse_seq = input_seq[::-1] return reverse_seq ### If called directly: # try reading the argument; if none given, read from stdin (which is what makes it work with pipes (echo ctcgag | script.py) and when called on a selection in vi and such). if __name__ == "__main__": import read_input, transform_sequence_input, parse_fasta # check if input is a list of files (i.e. if first arg is a valid filename - good enough)) input = read_input.read_input() # transform_sequence_input takes an input AND the function to apply to it - in this case reverse() for line in transform_sequence_input.transform_sequence_input(input, reverse): parse_fasta.print_seq(line)
base_table[seq_type] += base_table[seq_type].lower() # all other characters just get preserved, which is good. # define actual complement translation tables for seq_type in DNA,RNA: complement_table[seq_type] = string.maketrans(original_bases[seq_type], complement_bases[seq_type]) return complement_table # When called/imported, always set up the complement table complement_table = complement_table_setup() ### The actual complement function def complement(input_sequence,input=''): # if input type isn't given, detect RNA/DNA sequence type (default to DNA) if input=='DNA': input_type = DNA elif input=='RNA': input_type = RNA else: if input_sequence.count('U')>0: input_type = RNA elif input_sequence.count('u')>0: input_type = RNA else: input_type = DNA complement_seq = input_sequence.translate(complement_table[input_type]) return complement_seq ### If called directly, read, parse and complement the input. if __name__ == '__main__': import read_input,transform_sequence_input,parse_fasta input = read_input.read_input() for line in transform_sequence_input.transform_sequence_input(input,complement): parse_fasta.print_seq(line)
#! /usr/bin/env python2.7 """ This program takes one DNA sequence as an argument, prints the reverse-complement. Weronika Patena, nov2008 """ import complement ### The actual reverse-complement function: def reverse_complement(input_sequence, input_type=''): # use the complement function from the complement module complement_seq = complement.complement(input_sequence, input_type) # easy reverse method: full list slice with a step of -1 reverse_complement_seq = complement_seq[::-1] return reverse_complement_seq ### If called directly: # try reading the argument; if none given, read from stdin (which is what makes it work with pipes (echo ctcgag | script.py) and when called on a selection in vi and such). if __name__ == '__main__': import read_input, transform_sequence_input, parse_fasta # check if input is a list of files (i.e. if first arg is a valid filename - good enough) input = read_input.read_input() # transform_sequence_input takes an input AND the function to apply to it - in this case rev-compl for line in transform_sequence_input.transform_sequence_input( input, reverse_complement): parse_fasta.print_seq(line)