[R] extract objects from R output

2014-12-14 Thread Kruti Pandya
I am new to R and using this package BoolNet. I wanted to extract the
boolean transition functions resulting from the output of
generateRandomNKNetwork function. I am able to extract individual function
using
net$interactions$Gene1$expression,net$interactions$Gene2$expression .
But it gives me the transition function in quotes. How can I remove the
quotes ?

My goal is to  evaluate each transition function at a randomly generated
initial state. What I need to do is to extract each of the individual
functions one by one. Like

extract net$interactions$Gene1$expression
evaluate the function at random initial sate
then extract net$interactions$Gene2$expression
evaluate the function at random initial state

 do this for all five functions that comes out of the ouput.

I tried something like this but did not work.

for (i in 1:5){
  func[[i]]-rn$interactions$Gene[i]$expression

#extract net$interactions$Gene1$expression,
net$interactions$Gene2$expression and so on

}


# output of generateRandomNKNetwork
install.packages(BoolNet)
  library(BoolNet)

  net-generateRandomNKNetwork(5,3,readableFunctions=canonical)

#Output of net
Boolean network with 5 genes

Involved genes:
Gene1 Gene2 Gene3 Gene4 Gene5

Transition functions:
Gene1 = (!Gene5  Gene1  !Gene2) | (!Gene5  Gene1  Gene2) | (Gene5 
!Gene1  !Gene2)
Gene2 = (!Gene1  !Gene3  !Gene2) | (!Gene1  Gene3  !Gene2) | (!Gene1 
Gene3  Gene2) | (Gene1  Gene3  Gene2)
Gene3 = (!Gene3  Gene1  !Gene2) | (Gene3  !Gene1  !Gene2) | (Gene3 
Gene1  !Gene2)
Gene4 = (!Gene4  !Gene2  !Gene1) | (!Gene4  !Gene2  Gene1) | (!Gene4 
Gene2  Gene1) | (Gene4  !Gene2  !Gene1) | (Gene4  Gene2  Gene1)
Gene5 = (!Gene2  !Gene4  !Gene5) | (!Gene2  !Gene4  Gene5) | (Gene2 
!Gene4  Gene5)

net$interactions$Gene1$expression
#[1] (!Gene5  Gene1  !Gene2) | (!Gene5  Gene1  Gene2) | (Gene5 
!Gene1  !Gene2)

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extract objects from R output

2014-12-14 Thread David Winsemius
PLEASE DO NOT POST IN HTML:


 On Dec 14, 2014, at 12:30 PM, Kruti Pandya kp1...@gmail.com wrote:
 
 I am new to R and using this package BoolNet. I wanted to extract the
 boolean transition functions resulting from the output of
 generateRandomNKNetwork function. I am able to extract individual function
 using
 net$interactions$Gene1$expression,net$interactions$Gene2$expression .
 But it gives me the transition function in quotes. How can I remove the
 quotes ?
 
 My goal is to  evaluate each transition function at a randomly generated
 initial state. What I need to do is to extract each of the individual
 functions one by one. Like
 
 extract net$interactions$Gene1$expression
 evaluate the function at random initial sate
 then extract net$interactions$Gene2$expression
 evaluate the function at random initial state
 
  do this for all five functions that comes out of the ouput.
 
 I tried something like this but did not work.
 
 for (i in 1:5){
  func[[i]]-rn$interactions$Gene[i]$expression
 
 #extract net$interactions$Gene1$expression,
 net$interactions$Gene2$expression and so on
 
 }

So look at the object:

 str(net)
List of 3
 $ genes   : chr [1:5] Gene1 Gene2 Gene3 Gene4 ...
 $ interactions:List of 5
  ..$ Gene1:List of 3
  .. ..$ input : int [1:3] 5 4 3


 names(net$interactions)
[1] Gene1 Gene2 Gene3 Gene4 Gene5

There are not five items names named “Gene” with indices 1 to 5. You can get at 
items with those names by paste0()-ing with “[[“


#There is nothing named “fun” yet:


OR FOR THAT  MATTER…. an object name “rn”. Why on earth did you change the name 
to 'rn' from ‘net'?


 func=list()
 for (i in 1:5){
  func[[i]]-net$interactions[[paste0(Gene,i)]]$expression
 }

 str(func)
List of 5
 $ : chr (!Gene5  !Gene4  !Gene3) | (!Gene5  !Gene4  Gene3) | (Gene5  
!Gene4  Gene3) | (Gene5  Gene4  Gene3)
 $ : chr (!Gene1  Gene2  !Gene3) | (!Gene1  Gene2  Gene3) | (Gene1  
!Gene2  !Gene3) | (Gene1  !Gene2  Gene3) | (Gene1  Gene2  | __truncated__
 $ : chr (!Gene4  !Gene2  Gene5) | (Gene4  Gene2  !Gene5) | (Gene4  Gene2 
 Gene5)
 $ : chr (!Gene1  !Gene2  Gene5) | (!Gene1  Gene2  Gene5) | (Gene1  
!Gene2  Gene5) | (Gene1  Gene2  !Gene5)
 $ : chr (!Gene5  !Gene1  !Gene4) | (!Gene5  Gene1  !Gene4) | (!Gene5  
Gene1  Gene4) | (Gene5  !Gene1  !Gene4) | (Gene5  !Gene1| __truncated__


David.

 
 # output of generateRandomNKNetwork
 install.packages(BoolNet)
  library(BoolNet)
 
  net-generateRandomNKNetwork(5,3,readableFunctions=canonical)
 
 #Output of net
 Boolean network with 5 genes
 
 Involved genes:
 Gene1 Gene2 Gene3 Gene4 Gene5
 
 Transition functions:
 Gene1 = (!Gene5  Gene1  !Gene2) | (!Gene5  Gene1  Gene2) | (Gene5 
 !Gene1  !Gene2)
 Gene2 = (!Gene1  !Gene3  !Gene2) | (!Gene1  Gene3  !Gene2) | (!Gene1 
 Gene3  Gene2) | (Gene1  Gene3  Gene2)
 Gene3 = (!Gene3  Gene1  !Gene2) | (Gene3  !Gene1  !Gene2) | (Gene3 
 Gene1  !Gene2)
 Gene4 = (!Gene4  !Gene2  !Gene1) | (!Gene4  !Gene2  Gene1) | (!Gene4 
 Gene2  Gene1) | (Gene4  !Gene2  !Gene1) | (Gene4  Gene2  Gene1)
 Gene5 = (!Gene2  !Gene4  !Gene5) | (!Gene2  !Gene4  Gene5) | (Gene2 
 !Gene4  Gene5)
 
 net$interactions$Gene1$expression
 #[1] (!Gene5  Gene1  !Gene2) | (!Gene5  Gene1  Gene2) | (Gene5 
 !Gene1  !Gene2)
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.