#!/usr/bin/env python3 import utilities # User defined module, has functions to read in data and display it properly sequences = utilities.setup( ) # Read in our data and return a list of three sequences ATcontent = [] # Create a new list to hold AT content for our sequences for seq in sequences: # For every sequence in our list of sequences thisAT = 0 # Start a counter for the AT content of this sequence for base in seq: # For every base in our sequence if base == 'A' or base == 'T': # If the base is an 'A' or 'T' thisAT += 1 # Add one to our AT content counter thisAT = round(thisAT / len(seq) * 100.0, 2) # Change our AT counter to reflect percent AT ATcontent.append(thisAT) # Append the percent AT to our AT content list utilities.showAT( ATcontent) # Print the AT content to the screen all pretty-like
#!/usr/bin/env python3 import utilities # User defined module, has functions to read in data and display it properly sequences = utilities.setup() # Read in our data and return a list of three sequences ATcontent = [] # Create a new list to hold AT content for our sequences for seq in sequences: # For every sequence in our list of sequences thisAT = 0 # Start a counter for the AT content of this sequence for base in seq: # For every base in our sequence if base == 'A' or base == 'T': # If the base is an 'A' or 'T' thisAT += 1 # Add one to our AT content counter thisAT = round(thisAT / len(seq) * 100.0, 2) # Change our AT counter to reflect percent AT ATcontent.append(thisAT) # Append the percent AT to our AT content list utilities.showAT(ATcontent) # Print the AT content to the screen all pretty-like
#!/usr/bin/env python3 import utilities # Import user-defined module sequences = utilities.setup() # Setup or list of sequences checkAT = lambda base: base == 'A' or base == 'T' # Lambda expression to check a single base to see if we have an 'A' or a 'T' getAT = lambda sequence: round( sum(map(checkAT, sequence)) / len(sequence) * 100, 2 ) # A lambda expression that maps the first lambda expression to a sequence. Since Python converts `True' to 1 and `False' to 0, we use `sum' to add up all of the `Trues', divide it by the length of the sequence, converts it to a percentage, and rounds to two decimal places allAT = list( map(getAT, sequences) ) # Map the second lambda expression to all sequences provided and make a list out of it utilities.showAT( allAT ) # Special `print' wrapper that makes the AT content all nice and pretty
#!/usr/bin/env python3 import utilities # Import user-defined module sequences = utilities.setup() # Setup or list of sequences checkAT = lambda base : base == 'A' or base == 'T' # Lambda expression to check a single base to see if we have an 'A' or a 'T' getAT = lambda sequence : round(sum(map(checkAT, sequence))/len(sequence)*100, 2) # A lambda expression that maps the first lambda expression to a sequence. Since Python converts `True' to 1 and `False' to 0, we use `sum' to add up all of the `Trues', divide it by the length of the sequence, converts it to a percentage, and rounds to two decimal places allAT = list(map(getAT, sequences)) # Map the second lambda expression to all sequences provided and make a list out of it utilities.showAT(allAT) # Special `print' wrapper that makes the AT content all nice and pretty