def surrounding_OneMolecule_allframe(Input_MoleParentFolder, Output_moleParentFolder, Output_plotParentFolder, GroupNum, MoleculeNum, backbone_range = 2, close = False):

	GroupNum = int(GroupNum)
	MoleculeNum = int(MoleculeNum)
	
	fileContents = mfc.read_molecule_files_frominf(Input_MoleParentFolder, GroupNum, MoleculeNum)
	connect_count, frames, cells = mfc.get_frame_count_mole(fileContents)
	for FrameNum in frames:
		surrounding_OneMolecule(Input_MoleParentFolder, Output_moleParentFolder, Output_plotParentFolder, GroupNum, FrameNum, MoleculeNum, [-1,-1], backbone_range, close)
def simplify_lines_AllFrame(Input_MoleParentFolder_interval, GroupNum, MoleculeNum, threshold):

	fileContents = mfc.read_molecule_files_frominf(Input_MoleParentFolder_interval, GroupNum, MoleculeNum)
	connect_count, frames, cells = mfc.get_frame_count_mole(fileContents)

	straightness = []

	for FrameNum in frames:
		

		## readin molecule backbone information
		fileContents_setframe = mfc.get_content_setframe(fileContents, FrameNum)
		CellNumList_setframe = mfc.get_CellNumbers(fileContents_setframe)

		## create a list to store turning points of simplify polyline
		list_knots = [0, len(CellNumList_setframe)-1]

		## generate the simplify line
		simplify_test = simplify_line_test(CellNumList_setframe, threshold)
		while(simplify_test):

			## for first recursion
			if len(list_knots) == 2:
				re_time = [0]
				simplify_line(CellNumList_setframe, 0, len(CellNumList_setframe)-1, list_knots, threshold, re_time)
			## downstream recursion
			else:
				## for each segment
				for i in range(0, len(list_knots) - 2):
					## check whether this segment need more recursion
					if simplify_test_list[i]:
						re_time = [0]
						simplify_line(CellNumList_setframe, list_knots[i], list_knots[i+1], list_knots, threshold, re_time)
			list_knots = sorted(list(set(list_knots)))

			## check every segment, decide simplify polyline creation is finished or not
			simplify_test_list = []
			for i in range(0, len(list_knots) - 2):
				simplify_test_list.append(simplify_line_test(CellNumList_setframe[list_knots[i]:(list_knots[i+1] + 1)], threshold))
			simplify_test = max(simplify_test_list)
		
		## get turning positions
		turning_knots_cellnums = list(np.array(CellNumList_setframe)[list_knots])

		## get information related to turning angles
		theta_list = angle_list(turning_knots_cellnums)
		theta_max = max(map(abs, theta_list))
		theta_sum = sum(map(abs, theta_list))
		theta_net = sum(theta_list)
	
		## estimation
		test_score_sum = float(1 / math.exp((abs(theta_net) + theta_max) / 2))

		## result report
		straightness.append([FrameNum, theta_net, theta_max, test_score_sum])

	return straightness
def surrounding_OneMolecule_allframe(Input_MoleParentFolder,
                                     Output_moleParentFolder,
                                     Output_plotParentFolder,
                                     GroupNum,
                                     MoleculeNum,
                                     backbone_range=2,
                                     close=False):

    GroupNum = int(GroupNum)
    MoleculeNum = int(MoleculeNum)

    fileContents = mfc.read_molecule_files_frominf(Input_MoleParentFolder,
                                                   GroupNum, MoleculeNum)
    connect_count, frames, cells = mfc.get_frame_count_mole(fileContents)
    for FrameNum in frames:
        surrounding_OneMolecule(Input_MoleParentFolder,
                                Output_moleParentFolder,
                                Output_plotParentFolder, GroupNum, FrameNum,
                                MoleculeNum, [-1, -1], backbone_range, close)
예제 #4
0
def Effected_OneMolecule(Input_MoleParentFolder_interval, Input_SurroundingParentFolder_interval, GroupNum, MoleculeNum, layer, threshold):

#def main(argv):

#	try:                                
#        	opts, args = getopt.getopt(argv, "hs:e:", ["help", "grammar="])
#    	except getopt.GetoptError:          
#        	usage()                         
#        	sys.exit(2)   

#	GroupNum = int(args[0])	
#	MoleculeNum = int(args[1])
#	layer = int(args[2])
	
	GroupNum = int(GroupNum)	
	MoleculeNum = int(MoleculeNum)
	layer = int(layer)

	print GroupNum, MoleculeNum

	GroupName = "group1-" + str(GroupNum) + "-inca34-outputs/"

	
	
	GroupFolder = mfc.get_grouppath(GroupNum, Input_MoleParentFolder_interval)
	if os.path.exists(GroupFolder):
		molecule_fileContents = mfc.read_molecule_files_frominf(Input_MoleParentFolder_interval, GroupNum, MoleculeNum)
		connect_count, frames, cells = mfc.get_frame_count_mole(molecule_fileContents)
		for frame in frames:
			BackbonefileContents = mfc.get_content_setframe(molecule_fileContents, frame)
			
			FrameNum = frame
			surrounding_fileName = "molecule" + str(MoleculeNum) + "_frame" + str(FrameNum) + ".txt"
			SurroundingReadPath = os.path.join(Input_SurroundingParentFolder_interval, GroupName, surrounding_fileName)
			SurrID = open(SurroundingReadPath, 'r')
			SurroundingfileContents = SurrID.readlines()

			ConditionList = determine_within_forbackbone(BackbonefileContents, SurroundingfileContents, layer, threshold)
			

			## plotting
			fig = plt.figure(frame)
			BackboneIntensity = mfc.get_IntenAll(BackbonefileContents)
		
			attention_x = list(map(multiply, range(0, len(BackboneIntensity)), ConditionList))
			attention_x = filter(lambda x:x is not 0, attention_x)
			if ConditionList[0] != 0:
				attention_x.insert(0, 0)

			attention_y = map(multiply, BackboneIntensity, ConditionList)
			if attention_y.count(0) != 0:
				attention_y = filter(lambda y:y is not 0, attention_y)
		
			line, = plt.plot(BackboneIntensity, label = "intensity porfile")
			dot, = plt.plot(attention_x, attention_y, "ro", color = "red")

			Title = "Group" + str(GroupNum) + "_Molecule" + str(MoleculeNum) + " Backbone1 intensity" + "(default threshold" + str(threshold) + ")"
			plt.title(Title)			

			plt.xlabel("position(orientation depend on alignment)/pixels")
			plt.ylabel("intensity")

#			plt.legend([line], "intensity porfile", loc = 4)
			plt.legend([line, dot],  ["intensity porfile", "effected pixels(from layer"+str(layer) + ")"])
#			print ConditionList

		plt.show()
	else:
		print "group not exist!"
def simplify_lines_AllFrame(Input_MoleParentFolder_interval, GroupNum,
                            MoleculeNum, threshold):

    fileContents = mfc.read_molecule_files_frominf(
        Input_MoleParentFolder_interval, GroupNum, MoleculeNum)
    connect_count, frames, cells = mfc.get_frame_count_mole(fileContents)

    straightness = []

    for FrameNum in frames:

        ## readin molecule backbone information
        fileContents_setframe = mfc.get_content_setframe(
            fileContents, FrameNum)
        CellNumList_setframe = mfc.get_CellNumbers(fileContents_setframe)

        ## create a list to store turning points of simplify polyline
        list_knots = [0, len(CellNumList_setframe) - 1]

        ## generate the simplify line
        simplify_test = simplify_line_test(CellNumList_setframe, threshold)
        while (simplify_test):

            ## for first recursion
            if len(list_knots) == 2:
                re_time = [0]
                simplify_line(CellNumList_setframe, 0,
                              len(CellNumList_setframe) - 1, list_knots,
                              threshold, re_time)
            ## downstream recursion
            else:
                ## for each segment
                for i in range(0, len(list_knots) - 2):
                    ## check whether this segment need more recursion
                    if simplify_test_list[i]:
                        re_time = [0]
                        simplify_line(CellNumList_setframe, list_knots[i],
                                      list_knots[i + 1], list_knots, threshold,
                                      re_time)
            list_knots = sorted(list(set(list_knots)))

            ## check every segment, decide simplify polyline creation is finished or not
            simplify_test_list = []
            for i in range(0, len(list_knots) - 2):
                simplify_test_list.append(
                    simplify_line_test(
                        CellNumList_setframe[list_knots[i]:(list_knots[i + 1] +
                                                            1)], threshold))
            simplify_test = max(simplify_test_list)

        ## get turning positions
        turning_knots_cellnums = list(
            np.array(CellNumList_setframe)[list_knots])

        ## get information related to turning angles
        theta_list = angle_list(turning_knots_cellnums)
        theta_max = max(map(abs, theta_list))
        theta_sum = sum(map(abs, theta_list))
        theta_net = sum(theta_list)

        ## estimation
        test_score_sum = float(1 / math.exp((abs(theta_net) + theta_max) / 2))

        ## result report
        straightness.append([FrameNum, theta_net, theta_max, test_score_sum])

    return straightness
예제 #6
0
def Effected_OneMolecule(Input_MoleParentFolder_interval,
                         Input_SurroundingParentFolder_interval, GroupNum,
                         MoleculeNum, layer, threshold):

    #def main(argv):

    #	try:
    #        	opts, args = getopt.getopt(argv, "hs:e:", ["help", "grammar="])
    #    	except getopt.GetoptError:
    #        	usage()
    #        	sys.exit(2)

    #	GroupNum = int(args[0])
    #	MoleculeNum = int(args[1])
    #	layer = int(args[2])

    GroupNum = int(GroupNum)
    MoleculeNum = int(MoleculeNum)
    layer = int(layer)

    print GroupNum, MoleculeNum

    GroupName = "group1-" + str(GroupNum) + "-inca34-outputs/"

    GroupFolder = mfc.get_grouppath(GroupNum, Input_MoleParentFolder_interval)
    if os.path.exists(GroupFolder):
        molecule_fileContents = mfc.read_molecule_files_frominf(
            Input_MoleParentFolder_interval, GroupNum, MoleculeNum)
        connect_count, frames, cells = mfc.get_frame_count_mole(
            molecule_fileContents)
        for frame in frames:
            BackbonefileContents = mfc.get_content_setframe(
                molecule_fileContents, frame)

            FrameNum = frame
            surrounding_fileName = "molecule" + str(
                MoleculeNum) + "_frame" + str(FrameNum) + ".txt"
            SurroundingReadPath = os.path.join(
                Input_SurroundingParentFolder_interval, GroupName,
                surrounding_fileName)
            SurrID = open(SurroundingReadPath, 'r')
            SurroundingfileContents = SurrID.readlines()

            ConditionList = determine_within_forbackbone(
                BackbonefileContents, SurroundingfileContents, layer,
                threshold)

            ## plotting
            fig = plt.figure(frame)
            BackboneIntensity = mfc.get_IntenAll(BackbonefileContents)

            attention_x = list(
                map(multiply, range(0, len(BackboneIntensity)), ConditionList))
            attention_x = filter(lambda x: x is not 0, attention_x)
            if ConditionList[0] != 0:
                attention_x.insert(0, 0)

            attention_y = map(multiply, BackboneIntensity, ConditionList)
            if attention_y.count(0) != 0:
                attention_y = filter(lambda y: y is not 0, attention_y)

            line, = plt.plot(BackboneIntensity, label="intensity porfile")
            dot, = plt.plot(attention_x, attention_y, "ro", color="red")

            Title = "Group" + str(GroupNum) + "_Molecule" + str(
                MoleculeNum
            ) + " Backbone1 intensity" + "(default threshold" + str(
                threshold) + ")"
            plt.title(Title)

            plt.xlabel("position(orientation depend on alignment)/pixels")
            plt.ylabel("intensity")

            #			plt.legend([line], "intensity porfile", loc = 4)
            plt.legend([line, dot], [
                "intensity porfile",
                "effected pixels(from layer" + str(layer) + ")"
            ])
#			print ConditionList

        plt.show()
    else:
        print "group not exist!"