-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Embed image in nodes automation by py4cytoscape #120
Comments
Have you considered add_annotation_image()? This corresponds to the Annotation tab on the far left of the Cytoscape window, and is activated when you hit the image button. I'm not sure exactly what you're trying to accomplish, but that's what jumps to mind. Or are you trying to use an image to represent a node? If so, you might consider a visual style? Doing that in py4cytoscape isn't supported by explicit calls but should be possible via generic style functions. Does this help? |
Thanks very much for helping me!
I am currently trying to do it manually using the following way: Style>Image/Chart1>Open Image manager>add the image>then imbed per node using bypass. But it is not fun at all considering this won't be my last version.
I looked through the customize options. But there seems no such an option?
Thanks, |
I see ... thanks. The visual property that you'd need to set would be NODE_CUSTOMGRAPHICS_1, and the value would be something like: file:/C:/Users/CyDeveloper/Desktop/New%20Bitmap%20Image.jpg,bitmap image Not so obvious. So, to nail this down, I'll pose the question to the developers to see exactly what value should be set. (optional question) I think I can set chart type as a bypass in the Cytoscape GUI. I first select the node, then I use the Style tab to click Bypass for the Image/Chart 1 property, and then choose the Charts tab and then configure the chart. It seems like the followon question would be how to set the bypass via py4cytoscape by using a call something like set_node_custom_bar_chart() ... is that what you're thinking? |
/### NODE_CUSTOMGRAPHICS_1
Thanks, that is exactly I am trying to find. I am also reading the automation>command API: Based on the node list properties:
I actually don't see Okay I found it by get_visual_property_names
Thanks very much for it! This will save my life! NODE_CUSTOMGRAPHICS_# help me set the size
But if there is a way I can just set size based on the original size then it will be great! But it helps already. set_node_custom_bar_chart_by_pass ?
Exactly this is what I am wondering. lol Thanks again! Best, |
OK ... custom graphics (as either graphs or static images) are an odd thing in Cytoscape. Clearly, this all works in the GUI. But getting defaults and bypasses working in CyREST/py4cytoscape/RCy3 is another matter. I have submitted questions, but there aren't any immediate answers. I'm also having trouble getting them to work myself from either Swagger or py4cytoscape. I think we have to wait until the developers can engage this, and even then, with no certain result. Sorry not to have more definite information. |
Hi -- I have answers regarding static images ... In Cytoscape, a static image must be registered in the ImageManager before it can be used in a NODE_CUSTOMGRAPHICS_1 style. Unfortunately, there aren't any REST calls that allow access to the ImageManager, so calls would need to be added. I'm happy to request new calls, and they may be feasible. Supposing I were to do that, can you give me any idea of how many unique images would suit your application? I suspect that there are some ImageManager assumptions about the count of images in existing Cytoscape, supposing that they'll be entered via the GUI and would naturally be limited to only a few. Good to know these requirements and limits ahead of time. The functions I would ask for would be Add, Delete, List, and Clear. As for your question about a Pythonic way of loading tables, I think you must be asking about load_table_data_from_file(). You raise a decent point. I think you might get that functionality by using load_table_data() after loading a dataframe from a JSON file. No?? See here. |
Hi Barry, Thanks very much for replying back to me. Yes, if I can do python call to image for nodes that will be great. Then at least I don't need to do bypass to put new graph in each node. I think there might be at least 20 images I need to imbed. So far, they work manually. Thus, I am not aware of the limits of images allowed in GUI. But, I think this will be something very interesting to use in long run (e.g., some metabolic flux figures, which will be much better if I can imbed bar charts in the flux (e.g., TCA) that I generated externally. And thanks for the answer regarding Thanks, |
I may misunderstand what you just told me: I understands that there might be a missing call to import external figures to ImageManager. But do you mean that if I already have the figures in the ImageManager, there is already REST call to load figure to a specific node? If so, please let me know as assigning figures to nodes is basically the rate-limiting step for my process. Thanks, |
Hi Barry, How is this feature going now? Just want to check in if there are updates. Best, |
Hi, Minghao Gong -- This is a difficult issue, and I haven't gotten a good answer from the developers yet. For the sake of keeping track of information, suppose that there is an image loaded into the ImageManager (regardless of how it was loaded, which is another story). Setting the image for a node (e.g., 2301863) would be done by a call that looks like this: p4c.set_node_property_bypass(2301863, "org.cytoscape.ding.customgraphics.bitmap.URLImageCustomGraphics,32,file:/C:/Users/CyDeveloper/CytoscapeConfiguration/3/karaf_data/tmp/32.png,bitmap image", 'NODE_CUSTOMGRAPHICS_1') It's unclear how the "32" and the "32.png" figure into this. And it's unclear how the image gets loaded into ImageManager. That's what I'm tracking down. Stay tuned ... |
Hi, In case the following is helpful for anyone. Here's a function I use to add png's per node.: import pandas as pd
import py4cytoscape as p4c
def add_custom_png(network, create_png, style=None):
'''
network : int
Cytoscape suid, where to apply the layout
create_png: function
function that creates a png per node and returns png file path
'''
nodes = p4c.get_all_nodes(network=network)
node_pngs = {}
for node in nodes:
node_png_fname = create_png(node)
if node_png_fname:
node_pngs[node] = {'fig_location':f"file:{str(node_png_fname.absolute())}"}
table = pd.DataFrame.from_dict(node_pngs, orient='index')
if style is None:
style = p4c.styles.get_current_style(network=network)
p4c.load_table_data(table, network=network)
p4c.style_dependencies.sync_node_custom_graphics_size(False, style_name=style)
style_mapping = p4c.style_mappings.map_visual_property(
visual_prop="NODE_CUSTOMGRAPHICS_1",
table_column="fig_location",
mapping_type="p",
)
p4c.style_mappings.update_style_mapping(style, style_mapping) For example here: skm-tools/case-study-2-CKN-network-analysis.ipynb (very last section), I create heatmaps for each node and load it next the node. The style (e.g. png size and location relative to the node) is specific to my use-case, but it's easily adjusted. |
that is wonderful. Could it be vector-based fight like avg?
Thanks,
Minghao
…On Sat, Apr 6, 2024 at 5:52 PM Carissa Bleker ***@***.***> wrote:
Hi,
In case the following is helpful for anyone. Here's a function I use to
add png's per node.:
https://github.com/NIB-SI/skm-tools/blob/d29f104e03f88fb38737e924e3a430c68e848963/skm_tools/cytoscape_utils.py#L366C1-L396C1
import pandas as pdimport py4cytoscape as p4c
def add_custom_png(network, create_png, style=None):
''' network : int Cytoscape suid, where to apply the layout create_png: function function that creates a png per node and returns png file path '''
nodes = p4c.get_all_nodes(network=network)
node_pngs = {}
for node in nodes:
node_png_fname = create_png(node)
if node_png_fname:
node_pngs[node] = {'fig_location':f"file:{str(node_png_fname.absolute())}"}
table = pd.DataFrame.from_dict(node_pngs, orient='index')
if style is None:
style = p4c.styles.get_current_style(network=network)
p4c.load_table_data(table, network=network)
p4c.style_dependencies.sync_node_custom_graphics_size(False, style_name=style)
style_mapping = p4c.style_mappings.map_visual_property(
visual_prop="NODE_CUSTOMGRAPHICS_1",
table_column="fig_location",
mapping_type="p",
)
p4c.style_mappings.update_style_mapping(style, style_mapping)
For example here: skm-tools/case-study-2-CKN-network-analysis.ipynb
<https://github.com/NIB-SI/skm-tools/blob/main/publication/case-study-2/case-study-2-CKN-network-analysis.ipynb>
(very last section), I create heatmaps for each node and load it next the
node.
image.png (view on web)
<https://github.com/cytoscape/py4cytoscape/assets/26261557/b849c436-4cdf-490a-b915-974934e26390>
The style (e.g. png size and location relative to the node) is specific to
my use-case, but it's easily adjusted.
—
Reply to this email directly, view it on GitHub
<#120 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADDBUIOBAWL36GK2ZX3ZA2TY4BVDBAVCNFSM6AAAAAA5B4UBOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGIYTINRTGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I haven't tried it, but that should be possible, since Cytoscape does support SVG images as annotations. |
Very nice work! |
Hey @bdemchak
Any easy and quick way to embed image automatically by providing path in local directory?
Thanks,
Minghao Gong
The text was updated successfully, but these errors were encountered: