Create the following variables:
w = 10.2 x = 1.3 y = 2.8 z = 17.5 dna1 = 'attattaggaccaca' dna2 = 'attattaggaacaca' species1 = 'diplodocus' species2 = 'tyrannosaurus'
Use them to print whether or not the following statements are
wis greater than 10
xis less than 15
xis greater than
- 2 *
x+ 0.2 is equal to
dna1is the same as
dna1is not the same as
- The number of occurrences of the base t is the same in
wis between 13.2 and 13.5
wis greater than
yis greater than
dna1is longer than 5 bases, or
zis less than
x, or both
- The combined length of
dna2is greater than or equal to 30
y) divided by the logarithm (base 10) of 100 is equal to 7.15
- The GC content (which is always a percentage) of
dna1is not the same as the GC content of
The following function is intended to check if two geographic points are close to one another. If they are it should return
True. If they aren’t, it should return
False. Two points are considered near to each other if the absolute value of the difference in their latitudes is less than one and the absolute value of the difference in their longitudes is less than one.
Fill in the
_________in the function to make it work and then use it to check if the following pairs of points are near or not and print out the answers.
def near(lat1, long1, lat2, long2): """Check if two geographic points are near each other""" if (abs(lat1 - lat2) < 1) and (_________): near = True else: near = _________ return near
- Point 1: latitude = 29.65, longitude = -82.33. Point 2: latitude = 41.74, longitude = -111.83.
- Point 1: latitude = 29.65, longitude = -82.33. Point 2: latitude = 30.5, longitude = -82.8.
- Point 1: latitude = 48.86, longitude = 2.35. Point 2: latitude = 41.89, longitude = 2.5.
Write a function,
dna_or_rna(sequence), that determines if a sequence of base pairs is DNA, RNA, or if it is not possible to tell given the sequence provided. Since all the function will know about the material is the sequence the only way to tell the difference between DNA and RNA is that RNA has the base Uracil (
'u') instead of the base Thymine (
't'). Have the function return one of three outputs:
'UNKNOWN'. Use the function and a
forloop to print the type of the sequences in the following list.
sequences = ['ttgaatgccttacaactgatcattacacaggcggcatgaagcaaaaatatactgtgaaccaatgcaggcg', 'gauuauuccccacaaagggagugggauuaggagcugcaucauuuacaagagcagaauguuucaaaugcau', 'gaaagcaagaaaaggcaggcgaggaagggaagaagggggggaaacc', 'guuuccuacaguauuugaugagaaugagaguuuacuccuggaagauaauauuagaauguuuacaacugcaccugaucagguggauaaggaagaugaagacu', 'gauaaggaagaugaagacuuucaggaaucuaauaaaaugcacuccaugaauggauucauguaugggaaucagccggguc']
Optional: For a little extra challenge make your function work with both upper and lower case letters, or even strings with mixed capitalizationExpected outputs for DNA or RNA 1: 1
Dr. Granger is interested in studying the factors controlling the size and carbon storage of shrubs. This research is part of a larger area of research trying to understand carbon storage by plants. She has conducted a small preliminary experiment looking at the effect of three different treatments on shrub volume at four different locations. She wants to conduct a preliminary analysis of these data to include in a grant proposal and she would like you to conduct the analysis for her (she might be a world renowned expert in carbon storage in plants, but she sure doesn’t know much about computers). She has placed a data file on the web for you to download.
You might be able to do this analysis by hand in Excel, but Dr. Granger seems to always get funded meaning that you’ll be doing this again soon with a much larger dataset. So, you decide to write a script so that it will be easy to do the analysis again.
Write a Python script that:
- Imports the data using
numpy. It has a header row so you’ll need to tell
numpy.loadtxt()to ignore it by providing the optional argument
- Loops over the rows in the dataset
forloop to check each row in the dataset, groups by height as
if (height > 5),
if (2 <= height < 5), or
if (height < 2), and determines the total amount of carbon in the shrub.
The total amount of carbon is equal to
1.8 + 2 * log(volume)where
volumeis the volume of the shrub (
length * width * height).
- Stores this information as table in a nested list (i.e., a list that contains
a bunch of lists, with each of these sub-lists holding the results for one
shrub) where the first column has the experiment number, the second column
contains the string
'short'depending on the height of the shrub, and the third column contains the shrub carbon.
- Exports this table to a
csv(comma delimited text) file titled
- Use functions to break the code up into manageable pieces.
To help you get started here is a function for exporting the results to a CSV file. To use it you’ll need to copy and paste it into your code. It uses the
csvmodule so you’ll need to remember to import it.
def export_to_csv(data, filename): """Export list of lists to comma delimited text file""" outputfile = open(filename, 'wb') datawriter = csv.writer(outputfile) datawriter.writerows(data) outputfile.close()
Optional: If you’d like to test your skills a little more, try: 1. Adding a header row to you output file; and 2. Determining the average carbon in a shrub for each of the different experiments and printing those values to the screen.Expected outputs for Shrub Volume: 1
- Imports the data using