Hi all,
I have a list like this
expBefore <-
list(HM450=list(brac_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03),
gbm_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03)
),
HM27=list(brac_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03),
gbm_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03)
)
)
and I would convert it to
expAfter <-list(
list(
name="HM450",
children=list(
list(name="brca_tcga",
children=list(
list(name="ATM", colour="110000"),
list(name="ATR", colour="330000"),
list(name="BRCA1", colour="550000"),
list(name="BRCA2", colour="770000"),
list(name="CHEK1", colour="990000"),
list(name="CHEK2", colour="bb0000")
), colour="aa0000" # brca_tcga
),
list(name="gbm_tcga",
children=list(
list(name="ATM", colour="001100"),
list(name="ATR", colour="003300"),
list(name="BRCA1", colour="005500"),
list(name="BRCA2", colour="007700"),
list(name="CHEK1", colour="009900"),
list(name="CHEK2", colour="00bb00")
), colour="345345" # gbm_tcga
)
), colour="ffa500" # HM450
),
list(
name="HM27",
children=list(
list(name="brca_tcga",
children=list(
list(name="ATM", colour="110000"),
list(name="ATR", colour="330000"),
list(name="BRCA1", colour="550000"),
list(name="BRCA2", colour="770000"),
list(name="CHEK1", colour="990000"),
list(name="CHEK2", colour="bb0000")
), colour="aa0000" ##brca_tcga
),
list(name="gbm_tcga",
children=list(
list(name="ATM", colour="001100"),
list(name="ATR", colour="003300"),
list(name="BRCA1", colour="005500"),
list(name="BRCA2", colour="007700"),
list(name="CHEK1", colour="009900"),
list(name="CHEK2", colour="00bb00")
), colour="345345") #gbm_tcga
), colour="ff00ff" #HM27
)
);
any suggestion?
Thanks
[[alternative HTML version deleted]]
Sven E. Templer
2015-Jun-05 17:12 UTC
[R] rename and color a list of list of list of values
Hi Karim,
you should learn ?Map to iterate along the list and supply mutliple list
arguments (there is also parallel:::mcMap for multicore).
The magic of the color code generation you figure out yourself, I guess...
Here 'i' intends to be the value, 'n' the name, e.g.
# returns color by character/numeric value:
magic_colour <- function (x) { ... }
# returns child
list_child <- function (i, n) { list(name=n, colour=magic_colour(i)) }
# returns parent
list_parent <- function (i, n) { list(name=n, children=Map(list_child, i,
names(i)), colour=magic_colour(n)) }
# get grandparent
grandparent <- Map(list_parent, expBefore, names(expBefore))
Hope this helps!
Best, S.
On 5 June 2015 at 18:31, Karim Mezhoud <kmezhoud at gmail.com> wrote:
> Hi all,
> I have a list like this
>
> expBefore <-
>
>
list(HM450=list(brac_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03),
>
>
>
gbm_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03)
> ),
>
>
>
HM27=list(brac_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03),
>
>
>
gbm_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03)
> )
> )
>
>
> and I would convert it to
>
> expAfter <-list(
> list(
> name="HM450",
> children=list(
> list(name="brca_tcga",
> children=list(
> list(name="ATM", colour="110000"),
> list(name="ATR", colour="330000"),
> list(name="BRCA1", colour="550000"),
> list(name="BRCA2", colour="770000"),
> list(name="CHEK1", colour="990000"),
> list(name="CHEK2", colour="bb0000")
>
> ), colour="aa0000" # brca_tcga
> ),
> list(name="gbm_tcga",
> children=list(
> list(name="ATM", colour="001100"),
> list(name="ATR", colour="003300"),
> list(name="BRCA1", colour="005500"),
> list(name="BRCA2", colour="007700"),
> list(name="CHEK1", colour="009900"),
> list(name="CHEK2", colour="00bb00")
> ), colour="345345" # gbm_tcga
> )
>
> ), colour="ffa500" # HM450
> ),
> list(
> name="HM27",
> children=list(
> list(name="brca_tcga",
> children=list(
> list(name="ATM", colour="110000"),
> list(name="ATR", colour="330000"),
> list(name="BRCA1", colour="550000"),
> list(name="BRCA2", colour="770000"),
> list(name="CHEK1", colour="990000"),
> list(name="CHEK2", colour="bb0000")
>
> ), colour="aa0000" ##brca_tcga
> ),
> list(name="gbm_tcga",
> children=list(
> list(name="ATM", colour="001100"),
> list(name="ATR", colour="003300"),
> list(name="BRCA1", colour="005500"),
> list(name="BRCA2", colour="007700"),
> list(name="CHEK1", colour="009900"),
> list(name="CHEK2", colour="00bb00")
> ), colour="345345") #gbm_tcga
>
> ), colour="ff00ff" #HM27
> )
>
> );
> any suggestion?
> Thanks
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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]]
Thanks Sven,
I started with the first function.
The values are not in a list but in df. it is more easy for me
the output is a df:
Genes brca_tcga gbm_tcga color_brca color_gbm
name1 v1 v2 col1 col2
name2 v3 v4 col3 col4
name3 v5 v6 col5 col6
attriColorGene <- function(df,colname, color=c(x,y,z)){
Max <- max(df, na.rm=TRUE)
Min <- min(df, na.rm=TRUE)
#"white","yellow", "darkgoldenrod3"
my.colors <- colorRampPalette(c(x,y,z )) #creates a function my.colors
which interpolates n colors between blue, white and red
color.df <- data.frame(colname=seq(Min,Max,1), paste("col_",
colname,
sep="")=my.colors(Max- Min)) #generates 2001 colors from the color
ramp
df.with.color <- merge(df, color.df, by=colname)
return(df.with.color)
}
for(i in 2:length(colnames(df)) ){
colname <- colnames[i]
attriColorGene(df,colname, color=c(x,y,z))
}
could you describe me the structure of the output of
magic_colour, list_child , list_parent?
Thanks
Karim
On Fri, Jun 5, 2015 at 6:12 PM, Sven E. Templer <sven.templer at
gmail.com>
wrote:
> Hi Karim,
>
> you should learn ?Map to iterate along the list and supply mutliple list
> arguments (there is also parallel:::mcMap for multicore).
> The magic of the color code generation you figure out yourself, I guess...
>
>
> Here 'i' intends to be the value, 'n' the name, e.g.
>
> # returns color by character/numeric value:
> magic_colour <- function (x) { ... }
>
> # returns child
> list_child <- function (i, n) { list(name=n, colour=magic_colour(i)) }
>
> # returns parent
> list_parent <- function (i, n) { list(name=n, children=Map(list_child,
i,
> names(i)), colour=magic_colour(n)) }
>
> # get grandparent
> grandparent <- Map(list_parent, expBefore, names(expBefore))
>
>
> Hope this helps!
>
> Best, S.
>
>
> On 5 June 2015 at 18:31, Karim Mezhoud <kmezhoud at gmail.com> wrote:
>
>> Hi all,
>> I have a list like this
>>
>> expBefore <-
>>
>>
list(HM450=list(brac_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03),
>>
>>
>>
gbm_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03)
>> ),
>>
>>
>>
HM27=list(brac_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03),
>>
>>
>>
gbm_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03)
>> )
>> )
>>
>>
>> and I would convert it to
>>
>> expAfter <-list(
>> list(
>> name="HM450",
>> children=list(
>> list(name="brca_tcga",
>> children=list(
>> list(name="ATM", colour="110000"),
>> list(name="ATR", colour="330000"),
>> list(name="BRCA1", colour="550000"),
>> list(name="BRCA2", colour="770000"),
>> list(name="CHEK1", colour="990000"),
>> list(name="CHEK2", colour="bb0000")
>>
>> ), colour="aa0000" # brca_tcga
>> ),
>> list(name="gbm_tcga",
>> children=list(
>> list(name="ATM", colour="001100"),
>> list(name="ATR", colour="003300"),
>> list(name="BRCA1", colour="005500"),
>> list(name="BRCA2", colour="007700"),
>> list(name="CHEK1", colour="009900"),
>> list(name="CHEK2", colour="00bb00")
>> ), colour="345345" # gbm_tcga
>> )
>>
>> ), colour="ffa500" # HM450
>> ),
>> list(
>> name="HM27",
>> children=list(
>> list(name="brca_tcga",
>> children=list(
>> list(name="ATM", colour="110000"),
>> list(name="ATR", colour="330000"),
>> list(name="BRCA1", colour="550000"),
>> list(name="BRCA2", colour="770000"),
>> list(name="CHEK1", colour="990000"),
>> list(name="CHEK2", colour="bb0000")
>>
>> ), colour="aa0000" ##brca_tcga
>> ),
>> list(name="gbm_tcga",
>> children=list(
>> list(name="ATM", colour="001100"),
>> list(name="ATR", colour="003300"),
>> list(name="BRCA1", colour="005500"),
>> list(name="BRCA2", colour="007700"),
>> list(name="CHEK1", colour="009900"),
>> list(name="CHEK2", colour="00bb00")
>> ), colour="345345") #gbm_tcga
>>
>> ), colour="ff00ff" #HM27
>> )
>>
>> );
>> any suggestion?
>> Thanks
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at 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]]