Create the following variables:
w = 10.2
x = 1.3
y = 2.8
z = 17.5
dna1 = 'attattaggaccaca'
dna2 = 'attattaggaacaca'
species1 = 'diplodocus'
species2 = 'tyrannosaurus'
and use them to print whether or not the following statements are True or False:
w
is greater than 10w
+ x
is less than 15x
is greater than y
x
+ 0.2 is equal to y
dna1
is the same as dna2
dna1
is not the same as dna2
dna1
and
dna2
x
times w
is between 13.2 and 13.5species2
comes before species1
alphabeticallyw
is greater than x
, and y
is greater than z
dna1
is longer than 5 bases, or z
is less than w
* x
,
or bothw
+ x
+ y
) divided by the logarithm (base 10) of 100 is
equal to 7.15dna1
is not the
same as the GC content of dna2
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
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: ‘DNA’, ‘RNA’, or ‘UNKNOWN’. Use
the function and a for loop 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 capitalization
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:
numpy
. It has a header row so you’ll need to tell
numpy.loadtxt()
to ignore it by providing the optional argument
skiprows=1
.1.8 +
2 * log(volume)
where volume
is the volume of the shrub (i.e., its length
times its width times its height).shrubs_experiment_results.csv
.This code should 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
csv
module 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.