User Tools

Site Tools


examkey

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
examkey [2018/12/10 10:52]
dokuroot created
examkey [2018/12/10 10:59] (current)
dokuroot
Line 1: Line 1:
 +===== Exam Key =====
 +----
 +<file python exam_key.py>​
 +
 +"""​
 +DSCI 511 Exam Answer Key
 +"""​
 +
 def gc_content(sequence):​ def gc_content(sequence):​
 + """​
 + Caclulates GC content in a sequence
 + """​
  gc = 0  gc = 0
  for nt in sequence:  for nt in sequence:
Line 10: Line 21:
   
 def word_count(input_file):​ def word_count(input_file):​
 + """​
 + Counts the numbers of lines and characters in a file
 + """​
  try:  try:
  file_handle = open(input_file)  file_handle = open(input_file)
Line 25: Line 39:
  
 def matrix_mean(matrix):​ def matrix_mean(matrix):​
 + """​
 + Calculates the mean of each row in a matrix
 + """​
  l = []  l = []
  for i in range(len(matrix)):​  for i in range(len(matrix)):​
Line 35: Line 52:
   
 def element_counter(some_list):​ def element_counter(some_list):​
 + """​
 + Counts occurences of each element in a list
 + """​
  d = {}  d = {}
  for element in some_list:  for element in some_list:
Line 42: Line 62:
   
 def motif_coordinates(sequence,​ motif): def motif_coordinates(sequence,​ motif):
 + """​
 + Identifies the coordinates of a motif within a sequence
 + """​
  for i in range(len(sequence) - len(motif) + 1):  for i in range(len(sequence) - len(motif) + 1):
  if sequence[i:​i+len(motif)] == motif:  if sequence[i:​i+len(motif)] == motif:
  return i+1, i+len(motif)  return i+1, i+len(motif)
- +  
 +
 if __name__ == '​__main__':​ if __name__ == '​__main__':​
 + """​
 + Code for testing functions
 + """​
  print(gc_content('​ATTGCC'​)) # 0.5  print(gc_content('​ATTGCC'​)) # 0.5
  print(word_count('​test.txt'​)) # (2, 6)  print(word_count('​test.txt'​)) # (2, 6)
Line 53: Line 80:
  print(motif_coordinates('​ATGCTGTTAGCGA',​ '​CGA'​)) # (11, 13)  print(motif_coordinates('​ATGCTGTTAGCGA',​ '​CGA'​)) # (11, 13)
   
 +</​file>​
  
examkey.1544464322.txt.gz · Last modified: 2018/12/10 10:52 by dokuroot