Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. # <Gabrielle Byczek>
  2. # <GEOG656>
  3. # Purpose: <To effectively read and write text files using Python scripting>
  4.  
  5. # Collect imports
  6. import math
  7. import os
  8.  
  9. def main():
  10. # The main function
  11.     in_file, out_file, chi_table_file = findPath()
  12.     z_score_list = calculateZscore(in_file, out_file)
  13.     print z_score_list
  14.    
  15. def findPath():
  16.     direcName = raw_input("What is the working directory?      ")
  17.     fileName = raw_input("What is the name of the input file? ")
  18.     chiSquare = raw_input("The name of the chi-squared table?  ")
  19.     outputFile = raw_input("What is the output filename?        ")
  20.     #  Assemble the paths
  21.     inputPath = os.path.join(direcName,fileName)
  22.     chiTable = os.path.join(direcName, chiSquare)
  23.     finalOutput = os.path.join(direcName, outputFile)
  24.     # Return them
  25.     return inputPath, outputFile, chiTable
  26.  
  27. def calculateZscore(inFile,outFile):
  28.     inputFile = open(inFile,"r")
  29.     zscoreList = []
  30.     # Opening outFile
  31.     outFile= open(outFile, 'w')
  32.     # Read the lines of the file
  33.     for line in inputFile.readline():
  34.         line = line.strip()
  35.         line = line.replace(" ","")
  36.         line = line.split(",")
  37.         Zscore = float(int(line[3])-int(line[4]))/(int(line[4])**(0.5))
  38.         zscoreList.append(Zscore)
  39.         line= ',' .join(line)
  40.         line = line + "," + str(Zscore) + "\n"
  41.         print('outFile = %s (type %s)' % (outFile, type(outFile).__name__))
  42.         outFile.writeline(line)
  43.     outFile.close()
  44.     return zscoreList
  45.  
  46. if __name__ == '__main__':
  47.     # Call the main() function
  48.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement