creation of a dataframe in for cycle

Hi, I need help about the creation of a dataframe where for every for cycle I have to add a new column in dataframe with the new values.

Here's the content of the network (called rf.txt in the code)

targets	,	factors
BDNF,           BDNF
SEM3A,          SEM3A
TALIN,          BDNF
VINCULIN,       BDNF
ALFAACTININ,    BDNF
FAK	,	TALIN 
DOCK180	,	FAK
GRAF	,	FAK
CDC42	,	DOCK180
RAC1	,	DOCK180 | PIX
PAK2_3	,	CDC42 | RAC1
PIX	,	PAK2_3
GIT	,	PIX
PXN	,BDNF &!GIT
RHOA	,	SEM3A &! GRAF
NWASP	,	CDC42
WAVE	,	RAC1
SSH	,	RAC1
ROCK	,	RHOA
MLCK    , MLCK   &!PAK2_3
MLCP, MLCP &! ROCK
MLC_P	,	ROCK | MLCK &!MLCP
LIMK	,	PAK2_3
ADFCOFILIN ,SSH &!LIMK
ARP2_3	,	NWASP | WAVE
RF	,	MLC_P | ADFCOFILIN
PROTR	,	ARP2_3 &! RF

This is the code:


library(BoolNet)
setwd("C:/Users/eleme/OneDrive/Desktop/tesi")
a=loadNetwork("rf.txt")
#print(a)
list= generateState(a,specs=c("BDNF"=1,"SEM3A"=1))
#attr= getAttractors(a,type="synchronous",method = "chosen",startStates = list(list))
#print(attr)
#plot=plotAttractors(attr,title="PLOT EXHAUSTIVE SYNCHRONOUS BDNF ON",mode="table",allInOnePlot = T)


control = 0
inprob= c(0,0,0.04,0.04,0.04,0.04,
          0.04,0.04,0.04,0.04,0.04,0.04,
          0.04,0.04,0.04,0.04,0.04,0.04,
          0.04,0.04,0.04,0.04,0.04,0.04,
          0.04,0.04,0.04)

for (i in 1:10000) {
  if (i==1){
    stat1= stateTransition(a,list,type="asynchronous",
                           geneProbabilities = inprob)
    stat1=data.frame(stat1)
  }
  
  if (i!= 1){
    last_stat= stat1$stat1
    
    stat1= stateTransition(a,last_stat,type="asynchronous",
                                     geneProbabilities = inprob)
    stat1=data.frame(stat1)
   
    if (identical(stat1$stat1,last_stat)){
      control= control +1
      
    }
    else{
      control=0
    }
    
  }

  if (control==40){
    break
  }
 # print("ok")
  
  new= cbind(stat1,last_stat)
  write.table(new,file="new.csv",sep=";", append= TRUE )
  
  }

The first block of code does nothing helpful here because it does not expose the data being used. a reprex. See the FAQ. So the problem can only be addressed generically.

As I understand the problem, it is to begin with a vector of values, x, and then derive through some function f a new vector, y, which will be recycled as x to f to derive a new vector y with the goal of making a data .frame object d with columns composed of x_1 \dots x_{10000}.

  1. Write f for the case of one vector
  2. Create a receiver object d of dimensions equal to the planned result, with the first column consisting of x_1 and the remaining columns set to NA.
  3. Find a function f' to apply f successively to populate d

Candidates for f' are the apply family, it's {purrr} implementations which may or may not seem more user-friendly, and for1. It might call f recursively. One possible form for f` is

sapply(2:1e4,f)
1 Like

@technocrat , thanks for your answer. I haven't a good knowledge of R programming , I think I have to do this in easier way for my thesis in Biotechnology . The only thing I need to know is how to tell the program to do another column for every stat1 values ( I don't know which values and how much stat1 the for cycle creates).
The output at the moment is a simple column with many stat1 as shown in the figure attached.

The screenshot appears to be a spreadsheet screenshot with a single column of character strings. This needs to be exported as a csv file for remediation before proceeding or importing directly using one of the libraries that can read whatever format the spreadsheet is. Once that is accomplished, use

dput(your_object)

and copy/paste the output into this thread. (A screenshot is useless for this purpose.)

Then we can discuss splitting out the real data from the strings.

1 Like
 dput(stat1)
structure(list(stat1 = c(1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), class = "data.frame", row.names = c("BDNF", 
"SEM3A", "TALIN", "VINCULIN", "ALFAACTININ", "FAK", "DOCK180", 
"GRAF", "CDC42", "RAC1", "PAK2_3", "PIX", "GIT", "PXN", "RHOA", 
"NWASP", "WAVE", "SSH", "ROCK", "MLCK", "MLCP", "MLC_P", "LIMK", 
"ADFCOFILIN", "ARP2_3", "RF", "PROTR"))`

OK, thanks.

What this produces is a data frame with one column typeof numeric, but let's back up.

[quote="eleme96, post:1, topic:157384"]

a=loadNetwork("rf.txt")

[/quote]'

What a should look like but with your data from rf.txt

> print(net)
Boolean network with 4 genes

Involved genes:
Gene1 Gene2 Gene3 Gene4

Transition functions:
Gene1 = !Gene2 | !Gene3
Gene2 = Gene3 & Gene4
Gene3 = Gene2 & !Gene1
Gene4 = 1> print(net)
Boolean network with 4 genes

Involved genes:
Gene1 Gene2 Gene3 Gene4

Transition functions:
Gene1 = !Gene2 | !Gene3
Gene2 = Gene3 & Gene4
Gene3 = Gene2 & !Gene1
Gene4 = 1

Knocked-out and over-expressed genes:
Gene4 = 1
Knocked-out and over-expressed genes:
Gene4 = 1

Avoid naming objects with names like list which are built-in functions. What generateState returns looks like is your d put as a named vector

      BDNF       SEM3A       TALIN    VINCULIN ALFAACTININ 
          1           1           0           1           0 
        FAK     DOCK180        GRAF       CDC42        RAC1 
          0           0           0           0           0 
     PAK2_3         PIX         GIT         PXN        RHOA 
          0           0           0           0           0 
      NWASP        WAVE         SSH        ROCK        MLCK 
          0           0           0           0           0 
       MLCP       MLC_P        LIMK  ADFCOFILIN      ARP2_3 
          0           0           0           0           0 
         RF       PROTR 
          0           0 

But when we get here

we're stuck again for lack of the original

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.