Seth,
that's great! It is another piece of the puzzle, and a little more exposure
to the ways that graphs can be handled.

Based on some code by Elliot Kleiman and a suggestion or two from Vince
Carey, I think I've managed to solve my problem.
I admit, it is nowhere near as elegant as the solutions which others have
been suggesting, but that
is merely my "newbie"ness with R/BioC showing.
As you mentioned, the best route here is to go directly to PDF, perhaps
changing some font sizes.
In any case, the code is included below.

Thanks again.

Dan.

GOTermsAndIds <- as.list(GOTERM)
GOIDS=0
GOTERMS=0
# Place them into easily accessible arrays.
for(i in 1:length(GOTermsAndIds)){
    GOIDS[i]=GOID(GOTermsAndIds[[i]])
    GOTERMS[i]=Term(GOTermsAndIds[[i]])
}

 # Babies are the significant terms, whose parents/ancestors we will obtain
to build our
    # induced trees.
    babies=0
    babiesCounter=1

    params <- new("GOHyperGParams", geneIds = test,
    universeGeneIds = bkg,annotation="org.Rn.eg.db",
    conditional = FALSE, categoryName="GO", ontology="BP")

    MyHyperG=hyperGTest(params)

    Summary=summary(MyHyperG)

    # NEL graph object
    gGO <- goDag( MyHyperG )

   # Choose those nodes with significant p-value and add to babies.
    for(i in seq(along=nodes(gGO))) {

        nm <- nodes(gGO)[[i]]

        mn <- match(nm, names(pvalues(MyHyperG)))

        if(!is.na(mn)) {
            if(as.vector(pvalues(MyHyperG))[mn] < MyHyperG@pvalueCutoff){
                babies[babiesCounter]=nodes(gGO)[[i]]
                babiesCounter=babiesCounter+1
            }
        }
    }


      g=GOGraph(x, GOBPPARENTS),

    g=removeNode("all", g)

    # Put root node on the top, transpose adjacency matrix
    g <- as(t(as(g, 'matrix')), 'graphNEL')

    # Graph NEL attributes (node attribute graph object)
    nAgo <- makeNodeAttrs(g, shape="circle", label=nodes(g), fillcolor =
"white" )
    # Ragraph object
    agGO <- agopen(g, recipEdges="distinct", layoutType="dot",
nodeAttrs=nAgo, name="")
    # Get node info from Ragraph object and store as agraph node object
    agNO <- AgNode(agGO)

    # Color nodes below p-value cutoff, and add node labels
    for(i in seq(along=agNO)) {

        nm <- labelText(txtLabel(agNO[[i]]))

        mn <- match(nm, names(pvalues(MyHyperG)))

        # Also find the term in the lists of terms and IDs.
        termMatch=match(nm, GOIDS)

        if(!is.na(mn)) { # match

            # If we're below pvalue, color red, otherwise color white.
            agNO[[i]]@fillcolor <- ifelse( as.vector(pvalues(MyHyperG))[mn]
< MyHyperG@pvalueCutoff, "#e31a1c", "#edf8fb")

            # If we're below the pvalue, we want the number of genes
annotated by the term.
            if(as.vector(pvalues(MyHyperG))[mn] < MyHyperG@pvalueCutoff){

                count=Summary[row.names(Summary)==nm,]$Count

                # Build the label.
                agNO[[i]]@txtLabel@labelText <-  paste(GOTERMS[termMatch],
"\nNo. Genes:", count,sep=" ")

            }

            else{
                # Otherwise we just label with the term name.
                agNO[[i]]@txtLabel@labelText <-GOTERMS[termMatch]
            }
        }
        else { # no match
            agNO[[i]]@fillcolor <- "white"
            agNO[[i]]@txtLabel@labelText <- ""
        }
    }

    # Update Ragraph object's AgNode slot with agNO
    agGO@AgNode <- agNO

    # Plot
    name=paste("~/Desktop/",ontologies[k],fileName,".pdf", sep="")
    pdf(name, width=40, height=40, paper="special", pagecentre=TRUE)
    #fixInNamespace(drawAgNode, "Rgraphviz")
    fixInNamespace(drawTxtLabel, "Rgraphviz")
    plot(agGO)
    dev.off()

On Sat, Sep 13, 2008 at 12:34 PM, Seth Falcon <seth@userprimary.net> wrote:

> * Wolfgang:
> > > AfaIu, plotGOTermGraph wants to work on elements of the list y,
> > > not on y itself. I agree that the documentation in the function's
> > > manual page ("g : A graph object as returned by inducedTermGraph
> > > or termGraphs") would benefit from clarification/correction.
>
> Yes, it should be something like:
>
>       g: A 'graph' object as returned by 'inducedTermGraph' or
>           an element of the list returned by 'termGraphs'.
>
> * On 2008-09-12 at 19:42 -0500 daniel jupiter wrote:
> > I'm really looking to see the following.  The induced graph of all
> > the nodes declared significant, with those nodes in a different
> > color, with counts, and labels that are terms, not IDs.  It seems
> > that you've given me yet another piece of the puzzle.... but they
> > don't all fit together.  I can get many of these things with the
> > various suggestions I've received, I just can't get them all at
> > once.  It may just be that without a lot of work R/BioC can't quite
> > do what I'd like.
>
> Perhaps the following is what you want?
>
>  ## using the same example data as you posted...
>  x = hyperGTest(params)
>  tgs = termGraphs(x,use.terms=TRUE , pvalue=.01)
>
>  ## tgs is a list of graph objects that represent the connected
>  ## components of the subgraph of the tested GO DAG consisting of
>  ## significant nodes.
>
>  g1 = tgs[[1]]
>
>  ## here we add parents and children of a connected graph of
>  ## significant nodes.
>  bigg = inducedTermGraph(x, id=nodes(g1))
>
>  ## as you noted, inducedTermGraph doesn't add GO term labels, so we'll
>  ## add them in the way that plotGOTermGraph is expecting
>
>  # first add a default value for the node attribute named "term"
>  nodeDataDefaults(bigg) <- c(nodeDataDefaults(bigg),
>                              list(term=as.character(NA)))
>
>  # then add the terms
>  theTerms = as.character(sapply(mget(nodes(bigg), GOTERM), Term))
>  nodeData(bigg, attr="term") = theTerms
>
>  # the resulting graph has 38 nodes and I find the plot rather
>  # unsatisfying.  But if you use pdf, you can zoom in.
>
>  pdf("bigg.pdf")
>  plotGOTermGraph(bigg, x, node.shape="ellipse")
>  dev.off()
>
> Perhaps that gives you another piece of your puzzle?  Writing
> functions to visualize arbitrary GO graphs is difficult because once
> the node count grows the resulting plot tends to get difficult to
> read.
>
> + seth
>
> --
> Seth Falcon | http://userprimary.net/user/
>



-- 
Daniel C. Jupiter, Ph.D.
Postdoctoral Research Associate
Department of Systems Biology and Translational Medicine
College of Medicine
Texas A&M Health Science Center
702 SW H.K. Dodgen Loop
Temple, TX 76504

979.997.2106 | Fax 254.742.7145
djupiter@tamu.edu | www.tamhsc.edu

	[[alternative HTML version deleted]]

