<filename>calculateCDFallFiles.py
#!/usr/bin/env python

from __future__ import division
import io
import sys
import os
import os.path as op
from sys import argv
import skimage
from skimage import io
import csv
import numpy as np 
import matplotlib.pyplot as plt
from scipy import stats as stats

#This script is designed to take the results (area values) from Analyze Particles and generate 
#the appropriate cumulative sum data and data plot.
#Parameter: dirName - the directory that includes the csv files output by analyze particles
#Parameter: bins - this is the number of equally sized bins that the user would like to generate 
def main(dirName, bins):
        #Iterates through all the csv files that are output by the Analyze Particles function on ImageJ	
	for fileName in os.listdir(os.path.abspath(dirName)):
		if fileName.endswith(".csv"):
			#This extracts only the area values in a particular csv file generated by Analyze Particles 
			with open(fileName, 'rb') as f:
                		lines = csv.reader(f)

                		Column2 = []

				#This statement checks for the title line for the csv files generated by Analyze Particles
                		for line in lines:
                        		if(line[1] != 'Area'):
						#takes only the area values in the csv file
                                		Column2.append(int(line[1]))
                        		else:
                                		print 'I skipped a line'


			#converts the string argument into a usable integer value  
			bins = int(bins)
	
			print "This is the input values from the text file: "	
			print Column2

			#this function generates the binned sum values of all the area values in a single csv file (one condition)
			#using the bins parameter to designate the number of equally sized bins into which the area values will be
			#placed in. 
			binnedSums, edges, num = stats.binned_statistic(Column2, Column2, 'sum', bins)

			print "This is the sum of regions in their particular bins: "
			print binnedSums

			print "These are the edges of the bins: "
			print edges			
			
			#This generates a cummulative sum for the binned sum values generated by the method above (binned_statistics)
			cumsum = np.cumsum(binnedSums)
	
			print "This is the cummulative sum based on the bins generated: "
			print cumsum
	
			print "This is the total sum: "
			print cumsum[-1]

			name = op.splitext(fileName)[0]	
	
			totalSum = cumsum[-1]
			
			#This generates the ratio to explain the proportion of higher order structures in a given negative stain image
			normalized = cumsum/totalSum

			print "This is the normalized values:"
                        print normalized

			#Generates the files that store the cumulative sum values
                        overallDataName = name + 'OverallRawData.csv'
			binEdgeData = name + 'binEdges.csv'

                        np.savetxt(overallDataName, normalized, delimiter=",")
			np.savetxt(binEdgeData, edges, delimiter=",")

			plt.plot(edges[:-1], normalized, label=name)

	plt.legend(loc = 'center right')
	plt.savefig("Montage_histogram.png")
	plt.close()


#This is the main method which will run the only function of the script, both of the parameters that are needed
#are passed as command line arguments by the user: first argument is the path to the directory that contains
#the output files of Analyze Particles, second argument is the number of bins that will be generated for the 
#cumulative sum data and data plot. 
if __name__ == "__main__":
	if(len(sys.argv) != 3):
		sys.exit("Include a data text file that you want to analyze and desired binning: two additional arguments are needed")
	else:
		main(sys.argv[1], sys.argv[2])


<filename>calculateCDFallFiles.py
#!/usr/bin/env python

from __future__ import division
import io
import sys
import os
import os.path as op
from sys import argv
import skimage
from skimage import io
import csv
import numpy as np 
import matplotlib.pyplot as plt
from scipy import stats as stats

#This script is designed to take the results (area values) from Analyze Particles and generate 
#the appropriate cumulative sum data and data plot.
#Parameter: dirName - the directory that includes the csv files output by analyze particles
#Parameter: bins - this is the number of equally sized bins that the user would like to generate 
def main(dirName, bins):
        #Iterates through all the csv files that are output by the Analyze Particles function on ImageJ	
	for fileName in os.listdir(os.path.abspath(dirName)):
		if fileName.endswith(".csv"):
			#This extracts only the area values in a particular csv file generated by Analyze Particles 
			with open(fileName, 'rb') as f:
                		lines = csv.reader(f)

                		Column2 = []

				#This statement checks for the title line for the csv files generated by Analyze Particles
                		for line in lines:
                        		if(line[1] != 'Area'):
						#takes only the area values in the csv file
                                		Column2.append(int(line[1]))
                        		else:
                                		print 'I skipped a line'


			#converts the string argument into a usable integer value  
			bins = int(bins)
	
			print "This is the input values from the text file: "	
			print Column2

			#this function generates the binned sum values of all the area values in a single csv file (one condition)
			#using the bins parameter to designate the number of equally sized bins into which the area values will be
			#placed in. 
			binnedSums, edges, num = stats.binned_statistic(Column2, Column2, 'sum', bins)

			print "This is the sum of regions in their particular bins: "
			print binnedSums

			print "These are the edges of the bins: "
			print edges			
			
			#This generates a cummulative sum for the binned sum values generated by the method above (binned_statistics)
			cumsum = np.cumsum(binnedSums)
	
			print "This is the cummulative sum based on the bins generated: "
			print cumsum
	
			print "This is the total sum: "
			print cumsum[-1]

			name = op.splitext(fileName)[0]	
	
			totalSum = cumsum[-1]
			
			#This generates the ratio to explain the proportion of higher order structures in a given negative stain image
			normalized = cumsum/totalSum

			print "This is the normalized values:"
                        print normalized

			#Generates the files that store the cumulative sum values
                        overallDataName = name + 'OverallRawData.csv'
			binEdgeData = name + 'binEdges.csv'

                        np.savetxt(overallDataName, normalized, delimiter=",")
			np.savetxt(binEdgeData, edges, delimiter=",")

			plt.plot(edges[:-1], normalized, label=name)

	plt.legend(loc = 'center right')
	plt.savefig("Montage_histogram.png")
	plt.close()


#This is the main method which will run the only function of the script, both of the parameters that are needed
#are passed as command line arguments by the user: first argument is the path to the directory that contains
#the output files of Analyze Particles, second argument is the number of bins that will be generated for the 
#cumulative sum data and data plot. 
if __name__ == "__main__":
	if(len(sys.argv) != 3):
		sys.exit("Include a data text file that you want to analyze and desired binning: two additional arguments are needed")
	else:
		main(sys.argv[1], sys.argv[2])


#!/usr/bin/env python #This script is designed to take the results (area values) from Analyze Particles and generate #the appropriate cumulative sum data and data plot. #Parameter: dirName - the directory that includes the csv files output by analyze particles #Parameter: bins - this is the number of equally sized bins that the user would like to generate #Iterates through all the csv files that are output by the Analyze Particles function on ImageJ #This extracts only the area values in a particular csv file generated by Analyze Particles #This statement checks for the title line for the csv files generated by Analyze Particles #takes only the area values in the csv file #converts the string argument into a usable integer value #this function generates the binned sum values of all the area values in a single csv file (one condition) #using the bins parameter to designate the number of equally sized bins into which the area values will be #placed in. #This generates a cummulative sum for the binned sum values generated by the method above (binned_statistics) #This generates the ratio to explain the proportion of higher order structures in a given negative stain image #Generates the files that store the cumulative sum values #This is the main method which will run the only function of the script, both of the parameters that are needed #are passed as command line arguments by the user: first argument is the path to the directory that contains #the output files of Analyze Particles, second argument is the number of bins that will be generated for the #cumulative sum data and data plot.