Esempio n. 1
0
def main():
	data = dataIO.readData(options.data_FN)
	data = prepData( data )
	maxVal = data[:,1].max()
	minX = data[:,0].min()
	maxX = data[:,0].max()
	temp = (maxX - minX) * 0.1
	p0 = [ maxVal, temp, temp, maxVal, maxX - temp, temp ]
	
	pF, success = optimize.leastsq( errFnc, p0[:], args=( data[:,0], data[:,1] ), maxfev=100000, xtol=1E-10 )
	print pF

	xFit = linspace(data[:,0].min(),data[:,0].max(),100)
	yFit = fitFnc( abs(pF), xFit )

	plot( data[:,0], data[:,1],'.',label='Data')
	plot( xFit, yFit, '-r',lw=2,label='Fit')
	legend()
	if options.out_FN:
		ttl = '.'.join( options.out_FN.split('.')[:-1] )
	else:
		ttl = '.'.join( options.data_FN.split('/')[-1].split('.')[:-1]) + 'Fit to Gaussians'

	xlabel('.'.join( options.data_FN.split('/')[-1].split('.')[:-1] ) )
	ylabel('Frequency')
	title(ttl)

	if options.out_FN:
		savefig(options.out_FN[:-4]+'.pdf')
	else:
		savefig('.'.join( options.data_FN.split('/')[-1].split('.')[:-1] ) + 'fit2gauss.pdf')

	print "Wrote parameters to %s" % dataIO.writeData( [ options.out_FN ], pF )

	return
Esempio n. 2
0
def main():
	# First load in all the data:
	print "Loading Data..."
	ass = Serializer.LoadData(options.ass_FN)
	tProb = mmread(options.trans_FN)
	Proj = Project.LoadFromHDF(options.proj_FN)
	rawAry = dataIO.readData(options.raw_FN)
	msmAry = dataIO.readData(options.msm_FN)

	if options.low_is_folded:
		testFcn = lambda x: x <= options.fCut
	else:
		testFcn = lambda x: x >= options.fCut
	print "Calculating the raw folded over time..."
	# Now break up the raw data by trajectory:
	sum = 0
	rawTrajs = []
	for i in range( len( Proj['TrajLengths'] ) ):
		rawTrajs.append( rawAry[ sum : sum + Proj['TrajLengths'][i] ] )
		sum += Proj['TrajLengths'][i]

	# Now calculate the steps it takes to fold for each trajectory:
	time2fold_raw = []
	for trj in rawTrajs:
		count = 0
		for frame in trj:
			if testFcn(frame):
				break
			count += 1
		time2fold_raw.append( count )	
	time2fold_raw = array( time2fold_raw )
	rawName = dataIO.writeData( [ "RAW_FractionFolded" ], time2fold_raw )
	# Now calculate the msm fraction folded (using msmTools.calcFracFold)
	x0 = zeros( tProb.shape[0] ) # This start vector is based on the first frame of all the trajectories
	for i in range( ass.shape[0] ):
		x0[ ass[i,0] ] += 1.
	x0 /= float(ass.shape[0])
	print "Defining the folded state and calculating the MSM folded over time"
	# Need to define the folded state. Will use a cutoff, but if there are no states below/above the cutoff then pick the min/max value
	Fstates = []
	for index,stateAvg in enumerate(msmAry[:,1]):
		if testFcn( stateAvg ):
			Fstates.append( index )
	Fstates = array( Fstates )

	if not Fstates.any():
		if options.low_is_folded:
			Fstates = array([ where( msmAry[:,1] == msmAry[:,1].min() ) ] )
		else:
			Fstates = array([ where( msmAry[:,1] == msmAry[:,1].max() ) ] )
	N = time2fold_raw.max() / options.lag + 1
	time2fold_msm = msmTools.calcFracFold( Fstates, tProb, x0, N = N )
	datName = dataIO.writeData( [ "MSM_FractionFolded", str(options.lag) ], time2fold_msm )
	print "Saved data to %s" % datName
	# Now plot everything
	print "Making plot ..."
	hist( time2fold_raw, bins=100, histtype='step',label="Raw Data",cumulative=True,normed=True)
	
	plot( arange( N ) * options.lag , time2fold_msm, label="MSM")
	hlines( 1.0, xmin=0, xmax=time2fold_raw.max(),color='red' )
	xlim([0,time2fold_raw.max()])
	ylim([0,1.25])
	legend()
	xlabel( 'Time (frames)' )
	ylabel( 'Fraction Folded' )
	if options.title:
		title( 'Fraction folded over time (%s)' % options.title)
	else:
		title( 'Fraction folded over time' )
	text( 0.75 * time2fold_raw.max(), 0.2, "N = %d" % ass.shape[0] )
	savefig( "FracFolded_%s_rawVsMsm.pdf" % '.'.join( options.raw_FN.split('/')[-1].split('.')[:-1] ) )
	print "Plot saved to %s" % ("FracFolded_%s_rawVsMsm.pdf" % '.'.join( options.raw_FN.split('/')[-1].split('.')[:-1] ) )	
Esempio n. 3
0
   exit()

Total = []
nameList =[ 'CombinedData' ]

for i in range( len( options.data_FNs ) ):
   fn = options.data_FNs[i] 
   C = options.coefs[i]
   if C % 1: # Nonzero return from mod 1 means this is not an integer, so write as a float
      nameList.append('%.1e'%C)
   else: # It's an integer!
      nameList.append('%d'%int(C))
   nameList.append(fn)
   dat = dataIO.readData( fn )
   if len( dat.shape ) > 1:
      print "Using first column of data... re-shape the data if this doesn't work."
      dat = dat[:,0]
   if len( dat.shape ) == 0:
      dat = np.array([ dat ])

   Total.append( C * dat )


Total = np.array( Total ).sum(axis=0)

name = dataIO.writeData( nameList, Total, txt=False )

print "Wrote the combination to %s" % name