Question: Need help with simple FOR loop
0
gravatar for cook.675
16 months ago by
cook.67560
cook.67560 wrote:

This simple for loop I want it to run the function FindMarkers, which will take as an argument a data identifier (1,2,3 etc..) that it will use to pull data from. I then want it to store the result of the function in immunes.i, where I want I to be the same integer (1,2,3)

So I want an output of 15 files names immunes.0, immunes.1, immunes.2 etc...

Right now Im getting an error though; here is the code:

for (i in 0:14){
immunes.i <- FindMarkers(AllCells.combined, ident.1 = "VEH", ident.2 = "IMQ", verbose = TRUE, group.by="stim", subset.ident = "i")
}

The error i get is "Error in WhichCells.Seurat(object = x, cells = cells, idents = idents, : Cannot find the following identities in the object: i"

If I run the last line by itself it works perfectly, namely:

immunes.0 <- FindMarkers(AllCells.combined, ident.1 = "VEH", ident.2 = "IMQ", verbose = TRUE, group.by="stim", subset.ident = "0")

any advice? I want to use i as a variable within the loop but I don't know the right syntax or way to do it....

rna-seq seurat • 926 views
ADD COMMENTlink modified 16 months ago by Prakash2.1k • written 16 months ago by cook.67560
3
gravatar for Prakash
16 months ago by
Prakash2.1k
India
Prakash2.1k wrote:

I would try two things here.

create a list and push the values

immune =list()
 for (i in 0:14){
       immune[i] =FindMarkers(AllCells.combined, ident.1 = "VEH", ident.2 = "IMQ", verbose = TRUE, group.by="stim", subset.ident = i) )
}

or

create multiple object using loop

for (i in 0:14){
  assign(paste0("immune", i), FindMarkers(AllCells.combined, ident.1 = "VEH", ident.2 = "IMQ", verbose = TRUE, group.by="stim", subset.ident = i) ))
}
ADD COMMENTlink modified 16 months ago • written 16 months ago by Prakash2.1k
0
gravatar for swbarnes2
16 months ago by
swbarnes29.4k
United States
swbarnes29.4k wrote:

don't you want

immunes.i <- FindMarkers(AllCells.combined, ident.1 = "VEH", ident.2 = "IMQ", verbose = TRUE, group.by="stim", subset.ident = i)
ADD COMMENTlink written 16 months ago by swbarnes29.4k

Accually thank you, this runs the code but it doesn't give me the desired output. It will run all the functions but the output is only 1 file called immunes.i that contains the data from the last run of the loop.

I want the output to be immunes.1, immunes.2, etc...

ADD REPLYlink modified 16 months ago • written 16 months ago by cook.67560
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1565 users visited in the last hour
_