How to loop over two files ...

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

How to loop over two files ...

anikaM
Hello,

I have two files (each has 300 lines)like this:

head 1g.txt
rs6792369
rs1414517
rs16857712
rs16857703
rs12239392
...

head 1n.txt
rs1042779
rs2360630
rs10753597
rs7549096
rs2343491
...

For each pair of rs# from those two files I can run this command in R

library(httr)
library(jsonlite)
library(xml2)

server <- "http://rest.ensembl.org"
ext <- "/ld/human/pairwise/rs6792369/rs1042779?population_name=1000GENOMES:phase_3:KHV"

r <- GET(paste(server, ext, sep = ""), content_type("application/json"))

stop_for_status(r)
head(fromJSON(toJSON(content(r))))
   d_prime       r2 variation1 variation2         population_name
1 0.975513 0.951626  rs6792369  rs1042779 1000GENOMES:phase_3:KHV

What I would like to do is to do is to run this command for every SNP
in one list (1g.txt) to each SNP in another list (1n.txt). Where SNP#
is rs# and output every line of result in list.txt

The process is illustrated in the attachment.

Please help,
Ana

______________________________________________
[hidden email] 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.

lists.pdf (36K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

cpolwart-2
so (untested) if you did something like

f1 <- read.text("1g.txt")
f2 <- read.text("1n.txt")

for ( a in as.list(f1) ) {

   for ( b in as.list(f2) ) {

ext <- paste0( "/ld/human/pairwise/",
                a,
                "/",
                b,
                "?population_name=1000GENOMES:phase_3:KHV")

                r <- GET(paste(server, ext, sep = ""),
content_type("application/json"))

                # You presumably need to do something with 'r' at the
moment its over written by the next loop..  were
                # you appending it to list.txt?  Possibly its just a bit
of the R output you want.?

                write(r,file="list.txt",append=TRUE)


   }

}


Are we doing your PhD for you ;-)  Do we get to share ;-)


On 2020-06-19 20:34, Ana Marija wrote:

> Hello,
>
> I have two files (each has 300 lines)like this:
>
> head 1g.txt
> rs6792369
> rs1414517
> rs16857712
> rs16857703
> rs12239392
> ...
>
> head 1n.txt
> rs1042779
> rs2360630
> rs10753597
> rs7549096
> rs2343491
> ...
>
> For each pair of rs# from those two files I can run this command in R
>
> library(httr)
> library(jsonlite)
> library(xml2)
>
> server <- "http://rest.ensembl.org"
> ext <-
> "/ld/human/pairwise/rs6792369/rs1042779?population_name=1000GENOMES:phase_3:KHV"
>
> r <- GET(paste(server, ext, sep = ""),
> content_type("application/json"))
>
> stop_for_status(r)
> head(fromJSON(toJSON(content(r))))
>    d_prime       r2 variation1 variation2         population_name
> 1 0.975513 0.951626  rs6792369  rs1042779 1000GENOMES:phase_3:KHV
>
> What I would like to do is to do is to run this command for every SNP
> in one list (1g.txt) to each SNP in another list (1n.txt). Where SNP#
> is rs# and output every line of result in list.txt
>
> The process is illustrated in the attachment.
>
> Please help,
> Ana
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

Rasmus Liland-3
In reply to this post by anikaM
On 2020-06-19 14:34 -0500, Ana Marija wrote:

>
> server <- "http://rest.ensembl.org"
> ext <- "/ld/human/pairwise/rs6792369/rs1042779?population_name=1000GENOMES:phase_3:KHV"
>
> r <- GET(paste(server, ext, sep = ""), content_type("application/json"))
>
> stop_for_status(r)
> head(fromJSON(toJSON(content(r))))
>    d_prime       r2 variation1 variation2         population_name
> 1 0.975513 0.951626  rs6792369  rs1042779 1000GENOMES:phase_3:KHV
>
> What I would like to do is to do is to run this command for every SNP
> in one list (1g.txt) to each SNP in another list (1n.txt). Where SNP#
> is rs# and output every line of result in list.txt
Dear Ana,

I tried, but for some reason I get only a
response for the first URL you supplied.  

I wrote this:

        files <- c("1g.txt", "1n.txt")
        files <- lapply(files, readLines)
        server <- "http://rest.ensembl.org"
        population.name <- "1000GENOMES:phase_3:KHV"
        ext <- apply(expand.grid(files), 1, function(x) {
          return(paste0(server, "/ld/human/pairwise/",
            x[1], "/", x[2],
            "?population_name=", population.name))
        })
       
        # r <- lapply(ext, function(x) {
        #   httr::GET(x, httr::content_type("application/json"))
        # })
        # names(r) <- ext
        # file <- paste0(population.name, ".rds")
        # saveRDS(object=r, compress="xz", file=file)
       
        r <- readRDS(paste0(population.name, ".rds"))
        lapply(r[1:4], function(x) {
          jsonlite::fromJSON(jsonlite::toJSON(httr::content(x)))
        })


Which if you are able to run it (saving the
output in that rds file), yields this:

        $`http://rest.ensembl.org/ld/human/pairwise/rs6792369/rs1042779?population_name=1000GENOMES:phase_3:KHV`
          variation2         population_name  d_prime       r2 variation1
        1  rs1042779 1000GENOMES:phase_3:KHV 0.975513 0.951626  rs6792369
       
        $`http://rest.ensembl.org/ld/human/pairwise/rs1414517/rs1042779?population_name=1000GENOMES:phase_3:KHV`
        list()
       
        $`http://rest.ensembl.org/ld/human/pairwise/rs16857712/rs1042779?population_name=1000GENOMES:phase_3:KHV`
        list()
       
        $`http://rest.ensembl.org/ld/human/pairwise/rs16857703/rs1042779?population_name=1000GENOMES:phase_3:KHV`
        list()

For some reason, only the first url works ...

I am a bit unfamiliar working with REST
API's.  Or web scraping in general.  Daniel
Cegiełka knows something in this thread some
days ago, where it might be similar to the
API of borsaitaliana.it, where you can supply
headers with curl like he quickly did [2].

You might be able to supply the list of SNPs
in a header to Ensemble in httr::GET somehow
if you read some docs on their API?

Best,
Rasmus

[1] https://marc.info/?t=159249246100002&r=1&w=2
[2] https://marc.info/?l=r-sig-finance&m=159249894208684&w=2

______________________________________________
[hidden email] 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.

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

anikaM
In reply to this post by cpolwart-2
Hi,

thanks for getting back to me, it is just for my job :)

so I tried it:

library(httr)
library(jsonlite)
library(xml2)
library(SparkR, lib.loc = c(file.path(Sys.getenv("SPARK_HOME"), "R", "lib")))
sparkR.session(master = "local[*]", sparkConfig =
list(spark.driver.memory = "2g"))

server <- "http://rest.ensembl.org"

f1 <- read.text("1g.txt")
f2 <- read.text("1n.txt")

for ( a in as.list(f1) ) {

   for ( b in as.list(f2) ) {

ext <- paste0( "/ld/human/pairwise/",
                a,
                "/",
                b,
                "?population_name=1000GENOMES:phase_3:KHV")

                r <- GET(paste(server, ext, sep = ""),
content_type("application/json"))

                write(r,file="list.txt",append=TRUE)


   }

}

and I got this error:
Error in as.list.default(f1) :
  no method for coercing this S4 class to a vector

Please advise

On Fri, Jun 19, 2020 at 3:28 PM <[hidden email]> wrote:

>
> so (untested) if you did something like
>
> f1 <- read.text("1g.txt")
> f2 <- read.text("1n.txt")
>
> for ( a in as.list(f1) ) {
>
>    for ( b in as.list(f2) ) {
>
> ext <- paste0( "/ld/human/pairwise/",
>                 a,
>                 "/",
>                 b,
>                 "?population_name=1000GENOMES:phase_3:KHV")
>
>                 r <- GET(paste(server, ext, sep = ""),
> content_type("application/json"))
>
>                 # You presumably need to do something with 'r' at the
> moment its over written by the next loop..  were
>                 # you appending it to list.txt?  Possibly its just a bit
> of the R output you want.?
>
>                 write(r,file="list.txt",append=TRUE)
>
>
>    }
>
> }
>
>
> Are we doing your PhD for you ;-)  Do we get to share ;-)
>
>
> On 2020-06-19 20:34, Ana Marija wrote:
> > Hello,
> >
> > I have two files (each has 300 lines)like this:
> >
> > head 1g.txt
> > rs6792369
> > rs1414517
> > rs16857712
> > rs16857703
> > rs12239392
> > ...
> >
> > head 1n.txt
> > rs1042779
> > rs2360630
> > rs10753597
> > rs7549096
> > rs2343491
> > ...
> >
> > For each pair of rs# from those two files I can run this command in R
> >
> > library(httr)
> > library(jsonlite)
> > library(xml2)
> >
> > server <- "http://rest.ensembl.org"
> > ext <-
> > "/ld/human/pairwise/rs6792369/rs1042779?population_name=1000GENOMES:phase_3:KHV"
> >
> > r <- GET(paste(server, ext, sep = ""),
> > content_type("application/json"))
> >
> > stop_for_status(r)
> > head(fromJSON(toJSON(content(r))))
> >    d_prime       r2 variation1 variation2         population_name
> > 1 0.975513 0.951626  rs6792369  rs1042779 1000GENOMES:phase_3:KHV
> >
> > What I would like to do is to do is to run this command for every SNP
> > in one list (1g.txt) to each SNP in another list (1n.txt). Where SNP#
> > is rs# and output every line of result in list.txt
> >
> > The process is illustrated in the attachment.
> >
> > Please help,
> > Ana
> >
> > ______________________________________________
> > [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

anikaM
In reply to this post by Rasmus Liland-3
HI Rasmus,

I tried it:

library(base)

files <- c("1g.txt", "1n.txt")
        files <- lapply(files, readLines)
        server <- "http://rest.ensembl.org"
        population.name <- "1000GENOMES:phase_3:KHV"
        ext <- apply(expand.grid(files), 1, function(x) {
          return(paste0(server, "/ld/human/pairwise/",
            x[1], "/", x[2],
            "?population_name=", population.name))
        })

r <- readRDS(paste0(population.name, ".rds"))
        lapply(r[1:4], function(x) {
          jsonlite::fromJSON(jsonlite::toJSON(httr::content(x)))
        })

and I got this error:
> r <- readRDS(paste0(population.name, ".rds"))
Error in gzfile(file, "rb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "rb") :
  cannot open compressed file '1000GENOMES:phase_3:KHV.rds', probable
reason 'No such file or directory'
>         lapply(r[1:4], function(x) {
+           jsonlite::fromJSON(jsonlite::toJSON(httr::content(x)))
+         })
Error in lapply(r[1:4], function(x) { : object 'r' not found

Am I am doing here something wrong?
Do I need any other libraries loaded?

Thanks
Ana

On Fri, Jun 19, 2020 at 3:49 PM Rasmus Liland <[hidden email]> wrote:

>
> On 2020-06-19 14:34 -0500, Ana Marija wrote:
> >
> > server <- "http://rest.ensembl.org"
> > ext <- "/ld/human/pairwise/rs6792369/rs1042779?population_name=1000GENOMES:phase_3:KHV"
> >
> > r <- GET(paste(server, ext, sep = ""), content_type("application/json"))
> >
> > stop_for_status(r)
> > head(fromJSON(toJSON(content(r))))
> >    d_prime       r2 variation1 variation2         population_name
> > 1 0.975513 0.951626  rs6792369  rs1042779 1000GENOMES:phase_3:KHV
> >
> > What I would like to do is to do is to run this command for every SNP
> > in one list (1g.txt) to each SNP in another list (1n.txt). Where SNP#
> > is rs# and output every line of result in list.txt
>
> Dear Ana,
>
> I tried, but for some reason I get only a
> response for the first URL you supplied.
>
> I wrote this:
>
>         files <- c("1g.txt", "1n.txt")
>         files <- lapply(files, readLines)
>         server <- "http://rest.ensembl.org"
>         population.name <- "1000GENOMES:phase_3:KHV"
>         ext <- apply(expand.grid(files), 1, function(x) {
>           return(paste0(server, "/ld/human/pairwise/",
>             x[1], "/", x[2],
>             "?population_name=", population.name))
>         })
>
>         # r <- lapply(ext, function(x) {
>         #   httr::GET(x, httr::content_type("application/json"))
>         # })
>         # names(r) <- ext
>         # file <- paste0(population.name, ".rds")
>         # saveRDS(object=r, compress="xz", file=file)
>
>         r <- readRDS(paste0(population.name, ".rds"))
>         lapply(r[1:4], function(x) {
>           jsonlite::fromJSON(jsonlite::toJSON(httr::content(x)))
>         })
>
>
> Which if you are able to run it (saving the
> output in that rds file), yields this:
>
>         $`http://rest.ensembl.org/ld/human/pairwise/rs6792369/rs1042779?population_name=1000GENOMES:phase_3:KHV`
>           variation2         population_name  d_prime       r2 variation1
>         1  rs1042779 1000GENOMES:phase_3:KHV 0.975513 0.951626  rs6792369
>
>         $`http://rest.ensembl.org/ld/human/pairwise/rs1414517/rs1042779?population_name=1000GENOMES:phase_3:KHV`
>         list()
>
>         $`http://rest.ensembl.org/ld/human/pairwise/rs16857712/rs1042779?population_name=1000GENOMES:phase_3:KHV`
>         list()
>
>         $`http://rest.ensembl.org/ld/human/pairwise/rs16857703/rs1042779?population_name=1000GENOMES:phase_3:KHV`
>         list()
>
> For some reason, only the first url works ...
>
> I am a bit unfamiliar working with REST
> API's.  Or web scraping in general.  Daniel
> Cegiełka knows something in this thread some
> days ago, where it might be similar to the
> API of borsaitaliana.it, where you can supply
> headers with curl like he quickly did [2].
>
> You might be able to supply the list of SNPs
> in a header to Ensemble in httr::GET somehow
> if you read some docs on their API?
>
> Best,
> Rasmus
>
> [1] https://marc.info/?t=159249246100002&r=1&w=2
> [2] https://marc.info/?l=r-sig-finance&m=159249894208684&w=2

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

Rasmus Liland-3
On 2020-06-19 16:07 -0500, Ana Marija wrote:

> HI Rasmus,
>
> I tried it:
>
> library(base)
>
> > r <- readRDS(paste0(population.name, ".rds"))
> Error in gzfile(file, "rb") : cannot open the connection
> In addition: Warning message:
> In gzfile(file, "rb") :
>   cannot open compressed file '1000GENOMES:phase_3:KHV.rds', probable
> reason 'No such file or directory'
Because I run my script again and again after
every little small change using the program
entr[1] as opposed to using Emacs Speaks
Statistics or RStudio, I find it useful to
save partial outputs in rds files, but it
also make sense to not call ensembl.org again
and again ...

Right, so you would run the commented bit
before that first, then save the output list
to the rds to not send too many requests to
the list.  I have attached my rds here.  

        files <- c("1g.txt", "1n.txt")
        files <- lapply(files, readLines)
        server <- "http://rest.ensembl.org"
        population.name <- "1000GENOMES:phase_3:KHV"
        ext <- apply(expand.grid(files), 1, function(x) {
          return(paste0(server, "/ld/human/pairwise/",
            x[1], "/", x[2],
            "?population_name=", population.name))
        })
       
        r <- lapply(ext, function(x) {
          httr::GET(x, httr::content_type("application/json"))
        })
        names(r) <- ext
        file <- paste0(population.name, ".rds")
       
        saveRDS(object=r, compress="xz", file=file)  # <--- Then save the list here for another time!
        # r <- readRDS(paste0(population.name, ".rds"))  # Read it back like this
       
        r <-
        sapply(r, function(x) {
          x <- jsonlite::fromJSON(jsonlite::toJSON(httr::content(x)))
          length(x)
        })
        names(r) <- NULL
        r

[1] http://eradman.com/entrproject/

______________________________________________
[hidden email] 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.

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

cpolwart-2
In reply to this post by anikaM
Oh - read.text isn't in base!  Not sure where is came from (my head
mostly!)  You may have something that adds it but better to use
something that works.  So try using:

library(readr)
f1 <- read_tsv("1g.txt", col.names=F)

This will give you a tibble with f1$X1 with the file in it

then loop it with (a in as.list(f1[,1])

Others will have much slicker code than me!

On 2020-06-19 22:02, Ana Marija wrote:

> Hi,
>
> thanks for getting back to me, it is just for my job :)
>
> so I tried it:
>
> library(httr)
> library(jsonlite)
> library(xml2)
> library(SparkR, lib.loc = c(file.path(Sys.getenv("SPARK_HOME"), "R",
> "lib")))
> sparkR.session(master = "local[*]", sparkConfig =
> list(spark.driver.memory = "2g"))
>
> server <- "http://rest.ensembl.org"
>
> f1 <- read.text("1g.txt")
> f2 <- read.text("1n.txt")
>
> for ( a in as.list(f1) ) {
>
>    for ( b in as.list(f2) ) {
>
> ext <- paste0( "/ld/human/pairwise/",
>                 a,
>                 "/",
>                 b,
>                 "?population_name=1000GENOMES:phase_3:KHV")
>
>                 r <- GET(paste(server, ext, sep = ""),
> content_type("application/json"))
>
>                 write(r,file="list.txt",append=TRUE)
>
>
>    }
>
> }
>
> and I got this error:
> Error in as.list.default(f1) :
>   no method for coercing this S4 class to a vector
>
> Please advise
>
> On Fri, Jun 19, 2020 at 3:28 PM <[hidden email]> wrote:
>>
>> so (untested) if you did something like
>>
>> f1 <- read.text("1g.txt")
>> f2 <- read.text("1n.txt")
>>
>> for ( a in as.list(f1) ) {
>>
>>    for ( b in as.list(f2) ) {
>>
>> ext <- paste0( "/ld/human/pairwise/",
>>                 a,
>>                 "/",
>>                 b,
>>                 "?population_name=1000GENOMES:phase_3:KHV")
>>
>>                 r <- GET(paste(server, ext, sep = ""),
>> content_type("application/json"))
>>
>>                 # You presumably need to do something with 'r' at the
>> moment its over written by the next loop..  were
>>                 # you appending it to list.txt?  Possibly its just a
>> bit
>> of the R output you want.?
>>
>>                 write(r,file="list.txt",append=TRUE)
>>
>>
>>    }
>>
>> }
>>
>>
>> Are we doing your PhD for you ;-)  Do we get to share ;-)
>>
>>
>> On 2020-06-19 20:34, Ana Marija wrote:
>> > Hello,
>> >
>> > I have two files (each has 300 lines)like this:
>> >
>> > head 1g.txt
>> > rs6792369
>> > rs1414517
>> > rs16857712
>> > rs16857703
>> > rs12239392
>> > ...
>> >
>> > head 1n.txt
>> > rs1042779
>> > rs2360630
>> > rs10753597
>> > rs7549096
>> > rs2343491
>> > ...
>> >
>> > For each pair of rs# from those two files I can run this command in R
>> >
>> > library(httr)
>> > library(jsonlite)
>> > library(xml2)
>> >
>> > server <- "http://rest.ensembl.org"
>> > ext <-
>> > "/ld/human/pairwise/rs6792369/rs1042779?population_name=1000GENOMES:phase_3:KHV"
>> >
>> > r <- GET(paste(server, ext, sep = ""),
>> > content_type("application/json"))
>> >
>> > stop_for_status(r)
>> > head(fromJSON(toJSON(content(r))))
>> >    d_prime       r2 variation1 variation2         population_name
>> > 1 0.975513 0.951626  rs6792369  rs1042779 1000GENOMES:phase_3:KHV
>> >
>> > What I would like to do is to do is to run this command for every SNP
>> > in one list (1g.txt) to each SNP in another list (1n.txt). Where SNP#
>> > is rs# and output every line of result in list.txt
>> >
>> > The process is illustrated in the attachment.
>> >
>> > Please help,
>> > Ana
>> >
>> > ______________________________________________
>> > [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

anikaM
I tried it:

 > library(httr)
> library(jsonlite)
> library(xml2)
> library(readr)
> server <- "http://rest.ensembl.org"
> f1 <- read_tsv("1g", col_names=F)
Parsed with column specification:
cols(
  X1 = col_character()
)
> f2 <- read_tsv("1n", col_names=F)
Parsed with column specification:
cols(
  X1 = col_character()
)
>
> for ( a in as.list(f1[,1]) ) {
+
+    for ( b in as.list(f2[,1]) ) {
+
+ ext <- paste0( "/ld/human/pairwise/",
+                 a,
+                 "/",
+                 b,
+                 "?population_name=1000GENOMES:phase_3:KHV")
+
+                 r <- GET(paste(server, ext, sep = ""),
+ content_type("application/json"))
+
+                 write(r,file="list.txt",append=TRUE)
+
+
+    }
+
+ }
Error in parse_url(url) : length(url) == 1 is not TRUE

> traceback()
10: stop(simpleError(msg, call = if (p <- sys.parent(1L)) sys.call(p)))
9: stopifnot(length(url) == 1)
8: parse_url(url)
7: is.url(url)
6: stopifnot(is.url(url))
5: build_url(parse_url(url)[c("scheme", "hostname", "port")])
4: handle_name(url)
3: handle_find(url)
2: handle_url(handle, url, ...)
1: GET(paste(server, ext, sep = ""), content_type("application/json"))

On Fri, Jun 19, 2020 at 4:41 PM <[hidden email]> wrote:

>
> Oh - read.text isn't in base!  Not sure where is came from (my head
> mostly!)  You may have something that adds it but better to use
> something that works.  So try using:
>
> library(readr)
> f1 <- read_tsv("1g.txt", col.names=F)
>
> This will give you a tibble with f1$X1 with the file in it
>
> then loop it with (a in as.list(f1[,1])
>
> Others will have much slicker code than me!
>
> On 2020-06-19 22:02, Ana Marija wrote:
> > Hi,
> >
> > thanks for getting back to me, it is just for my job :)
> >
> > so I tried it:
> >
> > library(httr)
> > library(jsonlite)
> > library(xml2)
> > library(SparkR, lib.loc = c(file.path(Sys.getenv("SPARK_HOME"), "R",
> > "lib")))
> > sparkR.session(master = "local[*]", sparkConfig =
> > list(spark.driver.memory = "2g"))
> >
> > server <- "http://rest.ensembl.org"
> >
> > f1 <- read.text("1g.txt")
> > f2 <- read.text("1n.txt")
> >
> > for ( a in as.list(f1) ) {
> >
> >    for ( b in as.list(f2) ) {
> >
> > ext <- paste0( "/ld/human/pairwise/",
> >                 a,
> >                 "/",
> >                 b,
> >                 "?population_name=1000GENOMES:phase_3:KHV")
> >
> >                 r <- GET(paste(server, ext, sep = ""),
> > content_type("application/json"))
> >
> >                 write(r,file="list.txt",append=TRUE)
> >
> >
> >    }
> >
> > }
> >
> > and I got this error:
> > Error in as.list.default(f1) :
> >   no method for coercing this S4 class to a vector
> >
> > Please advise
> >
> > On Fri, Jun 19, 2020 at 3:28 PM <[hidden email]> wrote:
> >>
> >> so (untested) if you did something like
> >>
> >> f1 <- read.text("1g.txt")
> >> f2 <- read.text("1n.txt")
> >>
> >> for ( a in as.list(f1) ) {
> >>
> >>    for ( b in as.list(f2) ) {
> >>
> >> ext <- paste0( "/ld/human/pairwise/",
> >>                 a,
> >>                 "/",
> >>                 b,
> >>                 "?population_name=1000GENOMES:phase_3:KHV")
> >>
> >>                 r <- GET(paste(server, ext, sep = ""),
> >> content_type("application/json"))
> >>
> >>                 # You presumably need to do something with 'r' at the
> >> moment its over written by the next loop..  were
> >>                 # you appending it to list.txt?  Possibly its just a
> >> bit
> >> of the R output you want.?
> >>
> >>                 write(r,file="list.txt",append=TRUE)
> >>
> >>
> >>    }
> >>
> >> }
> >>
> >>
> >> Are we doing your PhD for you ;-)  Do we get to share ;-)
> >>
> >>
> >> On 2020-06-19 20:34, Ana Marija wrote:
> >> > Hello,
> >> >
> >> > I have two files (each has 300 lines)like this:
> >> >
> >> > head 1g.txt
> >> > rs6792369
> >> > rs1414517
> >> > rs16857712
> >> > rs16857703
> >> > rs12239392
> >> > ...
> >> >
> >> > head 1n.txt
> >> > rs1042779
> >> > rs2360630
> >> > rs10753597
> >> > rs7549096
> >> > rs2343491
> >> > ...
> >> >
> >> > For each pair of rs# from those two files I can run this command in R
> >> >
> >> > library(httr)
> >> > library(jsonlite)
> >> > library(xml2)
> >> >
> >> > server <- "http://rest.ensembl.org"
> >> > ext <-
> >> > "/ld/human/pairwise/rs6792369/rs1042779?population_name=1000GENOMES:phase_3:KHV"
> >> >
> >> > r <- GET(paste(server, ext, sep = ""),
> >> > content_type("application/json"))
> >> >
> >> > stop_for_status(r)
> >> > head(fromJSON(toJSON(content(r))))
> >> >    d_prime       r2 variation1 variation2         population_name
> >> > 1 0.975513 0.951626  rs6792369  rs1042779 1000GENOMES:phase_3:KHV
> >> >
> >> > What I would like to do is to do is to run this command for every SNP
> >> > in one list (1g.txt) to each SNP in another list (1n.txt). Where SNP#
> >> > is rs# and output every line of result in list.txt
> >> >
> >> > The process is illustrated in the attachment.
> >> >
> >> > Please help,
> >> > Ana
> >> >
> >> > ______________________________________________
> >> > [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

Rasmus Liland-3
In reply to this post by Rasmus Liland-3
Dear other list readers,

On 2020-06-19 23:31 +0200, Rasmus Liland wrote:
> I have attached my rds here.  

only Ana recieved this because of a Mailman
attachment policy, which also is why my
signature was bad ...

Best,
Rasmus

______________________________________________
[hidden email] 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.

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

cpolwart-2
In reply to this post by anikaM
Sorry - its been a long week!

there is a foreach package but I try to avoid extras

make your for statements:

for ( a in rownames(f1) ) {

# a will now be a row number rather than the value, so replace ' a ' in
the paste0 with: f1[ a, 1]

so

ext <- paste0( "/ld/human/pairwise/",
                  f1[a,1],
                  "/",
                  f2[b,1],
                  "?population_name=1000GENOMES:phase_3:KHV")

On 2020-06-19 22:54, Ana Marija wrote:

> I tried it:
>
>  > library(httr)
>> library(jsonlite)
>> library(xml2)
>> library(readr)
>> server <- "http://rest.ensembl.org"
>> f1 <- read_tsv("1g", col_names=F)
> Parsed with column specification:
> cols(
>   X1 = col_character()
> )
>> f2 <- read_tsv("1n", col_names=F)
> Parsed with column specification:
> cols(
>   X1 = col_character()
> )
>>
>> for ( a in as.list(f1[,1]) ) {
> +
> +    for ( b in as.list(f2[,1]) ) {
> +
> + ext <- paste0( "/ld/human/pairwise/",
> +                 a,
> +                 "/",
> +                 b,
> +                 "?population_name=1000GENOMES:phase_3:KHV")
> +
> +                 r <- GET(paste(server, ext, sep = ""),
> + content_type("application/json"))
> +
> +                 write(r,file="list.txt",append=TRUE)
> +
> +
> +    }
> +
> + }
> Error in parse_url(url) : length(url) == 1 is not TRUE
>
>> traceback()
> 10: stop(simpleError(msg, call = if (p <- sys.parent(1L)) sys.call(p)))
> 9: stopifnot(length(url) == 1)
> 8: parse_url(url)
> 7: is.url(url)
> 6: stopifnot(is.url(url))
> 5: build_url(parse_url(url)[c("scheme", "hostname", "port")])
> 4: handle_name(url)
> 3: handle_find(url)
> 2: handle_url(handle, url, ...)
> 1: GET(paste(server, ext, sep = ""), content_type("application/json"))
>
> On Fri, Jun 19, 2020 at 4:41 PM <[hidden email]> wrote:
>>
>> Oh - read.text isn't in base!  Not sure where is came from (my head
>> mostly!)  You may have something that adds it but better to use
>> something that works.  So try using:
>>
>> library(readr)
>> f1 <- read_tsv("1g.txt", col.names=F)
>>
>> This will give you a tibble with f1$X1 with the file in it
>>
>> then loop it with (a in as.list(f1[,1])
>>
>> Others will have much slicker code than me!
>>
>> On 2020-06-19 22:02, Ana Marija wrote:
>> > Hi,
>> >
>> > thanks for getting back to me, it is just for my job :)
>> >
>> > so I tried it:
>> >
>> > library(httr)
>> > library(jsonlite)
>> > library(xml2)
>> > library(SparkR, lib.loc = c(file.path(Sys.getenv("SPARK_HOME"), "R",
>> > "lib")))
>> > sparkR.session(master = "local[*]", sparkConfig =
>> > list(spark.driver.memory = "2g"))
>> >
>> > server <- "http://rest.ensembl.org"
>> >
>> > f1 <- read.text("1g.txt")
>> > f2 <- read.text("1n.txt")
>> >
>> > for ( a in as.list(f1) ) {
>> >
>> >    for ( b in as.list(f2) ) {
>> >
>> > ext <- paste0( "/ld/human/pairwise/",
>> >                 a,
>> >                 "/",
>> >                 b,
>> >                 "?population_name=1000GENOMES:phase_3:KHV")
>> >
>> >                 r <- GET(paste(server, ext, sep = ""),
>> > content_type("application/json"))
>> >
>> >                 write(r,file="list.txt",append=TRUE)
>> >
>> >
>> >    }
>> >
>> > }
>> >
>> > and I got this error:
>> > Error in as.list.default(f1) :
>> >   no method for coercing this S4 class to a vector
>> >
>> > Please advise
>> >
>> > On Fri, Jun 19, 2020 at 3:28 PM <[hidden email]> wrote:
>> >>
>> >> so (untested) if you did something like
>> >>
>> >> f1 <- read.text("1g.txt")
>> >> f2 <- read.text("1n.txt")
>> >>
>> >> for ( a in as.list(f1) ) {
>> >>
>> >>    for ( b in as.list(f2) ) {
>> >>
>> >> ext <- paste0( "/ld/human/pairwise/",
>> >>                 a,
>> >>                 "/",
>> >>                 b,
>> >>                 "?population_name=1000GENOMES:phase_3:KHV")
>> >>
>> >>                 r <- GET(paste(server, ext, sep = ""),
>> >> content_type("application/json"))
>> >>
>> >>                 # You presumably need to do something with 'r' at the
>> >> moment its over written by the next loop..  were
>> >>                 # you appending it to list.txt?  Possibly its just a
>> >> bit
>> >> of the R output you want.?
>> >>
>> >>                 write(r,file="list.txt",append=TRUE)
>> >>
>> >>
>> >>    }
>> >>
>> >> }
>> >>
>> >>
>> >> Are we doing your PhD for you ;-)  Do we get to share ;-)
>> >>
>> >>
>> >> On 2020-06-19 20:34, Ana Marija wrote:
>> >> > Hello,
>> >> >
>> >> > I have two files (each has 300 lines)like this:
>> >> >
>> >> > head 1g.txt
>> >> > rs6792369
>> >> > rs1414517
>> >> > rs16857712
>> >> > rs16857703
>> >> > rs12239392
>> >> > ...
>> >> >
>> >> > head 1n.txt
>> >> > rs1042779
>> >> > rs2360630
>> >> > rs10753597
>> >> > rs7549096
>> >> > rs2343491
>> >> > ...
>> >> >
>> >> > For each pair of rs# from those two files I can run this command in R
>> >> >
>> >> > library(httr)
>> >> > library(jsonlite)
>> >> > library(xml2)
>> >> >
>> >> > server <- "http://rest.ensembl.org"
>> >> > ext <-
>> >> > "/ld/human/pairwise/rs6792369/rs1042779?population_name=1000GENOMES:phase_3:KHV"
>> >> >
>> >> > r <- GET(paste(server, ext, sep = ""),
>> >> > content_type("application/json"))
>> >> >
>> >> > stop_for_status(r)
>> >> > head(fromJSON(toJSON(content(r))))
>> >> >    d_prime       r2 variation1 variation2         population_name
>> >> > 1 0.975513 0.951626  rs6792369  rs1042779 1000GENOMES:phase_3:KHV
>> >> >
>> >> > What I would like to do is to do is to run this command for every SNP
>> >> > in one list (1g.txt) to each SNP in another list (1n.txt). Where SNP#
>> >> > is rs# and output every line of result in list.txt
>> >> >
>> >> > The process is illustrated in the attachment.
>> >> >
>> >> > Please help,
>> >> > Ana
>> >> >
>> >> > ______________________________________________
>> >> > [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

Rasmus Liland-3
In reply to this post by anikaM
On 2020-06-19 14:34 -0500, Ana Marija wrote:
>
> I have two files (each has 300 lines)like this:

The example looks quite similar to the R example in
https://rest.ensembl.org/documentation/info/ld_pairwise_get#ra 
...

The question becomes: how did you query the
600 variant names in 1g.txt and 1n.txt?

  curl 'https://rest.ensembl.org/ld/human/pairwise/rs6792369/rs1042779?' -H 'Content-type:application/json'

shows the 26 population_names for the
rs6792369/rs1042779 combination ...

______________________________________________
[hidden email] 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.

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

anikaM
Hi Rasmus,

I got those SNPs from two GWAS-es which I run with different
phenotypes and I would like to compare weather the top SNPs in both of
them are in LD.
So 1n.txt and 1g.txt are just top SNPs from those two GWAS-es.
Unfortunately https://ldlink.nci.nih.gov/?tab=ldpair works for only
two SNPs at the time and I need to do that for 300 pairs

On Fri, Jun 19, 2020 at 6:42 PM Rasmus Liland <[hidden email]> wrote:

>
> On 2020-06-19 14:34 -0500, Ana Marija wrote:
> >
> > I have two files (each has 300 lines)like this:
>
> The example looks quite similar to the R example in
> https://rest.ensembl.org/documentation/info/ld_pairwise_get#ra
> ...
>
> The question becomes: how did you query the
> 600 variant names in 1g.txt and 1n.txt?
>
>   curl 'https://rest.ensembl.org/ld/human/pairwise/rs6792369/rs1042779?' -H 'Content-type:application/json'
>
> shows the 26 population_names for the
> rs6792369/rs1042779 combination ...

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

anikaM
In reply to this post by cpolwart-2
unfortunately it complains again:

> f1 <- read_tsv("1g", col_names=F)
Parsed with column specification:
cols(
  X1 = col_character()
)
> f2 <- read_tsv("1n", col_names=F)
Parsed with column specification:
cols(
  X1 = col_character()
)
> for ( a in rownames(f1) ) {
+
+    for ( b in rownames(f2) ) {
+
+ ext <- paste0( "/ld/human/pairwise/",
+                   f1[a,1],
+                   "/",
+                   f2[b,1],
+                   "?population_name=1000GENOMES:phase_3:KHV")
+
+                 r <- GET(paste(server, ext, sep = ""),
+ content_type("application/json"))
+
+                 write(r,file="list.txt",append=TRUE)
+
+
+    }
+
+ }
Error in cat(x, file = file, sep = c(rep.int(sep, ncolumns - 1), "\n"),  :
  argument 1 (type 'list') cannot be handled by 'cat'

> traceback()
2: cat(x, file = file, sep = c(rep.int(sep, ncolumns - 1), "\n"),
       append = append)
1: write(r, file = "list.txt", append = TRUE)

On Fri, Jun 19, 2020 at 5:19 PM <[hidden email]> wrote:

>
> Sorry - its been a long week!
>
> there is a foreach package but I try to avoid extras
>
> make your for statements:
>
> for ( a in rownames(f1) ) {
>
> # a will now be a row number rather than the value, so replace ' a ' in
> the paste0 with: f1[ a, 1]
>
> so
>
> ext <- paste0( "/ld/human/pairwise/",
>                   f1[a,1],
>                   "/",
>                   f2[b,1],
>                   "?population_name=1000GENOMES:phase_3:KHV")
>
> On 2020-06-19 22:54, Ana Marija wrote:
> > I tried it:
> >
> >  > library(httr)
> >> library(jsonlite)
> >> library(xml2)
> >> library(readr)
> >> server <- "http://rest.ensembl.org"
> >> f1 <- read_tsv("1g", col_names=F)
> > Parsed with column specification:
> > cols(
> >   X1 = col_character()
> > )
> >> f2 <- read_tsv("1n", col_names=F)
> > Parsed with column specification:
> > cols(
> >   X1 = col_character()
> > )
> >>
> >> for ( a in as.list(f1[,1]) ) {
> > +
> > +    for ( b in as.list(f2[,1]) ) {
> > +
> > + ext <- paste0( "/ld/human/pairwise/",
> > +                 a,
> > +                 "/",
> > +                 b,
> > +                 "?population_name=1000GENOMES:phase_3:KHV")
> > +
> > +                 r <- GET(paste(server, ext, sep = ""),
> > + content_type("application/json"))
> > +
> > +                 write(r,file="list.txt",append=TRUE)
> > +
> > +
> > +    }
> > +
> > + }
> > Error in parse_url(url) : length(url) == 1 is not TRUE
> >
> >> traceback()
> > 10: stop(simpleError(msg, call = if (p <- sys.parent(1L)) sys.call(p)))
> > 9: stopifnot(length(url) == 1)
> > 8: parse_url(url)
> > 7: is.url(url)
> > 6: stopifnot(is.url(url))
> > 5: build_url(parse_url(url)[c("scheme", "hostname", "port")])
> > 4: handle_name(url)
> > 3: handle_find(url)
> > 2: handle_url(handle, url, ...)
> > 1: GET(paste(server, ext, sep = ""), content_type("application/json"))
> >
> > On Fri, Jun 19, 2020 at 4:41 PM <[hidden email]> wrote:
> >>
> >> Oh - read.text isn't in base!  Not sure where is came from (my head
> >> mostly!)  You may have something that adds it but better to use
> >> something that works.  So try using:
> >>
> >> library(readr)
> >> f1 <- read_tsv("1g.txt", col.names=F)
> >>
> >> This will give you a tibble with f1$X1 with the file in it
> >>
> >> then loop it with (a in as.list(f1[,1])
> >>
> >> Others will have much slicker code than me!
> >>
> >> On 2020-06-19 22:02, Ana Marija wrote:
> >> > Hi,
> >> >
> >> > thanks for getting back to me, it is just for my job :)
> >> >
> >> > so I tried it:
> >> >
> >> > library(httr)
> >> > library(jsonlite)
> >> > library(xml2)
> >> > library(SparkR, lib.loc = c(file.path(Sys.getenv("SPARK_HOME"), "R",
> >> > "lib")))
> >> > sparkR.session(master = "local[*]", sparkConfig =
> >> > list(spark.driver.memory = "2g"))
> >> >
> >> > server <- "http://rest.ensembl.org"
> >> >
> >> > f1 <- read.text("1g.txt")
> >> > f2 <- read.text("1n.txt")
> >> >
> >> > for ( a in as.list(f1) ) {
> >> >
> >> >    for ( b in as.list(f2) ) {
> >> >
> >> > ext <- paste0( "/ld/human/pairwise/",
> >> >                 a,
> >> >                 "/",
> >> >                 b,
> >> >                 "?population_name=1000GENOMES:phase_3:KHV")
> >> >
> >> >                 r <- GET(paste(server, ext, sep = ""),
> >> > content_type("application/json"))
> >> >
> >> >                 write(r,file="list.txt",append=TRUE)
> >> >
> >> >
> >> >    }
> >> >
> >> > }
> >> >
> >> > and I got this error:
> >> > Error in as.list.default(f1) :
> >> >   no method for coercing this S4 class to a vector
> >> >
> >> > Please advise
> >> >
> >> > On Fri, Jun 19, 2020 at 3:28 PM <[hidden email]> wrote:
> >> >>
> >> >> so (untested) if you did something like
> >> >>
> >> >> f1 <- read.text("1g.txt")
> >> >> f2 <- read.text("1n.txt")
> >> >>
> >> >> for ( a in as.list(f1) ) {
> >> >>
> >> >>    for ( b in as.list(f2) ) {
> >> >>
> >> >> ext <- paste0( "/ld/human/pairwise/",
> >> >>                 a,
> >> >>                 "/",
> >> >>                 b,
> >> >>                 "?population_name=1000GENOMES:phase_3:KHV")
> >> >>
> >> >>                 r <- GET(paste(server, ext, sep = ""),
> >> >> content_type("application/json"))
> >> >>
> >> >>                 # You presumably need to do something with 'r' at the
> >> >> moment its over written by the next loop..  were
> >> >>                 # you appending it to list.txt?  Possibly its just a
> >> >> bit
> >> >> of the R output you want.?
> >> >>
> >> >>                 write(r,file="list.txt",append=TRUE)
> >> >>
> >> >>
> >> >>    }
> >> >>
> >> >> }
> >> >>
> >> >>
> >> >> Are we doing your PhD for you ;-)  Do we get to share ;-)
> >> >>
> >> >>
> >> >> On 2020-06-19 20:34, Ana Marija wrote:
> >> >> > Hello,
> >> >> >
> >> >> > I have two files (each has 300 lines)like this:
> >> >> >
> >> >> > head 1g.txt
> >> >> > rs6792369
> >> >> > rs1414517
> >> >> > rs16857712
> >> >> > rs16857703
> >> >> > rs12239392
> >> >> > ...
> >> >> >
> >> >> > head 1n.txt
> >> >> > rs1042779
> >> >> > rs2360630
> >> >> > rs10753597
> >> >> > rs7549096
> >> >> > rs2343491
> >> >> > ...
> >> >> >
> >> >> > For each pair of rs# from those two files I can run this command in R
> >> >> >
> >> >> > library(httr)
> >> >> > library(jsonlite)
> >> >> > library(xml2)
> >> >> >
> >> >> > server <- "http://rest.ensembl.org"
> >> >> > ext <-
> >> >> > "/ld/human/pairwise/rs6792369/rs1042779?population_name=1000GENOMES:phase_3:KHV"
> >> >> >
> >> >> > r <- GET(paste(server, ext, sep = ""),
> >> >> > content_type("application/json"))
> >> >> >
> >> >> > stop_for_status(r)
> >> >> > head(fromJSON(toJSON(content(r))))
> >> >> >    d_prime       r2 variation1 variation2         population_name
> >> >> > 1 0.975513 0.951626  rs6792369  rs1042779 1000GENOMES:phase_3:KHV
> >> >> >
> >> >> > What I would like to do is to do is to run this command for every SNP
> >> >> > in one list (1g.txt) to each SNP in another list (1n.txt). Where SNP#
> >> >> > is rs# and output every line of result in list.txt
> >> >> >
> >> >> > The process is illustrated in the attachment.
> >> >> >
> >> >> > Please help,
> >> >> > Ana
> >> >> >
> >> >> > ______________________________________________
> >> >> > [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

Bert Gunter-2
In reply to this post by anikaM
All of your torrent of requests for help to have others do your work for
you are about genomics issues. Why aren't you posting on the Bioconductor
Help forum instead, where both the expertise and tools for such matters
exist?  I would characterize your posts here as being largely inappropriate
for that reason.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Jun 19, 2020 at 5:35 PM Ana Marija <[hidden email]>
wrote:

> Hi Rasmus,
>
> I got those SNPs from two GWAS-es which I run with different
> phenotypes and I would like to compare weather the top SNPs in both of
> them are in LD.
> So 1n.txt and 1g.txt are just top SNPs from those two GWAS-es.
> Unfortunately https://ldlink.nci.nih.gov/?tab=ldpair works for only
> two SNPs at the time and I need to do that for 300 pairs
>
> On Fri, Jun 19, 2020 at 6:42 PM Rasmus Liland <[hidden email]> wrote:
> >
> > On 2020-06-19 14:34 -0500, Ana Marija wrote:
> > >
> > > I have two files (each has 300 lines)like this:
> >
> > The example looks quite similar to the R example in
> > https://rest.ensembl.org/documentation/info/ld_pairwise_get#ra
> > ...
> >
> > The question becomes: how did you query the
> > 600 variant names in 1g.txt and 1n.txt?
> >
> >   curl 'https://rest.ensembl.org/ld/human/pairwise/rs6792369/rs1042779?'
> -H 'Content-type:application/json'
> >
> > shows the 26 population_names for the
> > rs6792369/rs1042779 combination ...
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

Rasmus Liland-3
Dear Bert,

On 2020-06-19 18:33 -0700, Bert Gunter wrote:
> All of your torrent of requests for help to
> have others do your work for you are about
> genomics issues.

I am a bioinformatician, I am supposed should
know all of these things, GWAS, Le ggplot,
etc. ...

> Why aren't you posting on the Bioconductor
> Help forum instead, where both the
> expertise and tools for such matters exist?  
> I would characterize your posts here as
> being largely inappropriate for that
> reason.

Perhaps r-sig-genetics@ or r-sig-phylo@?  It
needs some more volume ...

Best,
Rasmus

______________________________________________
[hidden email] 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.

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

Ivan Krylov
In reply to this post by anikaM
On Fri, 19 Jun 2020 19:36:41 -0500
Ana Marija <[hidden email]> wrote:

> Error in cat(x, file = file, sep = c(rep.int(sep, ncolumns - 1),
> "\n"),  : argument 1 (type 'list') cannot be handled by 'cat'

It might be a good idea to try to solve problems like this yourself
instead of waiting for hours for someone to reply. All the required
information is there in the error message: write() fails because r is a
list. Why is r a list? It's returned from GET(), so let's read its
documentation.

httr::GET() returns a response object, not a string [1]. Try passing
as.character(r) or content(r,'text') instead of just r to write(...) or
use a different way of extracting the actual response from the response
object.

--
Best regards,
Ivan

[1] https://httr.r-lib.org/reference/GET.html

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

Bert Gunter-2
In reply to this post by Rasmus Liland-3
genetics is not genomics. Nor are phylogenies. I still believe Bioc is the
right resource.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Jun 19, 2020 at 11:17 PM Rasmus Liland <[hidden email]> wrote:

> Dear Bert,
>
> On 2020-06-19 18:33 -0700, Bert Gunter wrote:
> > All of your torrent of requests for help to
> > have others do your work for you are about
> > genomics issues.
>
> I am a bioinformatician, I am supposed should
> know all of these things, GWAS, Le ggplot,
> etc. ...
>
> > Why aren't you posting on the Bioconductor
> > Help forum instead, where both the
> > expertise and tools for such matters exist?
> > I would characterize your posts here as
> > being largely inappropriate for that
> > reason.
>
> Perhaps r-sig-genetics@ or r-sig-phylo@?  It
> needs some more volume ...
>
> Best,
> Rasmus
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

Rasmus Liland-3
On 2020-06-20 07:29 -0700, Bert Gunter wrote:

> On Fri, Jun 19, 2020 at 11:17 PM Rasmus Liland wrote:
> > On 2020-06-19 18:33 -0700, Bert Gunter wrote:
> > > Why aren't you posting on the
> > > Bioconductor Help forum instead
> >
> > Perhaps r-sig-genetics@ or r-sig-phylo@?  
>
> genetics is not genomics. Nor are
> phylogenies. I still believe Bioc is the
> right resource.
Right, I had a hunch all these fields
were kind of related somehow ¯\_(ツ)_/¯

______________________________________________
[hidden email] 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.

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to loop over two files ...

anikaM
In reply to this post by Ivan Krylov
Thank you so much as.character(r) indeed resolved the issue!

On Sat, Jun 20, 2020 at 3:47 AM Ivan Krylov <[hidden email]> wrote:

>
> On Fri, 19 Jun 2020 19:36:41 -0500
> Ana Marija <[hidden email]> wrote:
>
> > Error in cat(x, file = file, sep = c(rep.int(sep, ncolumns - 1),
> > "\n"),  : argument 1 (type 'list') cannot be handled by 'cat'
>
> It might be a good idea to try to solve problems like this yourself
> instead of waiting for hours for someone to reply. All the required
> information is there in the error message: write() fails because r is a
> list. Why is r a list? It's returned from GET(), so let's read its
> documentation.
>
> httr::GET() returns a response object, not a string [1]. Try passing
> as.character(r) or content(r,'text') instead of just r to write(...) or
> use a different way of extracting the actual response from the response
> object.
>
> --
> Best regards,
> Ivan
>
> [1] https://httr.r-lib.org/reference/GET.html

______________________________________________
[hidden email] 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.