def surrounding_OneFrame(Input_MoleParentFolder, Output_moleParentFolder, Output_plotParentFolder, GroupNum, FrameNum, backbone_range = 2, close = False): GroupNum = int(GroupNum) FrameNum = int(FrameNum) GroupFolder = mfc.get_grouppath(GroupNum, Input_MoleParentFolder) grayData_array = fi.get_grayData_frominf(GroupNum, FrameNum) display_array = copy.deepcopy(grayData_array) molecule_filenames = mfc.get_names_setframe(GroupFolder, FrameNum) molecule_amount = len(molecule_filenames) start_cells = [] if(molecule_amount): for molecule_filename in molecule_filenames: mole_start_cell = surrounding_OneMolecule_forframe(display_array, Input_MoleParentFolder, Output_moleParentFolder, Output_plotParentFolder, GroupNum, FrameNum, 0, backbone_range, close, molecule_filename) start_cells.append(mole_start_cell) print "end of frame!" plt.figure(FrameNum, figsize=(16, 12), dpi = 100) mergeplot = plt.imshow(display_array) mergeplot.set_cmap(colormap) plt.colorbar() for ind in range(0, molecule_amount): mole_start_position = mfc.get_coordinate(start_cells[ind], ncol) text_position = [mole_start_position[0]-15, mole_start_position[1]] text = molecule_filenames[ind].split(".")[0].split("e")[2] plt.text(text_position[1], text_position[0], text, color = "yellow", size = 'medium',weight = 400) mergeplot.set_clim([np.min(display_array), image_max]) else: plt.figure(1,figsize=(16, 12), dpi = 100) mergeplot = plt.imshow(display_array) mergeplot.set_cmap(colormap) plt.colorbar() mergeplot.set_clim([np.min(display_array), image_max]) GroupName = "group1-" + str(GroupNum) + "-inca34-outputs/" FrameName = "frame" + str(FrameNum) output_groupfolder = os.path.join(Output_moleParentFolder, GroupName) output_framefolder = os.path.join(output_groupfolder, FrameName) if(not os.path.exists(output_framefolder)): os.mkdir(output_framefolder) os.chdir(output_framefolder) framename_png = "frame" + str(FrameNum) + ".png" plt.savefig(framename_png) output_groupfolder_plot = os.path.join(Output_plotParentFolder, GroupName) output_framefolder_plot = os.path.join(output_groupfolder_plot, FrameName) if(not os.path.exists(output_framefolder_plot)): os.mkdir(output_framefolder_plot) framename_png_plot = framename_png shutil.copyfile(os.path.join(output_framefolder,framename_png),os.path.join(output_framefolder_plot,framename_png_plot)) plt.close() # plt.show() return molecule_amount
def surrounding_OneGroup(Input_MoleParentFolder, Output_moleParentFolder, Output_plotParentFolder, GroupNum, backbone_range = 2, close = False): GroupNum = int(GroupNum) GroupFolder = mfc.get_grouppath(GroupNum, Input_MoleParentFolder) framenames = fi.get_framenames(GroupNum) for FrameNum in range(0, len(framenames)): print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for frame ", FrameNum, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" surrounding_OneFrame(Input_MoleParentFolder, Output_moleParentFolder, Output_plotParentFolder, GroupNum, FrameNum, backbone_range, close) print "end of group!"
def surrounding_OneGroup(Input_MoleParentFolder, Output_moleParentFolder, Output_plotParentFolder, GroupNum, backbone_range=2, close=False): GroupNum = int(GroupNum) GroupFolder = mfc.get_grouppath(GroupNum, Input_MoleParentFolder) framenames = fi.get_framenames(GroupNum) for FrameNum in range(0, len(framenames)): print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for frame ", FrameNum, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" surrounding_OneFrame(Input_MoleParentFolder, Output_moleParentFolder, Output_plotParentFolder, GroupNum, FrameNum, backbone_range, close) print "end of group!"
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 surrounding_OneFrame(Input_MoleParentFolder, Output_moleParentFolder, Output_plotParentFolder, GroupNum, FrameNum, backbone_range=2, close=False): GroupNum = int(GroupNum) FrameNum = int(FrameNum) GroupFolder = mfc.get_grouppath(GroupNum, Input_MoleParentFolder) grayData_array = fi.get_grayData_frominf(GroupNum, FrameNum) display_array = copy.deepcopy(grayData_array) molecule_filenames = mfc.get_names_setframe(GroupFolder, FrameNum) molecule_amount = len(molecule_filenames) start_cells = [] if (molecule_amount): for molecule_filename in molecule_filenames: mole_start_cell = surrounding_OneMolecule_forframe( display_array, Input_MoleParentFolder, Output_moleParentFolder, Output_plotParentFolder, GroupNum, FrameNum, 0, backbone_range, close, molecule_filename) start_cells.append(mole_start_cell) print "end of frame!" plt.figure(FrameNum, figsize=(16, 12), dpi=100) mergeplot = plt.imshow(display_array) mergeplot.set_cmap(colormap) plt.colorbar() for ind in range(0, molecule_amount): mole_start_position = mfc.get_coordinate(start_cells[ind], ncol) text_position = [ mole_start_position[0] - 15, mole_start_position[1] ] text = molecule_filenames[ind].split(".")[0].split("e")[2] plt.text(text_position[1], text_position[0], text, color="yellow", size='medium', weight=400) mergeplot.set_clim([np.min(display_array), image_max]) else: plt.figure(1, figsize=(16, 12), dpi=100) mergeplot = plt.imshow(display_array) mergeplot.set_cmap(colormap) plt.colorbar() mergeplot.set_clim([np.min(display_array), image_max]) GroupName = "group1-" + str(GroupNum) + "-inca34-outputs/" FrameName = "frame" + str(FrameNum) output_groupfolder = os.path.join(Output_moleParentFolder, GroupName) output_framefolder = os.path.join(output_groupfolder, FrameName) if (not os.path.exists(output_framefolder)): os.mkdir(output_framefolder) os.chdir(output_framefolder) framename_png = "frame" + str(FrameNum) + ".png" plt.savefig(framename_png) output_groupfolder_plot = os.path.join(Output_plotParentFolder, GroupName) output_framefolder_plot = os.path.join(output_groupfolder_plot, FrameName) if (not os.path.exists(output_framefolder_plot)): os.mkdir(output_framefolder_plot) framename_png_plot = framename_png shutil.copyfile(os.path.join(output_framefolder, framename_png), os.path.join(output_framefolder_plot, framename_png_plot)) plt.close() # plt.show() return molecule_amount
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!"