@@ -0,0 +1,2238 @@
+#Python Problem 3%0A#mode.py%0A#Introduction to Bioinformatics Assignment 2%0A#Purpose:Calculating the mode of a dataset%0A#Your Name: Michael Thomas%0A#Date: 10/12/15%0A%0A#will contain all the data of a list including some unwanted carriage return symbols%0AtempList = %5B%5D%0A#will contain the data as floats after it is stripped and the header is removed%0AmyData = %5B%5D%0A#will store the header%0Aheader = %22%22%0A#this will store the value of the mode%0Amode = 0%0A%0A#TASK1%0A#We have the file data.txt read all the values of this file in the list tempList%0A#open data.txt and save to a tempList%0Atext_file = open('data.txt' , 'r')%0AtempList = text_file.readlines()%0Atext_file.close()%0Aprint tempList%0A%0A#TASK2%0A#We don't want the header to be in the list Pop it and save it into the header variable%0A#pop out header (position 0 in list tempList) and save to header.%0Aheader = tempList.pop(0).strip()%0A%0Aprint header%0A%0A#TASK3%0A#for every member of tempList, clean it up from carriage return, convert it into a float and add it to the list myData%0A#Using list comprehension, we delete all '%5Cr%5Cn' from each line in tempList%0AmyData = %5Bline.rstrip('%5Cr%5Cn') for line in tempList%5D%0A#Simialr to the list comprehension above, we convert all items to floats%0AmyData = %5Bfloat(i) for i in myData%5D %0Aprint myData%0A#print type(myData%5B1%5D)%0A%0A#TASK4%0A#Sort the list myData%0AmyData.sort()%0Aprint myData%0A%0A#TASK5%0A#using the list of floats myData Find the MODE of the data%0A#The mode of a dataset is the number that occurs most frequently.%0A#i.e. in the list %5B2,2,3,3,3,4%5D the mode is 3%0A#create dictionary myDic%0AmyDic = %7B%7D%0A%0A#using exceptions, we can incriment the key if a repeat%0A#value is found, except if the value is unique%0A#this will create a counter that will contain%0A#len(myData) keys and their corresponding values%0A#that each key repeats in myData%0Afor i in myData:%0A%09try:%0A%09%09myDic%5Bi%5D += 1%0A%09except:%0A%09%09myDic%5Bi%5D = 1%0Aprint myDic%0A#calculate the maximum values in the dictionary%0A#this will represent the value of the mode%0Amaxval =  max(myDic.values())%0A#for loop to print the key for the %0A#corresponding value of maxval which will%0A#be the mode for the dataset%0Afor key, value  in myDic.items():%0A%09if value == maxval:%0A%09%09mode = key%0A#print results%0Aprint %22%5Cn%22%0Aprint %22The mode of the:%22, header, %22 dataset is: %22, mode%0Aprint %22%5Cn%22%0A

Create mode.py