Re: [R] Merge the data from multiple text files

2019-01-07 Thread Priya Arasu via R-help
Thank you David Winsemius and David L Carlson. 
@David L Carlson, Thank you for the code. I have one more issue, while merging 
the files. Please advice.For example
In text file 1:
A = not(B or C)B = A and CC = D
In text file 2:
A = not(C or D) and (D and E)

So when I merge using your code, it merges A = not(B or C) and (D and E). How 
do I merge A as A= not(B or C or D) and (D and E) ?  I also have duplicates 
like A= not(B or C) and not (C or D) instead as A= not(B or C or D) ThanksPriya 

On Sunday, 6 January 2019 4:39 AM, David L Carlson  
wrote:
 

 To expand on David W's answer, here is an approach to your example. If you 
have many text files, you would want to process them together rather than 
individually. You gave us two examples so I'll use those and read them from the 
console using readLines(), but you would use the same function to open the 
files on your computer:

> TF1 <- readLines(n=3)
A = not(B or C)
B = A and C
C = D
> 
> TF2 <- readLines(n=2)
A = D and E
B = not(D)
> 
> TF <- sort(c(TF1, TF2))
> TF
[1] "A = D and E"    "A = not(B or C)" "B = A and C"    "B = not(D)"
[5] "C = D"

Now we have combined the files into a single character vector called TF and 
sorted them. Next we need to parse them into the left and right hand sides. We 
will replace " = " with "\t" (tab) to do that:

> TF.delim <- gsub(" = ", "\t", TF)
> TF.data <- read.delim(text=TF.delim, header=FALSE, as.is=TRUE)
> colnames(TF.data) <- c("LHS", "RHS")
> print(TF.data, right=FALSE)
  LHS RHS
1 A  D and E
2 A  not(B or C)
3 B  A and C
4 B  not(D)
5 C  D

TF.data is a data frame with two columns. The tricky part is to add surrounding 
parentheses to rows 1 and 3 to get your example output:

> paren1 <- grepl("and", TF.data$RHS)
> paren2 <- !grepl("\\(*\\)", TF.data$RHS)
> paren <- apply(cbind(paren1, paren2), 1, all)
> TF.data$RHS[paren] <- paste0("(", TF.data$RHS[paren], ")")
> print(TF.data, right=FALSE)
  LHS RHS
1 A  (D and E)
2 A  not(B or C)
3 B  (A and C)
4 B  not(D)
5 C  D

The first three lines identify the rows that have the word "and" but do not 
already have parentheses. The fourth line adds the surrounding parentheses. 
Finally we will combine the rows that belong to the same LHS value with split 
and create a list:

> TF.list <- split(TF.data$RHS, TF.data$LHS)
> TF.list
$`A`
[1] "(D and E)"  "not(B or C)"

$B
[1] "(A and C)" "not(D)"  

$C
[1] "D"

> TF.and <- lapply(TF.list, paste, collapse=" and ")
> TF.final <- lapply(names(TF.and), function(x) paste(x, "=", TF.and[[x]]))
> TF.final <- do.call(rbind, TF.final)
> TF.final
    [,1]                          
[1,] "A = (D and E) and not(B or C)"
[2,] "B = (A and C) and not(D)"
[3,] "C = D"
> write(TF.final, file="TF.output.txt")

The text file "TF.output.txt" contains the three lines.

--
David L. Carlson
Department of Anthropology
Texas A&M University

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius
Sent: Saturday, January 5, 2019 1:12 PM

Subject: Re: [R] Merge the data from multiple text files


On 1/5/19 7:28 AM, Priya Arasu via R-help wrote:
> I have multiple text files, where each file has Boolean rules.
> Example of my text file 1 and 2
> Text file 1:
> A = not(B or C)
> B = A and C
> C = D
> Text file 2:
> A = D and E
> B = not(D)
>
> I want to merge the contents in text file as follows
> A = not(B or C) and (D and E)
> B = not(D) and (A and C)
> C = D
> Is there a code in R to merge the data from multiple text files?


There is a `merge` function. For this use case you would need to first 
parse your expressions so that the LHS was in one character column and 
the RHS was in another character column in each of 2 dataframes. Then 
merge on the LHS columns and `paste` matching values from the two 
columns. You will probably need to learn how to use `ifelse` and `is.na`.

> Thank you
> Priya
>
>     [[alternative HTML version deleted]]


You also need to learn that R is a plain text mailing list and that each 
mail client has its own method for building mail in plain text.


-- 

David.

>
> __
> 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.

__
R-help@r-project.org mailing lis

[R] Merge the data from multiple text files

2019-01-05 Thread Priya Arasu via R-help
I have multiple text files, where each file has Boolean rules.
Example of my text file 1 and 2
Text file 1:
A = not(B or C)
B = A and C
C = D
Text file 2:
A = D and E
B = not(D)

I want to merge the contents in text file as follows
A = not(B or C) and (D and E)
B = not(D) and (A and C)
C = D
Is there a code in R to merge the data from multiple text files?
Thank you
Priya 

[[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] Function to save results

2017-11-01 Thread Priya Arasu via R-help
Hi David,Thank you for the example.When I try to use the cat function, I get an 
error

cat(attr<-getAttractors(net, type="asynchronous"))Error in cat(attr <- 
getAttractors(net, type = "asynchronous")) : 
  argument 1 (type 'pairlist') cannot be handled by 'cat'

Please let me know, if I have used the function in right way?. 
Thank you
Priya






 
 

On Wednesday, 1 November 2017 9:32 PM, David L Carlson  
wrote:
 

 Let's try a simple example. 

> # Create a script file of commands
> # Note we must print the results of quantile explicitly
> cat("x <- rnorm(50)\nprint(quantile(x))\nstem(x)\n", file="Test.R")
> 
> # Test it by running it to the console
> source("Test.R")
        0%        25%        50%        75%      100% 
-2.4736219 -0.7915433 -0.1178056  0.7023577  2.9158617 

  The decimal point is at the |

  -2 | 510
  -1 | 7631110
  -0 | 998877733211
  0 | 011244889
  1 | 00045
  2 | 19

> 
> # Now run it and save the file
> sink("Testout.txt")
> source("Test.R")
> sink()
> 
> # What is located in "Testout.txt"?
> cat(readLines("Testout.txt"), sep="\n")
        0%        25%        50%        75%        100% 
-2.47511893 -0.47919111  0.05761628  0.67403447  1.79825459 

  The decimal point is at the |

  -2 | 5
  -2 | 4
  -1 | 
  -1 | 432000
  -0 | 87755
  -0 | 442110
  0 | 001244
  0 | 556789
  1 | 113
  1 | 5788

> # Success

Depending on your operating system, you may also be able to save the output 
with File | Save to File.

---
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Priya Arasu via 
R-help
Sent: Wednesday, November 1, 2017 9:57 AM
To: Eric Berger 
Cc: r-help@r-project.org
Subject: Re: [R] Function to save results

Hi Eric,Thanks for the explanation. Is there a way to save the results 
automatically after the analysis gets over?. As I recently lost the results, 
because I didn't save the results. I don't want to run the sink or save command 
after the analysis is over rather run the command for saving the file before 
starting to run the analysis, so the file gets saved automatically after the 
script has finished running Priya
 


    On Wednesday, 1 November 2017 7:53 PM, Eric Berger  
wrote:


 Hi Priya,
You did not follow the logic of the pseudo-code. The sink("filename"), sink() 
pair captures whatever output is generated between the first sink statement and 
the second sink statement.You need (possibly) to do:
sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//attr. txt") net <- loadNetwork("C://Users//Priya/ 
/Desktop//Attractor analysis_all genes//synaptogenesis// regulationof_dopamine_ 
signaling_submodule3.txt")attr <- getAttractors(net, type="asynchronous")
sink()
HTH,Eric


 


Hi Eric,I tried as you suggested but I could not find the output in the text 
file I created (attr.txt)

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ 
signaling_submodule3.txt")sink("C://Users//Priya// Desktop//Attractor 
analysis_all genes//synaptogenesis//attr. txt")


sink()

attr <- getAttractors(net, type="asynchronous")
 Priya


    On Wednesday, 1 November 2017 6:54 PM, Eric Berger  
wrote:


 Some comments:1. sink() does not return a value. There is on point to set attr 
<- sink(...). Just give the command sink("C://etc")2. to complete the 
saving to the file you must give a second sink command with no argument:  
sink()So your code would be (pseudo-code, not actual code) sink( "filename" )do 
something that prints output which will be captured by sinksink() HTH,Eric


On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help  
wrote:

Hi,I want the results to be saved automatically in a output text file after the 
script has finished running.

I used the sink function in the following example, but the results file 
(output.txt) was empty.

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")# 
First I loaded theinput file for which I want to identify attractors attr <- 
sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//output. txt")# used the sink function to save the 
results from attr function

attr <- getAttractors(net, type="asynchronous")# then ran the script for 
identifying attractors Is there any function to save the results before setting 
the script to run, so that results are automatically saved in a text file after 
the s

Re: [R] Function to save results

2017-11-01 Thread Priya Arasu via R-help
Hi Eric,Thanks for the explanation. Is there a way to save the results 
automatically after the analysis gets over?. As I recently lost the results, 
because I didn't save the results. I don't want to run the sink or save command 
after the analysis is over rather run the command for saving the file before 
starting to run the analysis, so the file gets saved automatically after the 
script has finished running
Priya
 


On Wednesday, 1 November 2017 7:53 PM, Eric Berger  
wrote:
 

 Hi Priya,
You did not follow the logic of the pseudo-code. The sink("filename"), sink() 
pair captures whatever output is generated between the first sink statement and 
the second sink statement.You need (possibly) to do:
sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//attr. txt")
net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")attr 
<- getAttractors(net, type="asynchronous")
sink()
HTH,Eric


 
On Wed, Nov 1, 2017 at 4:10 PM, Priya Arasu  wrote:

Hi Eric,I tried as you suggested but I could not find the output in the text 
file I created (attr.txt)

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ 
signaling_submodule3.txt")sink("C://Users//Priya// Desktop//Attractor 
analysis_all genes//synaptogenesis//attr. txt")


sink()

attr <- getAttractors(net, type="asynchronous")
 Priya
 

On Wednesday, 1 November 2017 6:54 PM, Eric Berger  
wrote:
 

 Some comments:1. sink() does not return a value. There is on point to set attr 
<- sink(...). Just give the command sink("C://etc")2. to complete the 
saving to the file you must give a second sink command with no argument:  
sink()So your code would be (pseudo-code, not actual code)
sink( "filename" )do something that prints output which will be captured by 
sinksink()
HTH,Eric


On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help  
wrote:

Hi,I want the results to be saved automatically in a output text file after the 
script has finished running.

I used the sink function in the following example, but the results file 
(output.txt) was empty.

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")# 
First I loaded theinput file for which I want to identify attractors
attr <- sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//output. txt")# used the sink function to save the 
results from attr function

attr <- getAttractors(net, type="asynchronous")# then ran the script for 
identifying attractors
Is there any function to save the results before setting the script to run, so 
that results are automatically saved in a text file after the script has 
finished running?

Thank youPriya



        [[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.




   



   
[[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] Function to save results

2017-11-01 Thread Priya Arasu via R-help
Hi Eric,I tried as you suggested but I could not find the output in the text 
file I created (attr.txt)

net <- loadNetwork("C://Users//Priya//Desktop//Attractor analysis_all 
genes//synaptogenesis//regulationof_dopamine_signaling_submodule3.txt")sink("C://Users//Priya//Desktop//Attractor
 analysis_all genes//synaptogenesis//attr.txt")


sink()

attr <- getAttractors(net, type="asynchronous")
 Priya
 

On Wednesday, 1 November 2017 6:54 PM, Eric Berger  
wrote:
 

 Some comments:1. sink() does not return a value. There is on point to set attr 
<- sink(...). Just give the command sink("C://etc")2. to complete the 
saving to the file you must give a second sink command with no argument:  
sink()So your code would be (pseudo-code, not actual code)
sink( "filename" )do something that prints output which will be captured by 
sinksink()
HTH,Eric


On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help  
wrote:

Hi,I want the results to be saved automatically in a output text file after the 
script has finished running.

I used the sink function in the following example, but the results file 
(output.txt) was empty.

net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all 
genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")# 
First I loaded theinput file for which I want to identify attractors
attr <- sink("C://Users//Priya// Desktop//Attractor analysis_all 
genes//synaptogenesis//output. txt")# used the sink function to save the 
results from attr function

attr <- getAttractors(net, type="asynchronous")# then ran the script for 
identifying attractors
Is there any function to save the results before setting the script to run, so 
that results are automatically saved in a text file after the script has 
finished running?

Thank youPriya



        [[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.




   
[[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.

[R] Function to save results

2017-11-01 Thread Priya Arasu via R-help
Hi,I want the results to be saved automatically in a output text file after the 
script has finished running.

I used the sink function in the following example, but the results file 
(output.txt) was empty.

net <- loadNetwork("C://Users//Priya//Desktop//Attractor analysis_all 
genes//synaptogenesis//regulationof_dopamine_signaling_submodule3.txt")# First 
I loaded theinput file for which I want to identify attractors
attr <- sink("C://Users//Priya//Desktop//Attractor analysis_all 
genes//synaptogenesis//output.txt")# used the sink function to save the results 
from attr function

attr <- getAttractors(net, type="asynchronous")# then ran the script for 
identifying attractors
Is there any function to save the results before setting the script to run, so 
that results are automatically saved in a text file after the script has 
finished running?

Thank youPriya



[[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.


[R] Help-Text file

2016-11-05 Thread Priya Arasu via R-help
Hi, 
 I am using R 3.3.1 in R studio version 1.0.44 (Windows10, 64 bit system). 
I could import text file with Boolean rules, but when I start doing analysis in 
R, I get the error: I have been trying to do attractor analysis using R package 
Boolnet, using the command: attr <- getAttractors(net, type="asynchronous"). 
This command throws up the below error:

Error in matrix(nrow = n, ncol = length(network$genes)) : 
  invalid 'nrow' value (too large or NA)
In addition: Warning message:
In matrix(nrow = n, ncol = length(network$genes)) :
  NAs introduced by coercion to integer range


 Have anyone come across this error?. I have attached the text file with 
Boolean rules. Pls find it. Any suggestions or ideas, would be of great help
Thank you
Priya
















Targets, factors
DISC1, (!miR124 & !let7b & !let7a & !let7d) | (PCM1 & BBS4) | (MITF | GATA1 | 
TAL1 | EZH2 | AR | TCF3 | HNF4A | RUNX1)
MITF, (MITF)
GATA1, (GATA1)
TAL1, (!miR377) | (TAL1)
EZH2, (!miR124) | (EZH2)
AR, (!miR124) | (AR)
TCF3, (!miR124) | (TCF3)
miR124, (EGR1)
miR377, (miR377)
let7b, (let7b)
let7a, (let7a)
let7d, (let7d)
PCM1, (! miR33a) | (DISC1 & BBS4) | (EGR1 | SALL4 | POU3F2 | THAP11 | HCFC1 | 
ZFP281 | WT1 | SOX2 | CUX1 | SIN3B | KDM5B | HOXB4 | ELK1 | TCF3 | FLI1 | HNF4A 
| RUNX1 | MITF)
miR33a, (miR33a)
EGR1, (! miR124) | (EGR1)
SALL4, (SALL4)
POU3F2, (POU3F2)
THAP11, (THAP11)
HCFC1, (HCFC1)
ZFP281, (ZFP281)
WT1, (WT1)
SOX2, (SOX2)
CUX1, (CUX1)
SIN3B, (SIN3B)
KDM5B, (KDM5B)
HOXB4, (HOXB4)
ELK1, (ELK1)
FLI1, (FLI1)
HNF4A, (HNF4A)
RUNX1, (RUNX1)
BBS4, (! miR432 & ! miR382 & ! miR127 & ! miR377) | (DISC1 & PCM1) | (E2F1 | 
GATA1 | FLI1 | MITF | ELK1 | CUX1 | KDM5B | SIN3B) | GABP | EOMES | TFAP2A)
miR432, (miR432)
miR382, (miR382)
miR127, (miR127)
E2F1, (! let7a) | (E2F1)
TFAP2A, (TFAP2A)
EOMES, (EOMES)
GABP, (GABP)






__
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.

[R] Stop R script from running, when the memory goes beyond 15.4GB

2016-11-05 Thread Priya Arasu via R-help
Hi, 
 I am using R 3.3.1 in RedHat Linux7 , 64bit system (16GB RAM).  I could 
run simulation in R package, Boolnet for 25 genes without any problem. When I 
add more gene i.e. 26 genes, the system becomes slow. Simulation keeps running 
for more than a day. I have to stop the simulation, as it takes a lot of 
memory. I need a suggestion here, I want to stop the script from running when 
the script takes memory beyond 15.4 GB. How do I do it? Should I generate 
warning in my script or use typeCatch?
Any idea or advice, would be of great help
Thank you
Priya


 

[[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.