3D and jpeg/pdf export

12 views
Skip to first unread message

Grimes Mark

unread,
Aug 10, 2012, 7:05:10 PM8/10/12
to rcyto...@googlegroups.com
Paul

I have a network with coordinates in three dimensions.  Using RCytoscape it is possible to give the appearance of three dimensions, if the background is set to black (or a dark color) and the edges are not black, using:

setNodePosition (cywindow, as.character(cf$Node.Name), newcoords[,1], newcoords[,2])
scaleop = scale(newcoords[,3], scale=T, center=T)
nodeop = 255*scale((scaleop + abs(min(scaleop))), scale=(max(scaleop) + abs(min(scaleop))), center=FALSE)
setNodeOpacityDirect(cywindow, as.character(cf$Node.Name), nodeop)

Using package 'rgl' it is possible to achieve 3D transformations in an animation, as in the following example.

for (i in 1:15) {
newcoords <- rotate3d(oldcoords, pi/45, 0, 1, 0)
setNodePosition (cywindow, as.character(cf$Node.Name), newcoords[,1], newcoords[,2])
scaleop = scale(newcoords[,3], scale=T, center=T)
nodeop = 255*scale((scaleop + abs(min(scaleop))), scale=(max(scaleop) + abs(min(scaleop))), center=FALSE)
setNodeOpacityDirect(cywindow, as.character(cf$Node.Name), nodeop)
     #fitContent (cywindow)
    #showGraphicsDetails (cywindow, TRUE)
oldcoords=newcoords
Sys.sleep(1)
}

This animation would make a marvelous movie (by importing individual frames) if the ability to save the network as a jpg file is inserted into the above loop.  If you have time and inclination, I would like to request that the following hypothetical command be made available:

exportNetworkView (cywindow, filename, format='jpeg') 

This would also be useful for format='pdf' (or other formats) to make figures for publication, but of course this could be done manually using the Cytoscape GUI.  Manually saving hundreds of such files for a movie, however, is impractical, hence my request.

Thanks and best wishes,

Mark Grimes
University of Montana

Paul Shannon

unread,
Aug 10, 2012, 7:09:44 PM8/10/12
to rcyto...@googlegroups.com, Paul Shannon

Burak Kutlu

unread,
Aug 10, 2012, 7:10:57 PM8/10/12
to rcyto...@googlegroups.com
Hey Paul
How is the rebuttal coming along?
Have a good weekend
-burak

Mark Grimes

unread,
Aug 11, 2012, 9:22:24 AM8/11/12
to rcyto...@googlegroups.com, Paul Shannon
Paul

Yes!

I think I missed this because I was looking for 'export' or 'print' - saveImage is just the thing !

Thanks,

Mark

Grimes Mark

unread,
Aug 13, 2012, 6:40:30 PM8/13/12
to rcyto...@googlegroups.com, Paul Shannon
Paul

The saveImage command works! This is good.

To note: the help file in RCy says only 'jpeg' is supported as image
type, but the R console says
'Error: image.type %in c("png", "pdf", "svg") is not TRUE'

Also: the image is saved to the top-level directory, not the one found
by getwd().

So it works if you use one of the three formats above and the full
path is specified.

Mark


On Aug 10, 2012, at 5:09 PM, Paul Shannon wrote:

Grimes Mark

unread,
Aug 14, 2012, 11:20:21 AM8/14/12
to rcyto...@googlegroups.com, Paul Shannon
Paul and friends,

Here is an example of a movie using the approach below, including in the loop the commands:

filename = paste(noquote("/Users/Path/_"), i, noquote("_Rcy_movie.png"), sep="", collapse=NULL)
  saveImage(nb.edgewin, filename, 'png', 2.0)

It's only a small movie, low resolution, so it can be emailed.  

Another application for RCytoscape!

Best,

Mark
RCyMovie1.mp4

Paul Shannon

unread,
Aug 14, 2012, 11:30:33 AM8/14/12
to rcyto...@googlegroups.com, Grimes Mark, Paul Shannon
HI Mark,

This is very cool!

Could i persuade you to post this to cytoscape-discuss? I've been thinking lately that that is would be a better forum for our occasional emails -- better than rcyot...@google.groups.

- Paul
> On Aug 13, 2012, at 4:40 PM, Grimes Mark wrote:
>
>> Paul
>>
>> The saveImage command works! This is good.
>>
>> To note: the help file in RCy says only 'jpeg' is supported as image type, but the R console says
>> 'Error: image.type %in c("png", "pdf", "svg") is not TRUE'
>>
>> Also: the image is saved to the top-level directory, not the one found by getwd().
>>
>> So it works if you use one of the three formats above and the full path is specified.
>>
>> Mark
>>
>>
>> On Aug 10, 2012, at 5:09 PM, Paul Shannon wrote:
>>
>>> Hi Mark,
>>>
>>> Does saveImage help here?
>>>
>>> http://db.systemsbiology.net:8080/cytoscape/RCytoscape/versions/current/methods/saveImage.html
>>>
>>> - Paul
>>>
>>>
>>> On Aug 10, 2012, at 4:05 PM, Grimes Mark wrote:
>>>
>>>> Paul
>>>>
>>>> I have a network with coordinates in three dimensions. Using RCytoscape it is possible to give the appearance of three dimensions, if the background is set to black (or a dark color) and the edges are not black, using:
>>>>
>>>> setNodePosition (cywindow, as.character(cf$Node.Name), newcoords[,1], newcoords[,2])
>>>> scaleop = scale(newcoords[,3], scale=T, center=T)
>>>> nodeop = 255*scale((scaleop + abs(min(scaleop))), scale=(max(scaleop) + abs(min(scaleop))), center=FALSE)
>>>> setNodeOpacityDirect(cywindow, as.character(cf$Node.Name), nodeop)
>>>>
>>>> Using package 'rgl' it is possible to achieve 3D transformations in an animation, as in the following example.
>>>>
>>>> for (i in 1:15) {
>>>> newcoords <- rotate3d(oldcoords, pi/45, 0, 1, 0)
>>>> setNodePosition (cywindow, as.character(cf$Node.Name), newcoords[,1], newcoords[,2])
>>>> scaleop = scale(newcoords[,3], scale=T, center=T)
>>>> nodeop = 255*scale((scaleop + abs(min(scaleop))), scale=(max(scaleop) + abs(min(scaleop))), center=FALSE)
>>>> setNodeOpacityDirect(cywindow, as.character(cf$Node.Name), nodeop)
>>>> #fitContent (cywindow)
>>>> #showGraphicsDetails (cywindow, TRUE)
>>>> oldcoords=newcoords
>>>> Sys.sleep(1)
>>>> }
>>>>
>>>> This animation would make a marvelous movie (by importing individual frames) if the ability to save the network as a jpg file is inserted into the above loop. If you have time and inclination, I would like to request that the following hypothetical command be made available:
>>>>
>>>> exportNetworkView (cywindow, filename, format='jpeg')
>>>>
>>>> This would also be useful for format='pdf' (or other formats) to make figures for publication, but of course this could be done manually using the Cytoscape GUI. Manually saving hundreds of such files for a movie, however, is impractical, hence my request.
>>>>
>>>> Thanks and best wishes,
>>>>
>>>> Mark Grimes
>>>> University of Montana
>>>
>>
>
> <RCyMovie1.mp4>

Reply all
Reply to author
Forward
0 new messages