royfrancis / pophelper

An R package to analyse and visualise admixture proportions from STRUCTURE, fastSTRUCTURE, TESS, ADMIXTURE etc.
http://royfrancis.github.io/pophelper/
139 stars 37 forks source link

Change sample names in plotQMultiline #3

Closed markusruhsam closed 7 years ago

markusruhsam commented 7 years ago

Hello,

I was wondering if it's possible to have the actual sample names in the multi-line plot instead of the numbers?

Thank you

Markus

image

royfrancis commented 7 years ago

By default, it labels numerically 1, 2, 3 ... If you set the option useindlab=T, then labels are taken from input list object. The rownames of the list object are used as individual names. Here is a working example below:

library(pophelper)

#read structure file
sfiles <- list.files(path=system.file("files/structure",package="pophelper"),full.names=T)
slist <- readQ(files=sfiles[1])

# plot using numeric numbering
plotQMultiline(slist,useindlab=F)

#plot using labels from the input (no change because input rownames are 1, 2, 3 ...)
plotQMultiline(slist,useindlab=T)

#read new labels
inds <- read.delim(system.file("files/structureindlabels.txt",package="pophelper"),header=FALSE,stringsAsFactors=FALSE)

# add labels as rownames to qlist
rownames(slist[[1]]) <- inds$V1

# plot with new labels.
plotQMultiline(slist,useindlab=T)

# plot without using labels from input.
plotQMultiline(slist,useindlab=F)
markusruhsam commented 7 years ago

That’s great. Thank you!

Markus

From: Roy Francis [mailto:notifications@github.com] Sent: 23 January 2017 17:46 To: royfrancis/pophelper Cc: Markus Ruhsam; Author Subject: Re: [royfrancis/pophelper] Sample names (#3)

By default, it labels numerically 1, 2, 3 ... If you set the option useindlab=T, then labels are taken from input list object. The rownames of the list object are used as individual names. Here is a working example below:

library(pophelper)

read structure file

sfiles <- list.files(path=system.file("files/structure",package="pophelper"),full.names=T)

slist <- readQ(files=sfiles[1])

plot using numeric numbering

plotQMultiline(slist,useindlab=F)

plot using labels from the input (no change because input rownames are 1, 2, 3 ...)

plotQMultiline(slist,useindlab=T)

read new labels

inds <- read.delim(system.file("files/structureindlabels.txt",package="pophelper"),header=FALSE,stringsAsFactors=FALSE)

add labels as rownames to qlist

rownames(slist[[1]]) <- inds$V1

plot with new labels.

plotQMultiline(slist,useindlab=T)

plot without using labels from input.

plotQMultiline(slist,useindlab=F)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/royfrancis/pophelper/issues/3#issuecomment-274562434, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWI7FrD3UdyXshzO5LOU7WUkoT7QN4G3ks5rVOdbgaJpZM4LrH3M.

The Royal Botanic Garden Edinburgh is a charity registered in Scotland (No SC007983)

markusruhsam commented 7 years ago

Hi Roy,

I just ran through the script with the following commands but the plot still had only the rownames in the plot.

setwd(choose.dir()) library(pophelper) Loading required package: Cairo Loading required package: ggplot2 pophelper v2.0.0 ready. sfiles <- choose.files() slist <- readQ(files=sfiles) inds <- read.delim("mylabels.txt",header=FALSE,stringsAsFactors=FALSE) rownames(slist[[1]]) <- inds$V1 plotQMultiline(slist[c(6)], lpp=7, spl=70, useindlab=T, imgtype="pdf") 20000_run_6_f-Multiline-1.pdf exported.

Maybe it’s because I didn’t use system.file when using read.delim but I couldn’t get it to work. I am not familiar with system.files but thought that "files/structureindlabels.txt" should be substituted with the path to my label files but

inds <- read.delim(system.file("Z:/My Documents/LAB/LAB BOOK/Bluebells/SNP ARRAY/Analyses/pophelper/mylabels.txt", package="pophelper"),header=FALSE,stringsAsFactors=FALSE) produced this error

Error in read.table(file = file, header = header, sep = sep, quote = quote, : no lines available in input In addition: Warning message: In file(file, "rt") : file("") only supports open = "w+" and open = "w+b": using the former

Thank you

Markus

From: Roy Francis [mailto:notifications@github.com] Sent: 23 January 2017 17:46 To: royfrancis/pophelper Cc: Markus Ruhsam; Author Subject: Re: [royfrancis/pophelper] Sample names (#3)

By default, it labels numerically 1, 2, 3 ... If you set the option useindlab=T, then labels are taken from input list object. The rownames of the list object are used as individual names. Here is a working example below:

library(pophelper)

read structure file

sfiles <- list.files(path=system.file("files/structure",package="pophelper"),full.names=T)

slist <- readQ(files=sfiles[1])

plot using numeric numbering

plotQMultiline(slist,useindlab=F)

plot using labels from the input (no change because input rownames are 1, 2, 3 ...)

plotQMultiline(slist,useindlab=T)

read new labels

inds <- read.delim(system.file("files/structureindlabels.txt",package="pophelper"),header=FALSE,stringsAsFactors=FALSE)

add labels as rownames to qlist

rownames(slist[[1]]) <- inds$V1

plot with new labels.

plotQMultiline(slist,useindlab=T)

plot without using labels from input.

plotQMultiline(slist,useindlab=F)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/royfrancis/pophelper/issues/3#issuecomment-274562434, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWI7FrD3UdyXshzO5LOU7WUkoT7QN4G3ks5rVOdbgaJpZM4LrH3M.

The Royal Botanic Garden Edinburgh is a charity registered in Scotland (No SC007983)

royfrancis commented 7 years ago

The system.file() is not needed if reading a file locally.

The below should work.

 sfiles <- choose.files()
 slist <- readQ(files=sfiles)
 inds <- read.delim("mylabels.txt", header=FALSE, stringsAsFactors=FALSE)
 rownames(slist[[1]]) <- inds$V1
 plotQMultiline(slist, lpp=7, spl=70, useindlab=T, imgtype="pdf")

If not, then we need to inspect if inds$V1 actually has a vector of the correct labels. And ensure that the first qlist element is renamed correctly like this rownames(slist[[1]]). If this still doesn't work, then you can send me the files and I can have a look.

markusruhsam commented 7 years ago

Hi Roy,

inds$V1 has a vector of the correct labels and rownames(slist[[1]]) has been renamed correctly but still no individual names in the plot. I attached the files – maybe you can have a look.

Thank you

Markus

From: Roy Francis [mailto:notifications@github.com] Sent: 24 January 2017 17:47 To: royfrancis/pophelper Cc: Markus Ruhsam; Author Subject: Re: [royfrancis/pophelper] Change sample names in plotQMultiline (#3)

The system.file() is not needed if reading a file locally.

The below should work.

sfiles <- choose.files()

slist <- readQ(files=sfiles)

inds <- read.delim("mylabels.txt", header=FALSE, stringsAsFactors=FALSE)

rownames(slist[[1]]) <- inds$V1

plotQMultiline(slist, lpp=7, spl=70, useindlab=T, imgtype="pdf")

If not, then we need to inspect if inds$V1 actually has a vector of the correct labels. And ensure that the first qlist element is renamed correctly like this rownames(slist[[1]]). If this still doesn't work, then you can send me the files and I can have a look.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/royfrancis/pophelper/issues/3#issuecomment-274880223, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWI7FpVqNQY98-2hs5hCxW3knqa60AR_ks5rVjj4gaJpZM4LrH3M.

The Royal Botanic Garden Edinburgh is a charity registered in Scotland (No SC007983)

09N-20 426-07 426-10 AH-1 AH-10 AH-12 AH-13 AH-15 AH-19 AH-2 AH-3 AH-7 AH-8 AR-10 AR-11 AR-12 AR14 AR-17 AR-20 AR-3 AR-4 AR-5 AR-6 B-1 B-10 B-11 B-12 B14 B16 B17 B-2 B-3 B-6 B-7 B-8 BE-1 BE-10 BE11 BE-18 BE-19 BE-3 BE-4 BE-5 BE-6 BE-7 BL-1 BL-10 BL-13 BL-16 BL-17 BL-18 BL-20 BL-3 BL-4 BL-6 BW-12 BW-13 BW-19 BW-2 BW-20 BW-4 BW-5 BW-7 CB9-1 CF-13 CF-2 CF-3 CF-4 CF-5 CF-6 CF-7 CF-8 CT17 CT18 CT6 CT7 CW1 CW2 D15 D16 DK-CM-1 DK-CM-11 DK-CM-13 DK-CM-14 DK-CM-17 DK-CM-2 DK-CM-3 DK-CM-4 DK-CM-5 DK-CM-6 DK-CM-7 DK-CM-8 DK-K-10 DK-K-12 DK-K-14 DK-K-15 DK-K-2 DK-K-20 DK-K-4 DK-K-5 DK-K-8 DK-K-9 DU4 DU5 DU6 FW2 FW3 FW4 GF25 GF26 GF27 GI1 GI2 GI3 GL-1 GL-14 GL-3 GL-4 GL-5 GL-7 GL-9 H10 H11 H12 H2 H3 HH-1 HH-10 HH-11 HH-13 HH2 HH-2 HH-3 HH-4 HH-5 HH-9 K12 L11 L15 L2 L3 L9 N10-8 P10 P1-1 P1-2 P1-3 P8 P9 PD-10 PD-11 PD-14 PD-15 PD-17 PD-2 PD-3 PD-4 PD-6 PD-9 PH8 PH9 T11 T13 T15 T18 T2 T20 T3 T5 T8 T9 TM10 TM12 TM13 TM15 TM19 TM4 TM5 TM6 TM7 TM9 W18 W19 W20 34 37 40 12663 232-01 232-02 232-10 232-11 232-13 232-15 232-20 232-24 232-25 233-25 233-26 239-04 239-05 239-07 239-08 239-09 239-10 239-11 239-12 239-13 239-14 240-23 240-24 240-25 241-21 241-22 241-25 241-28 241-47 241-52 241-53 241-54 241-55 241-56 241-57 241-58 241-59 246-01 246-06 246-11 246-42 CB12 CB13 CB25 CB4 CB7 CB8 CM1 CM10 CM11 CM12 CM13 CM14 CM15 CM16 CM18 CM2 CM4 CM5 CM6 CM7 CM8 CM9 K14 K15 NN10-5 187-03 188-02 258-09 258-10 262-02 232-18 233-29 233-35 233-37 233-48 241-34 245-04 245-11 245-18 245-27 245-31 245-36 246-34 246-54 AH-26 AH-27 AH-28 AH-29 AH-31 AH-32 AH-34 AH-36 AH-38 AH-40 AR-21 AR-22 AR-24 AR-26 AR-27 AR-28 AR-31 AR-32 AR-34 AR-40 B21 B23 B-26 B-27 B28 B-29 B-30 B-31 B-32 B-34 B-36 B-40 BE-23 BE-24 BE-25 BE-26 BE27 BE-29 BE-30 BE-33 BE-35 BE37 BE-38 BE-40 BL-22 BL-24 BL-26 BL-27 BL-30 BL-31 BL-32 BL-35 BL-36 BL-41 BW-23 BW-28 BW-29 BW-30 BW-32 CF-25 CF-28 CF-32 CF-34 CF-35 CF-36 CF-38 CF-39 CF-40 CW19 D14 D7 DK-CM-21 DK-CM-23 DK-CM-25 DK-CM-28 DK-CM-30 DK-CM-34 DK-CM-35 DK-CM-36 DK-CM-37 DK-CM-38 DK-CM-39 DK-CM-40 DK-K-23 DK-K-24 DK-K-25 DK-K-26 DK-K-29 DK-K-31 DK-K-33 DK-K-34 DK-K-36 DK-K-39 GL-21 GL-24 GL-27 GL-30 GL-31 GL-32 GL-33 GL-34 GL-36 GL-37 HH-21 HH-22 HH24 HH-24 HH-26 HH-29 HH31 HH-36 HH-37 HH-40 P1-21 P1-23 P1-25 P1-26 P1-29 P1-30 P1-34 P1-35 P1-36 PD-23 PD-24 PD-26 PD-27 PD28 PD-31 PD-37 PD-38 PD-39 PH10 PH7 T24 T25 T26 T28 T29 T30 T31 T32 T33 T37 TM21 TM22 TM24 TM25 TM27 TM28 TM29 TM30 TM33 TM35 TM36

royfrancis commented 7 years ago

I can't seem to find any attachments.

markusruhsam commented 7 years ago

As the files were attached to the last email but obviously didn’t come through I re-sent the files to your email address given in the pophelper paper.

From: Roy Francis [mailto:notifications@github.com] Sent: 25 January 2017 11:07 To: royfrancis/pophelper Cc: Markus Ruhsam; Author Subject: Re: [royfrancis/pophelper] Change sample names in plotQMultiline (#3)

I can't seem to find any attachments.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/royfrancis/pophelper/issues/3#issuecomment-275080709, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWI7FjIQU1MqJkHgAcwmtJGLp591GZ57ks5rVyzpgaJpZM4LrH3M.

The Royal Botanic Garden Edinburgh is a charity registered in Scotland (No SC007983)

royfrancis commented 7 years ago

Sorry for the delay, but your files do seem to work for me. I tried one file. I used the code below. See attached figure.

library(pophelper)

#read structure file
slist <- readQ(files="20000_run_6_f")

# plot using numeric numbering
plotQMultiline(slist,useindlab=F)

#read new labels
inds <- read.delim("mylabels.txt",header=FALSE,stringsAsFactors=FALSE)

# add labels as rownames to qlist
rownames(slist[[1]]) <- inds$V1

# plot with new labels.
plotQMultiline(slist,useindlab=T)

20000_run_6_f-multiline-1

markusruhsam commented 7 years ago

I just worked out why it didn’t work as I used

slist <- readQ(files=sfiles) inds <- read.delim("mylabels.txt",header=FALSE,stringsAsFactors=FALSE) rownames(slist[[1]]) <- inds$V1 plotQMultiline(slist[c(6)], lpp=7, spl=70, useindlab=T, imgtype="pdf")

when I should have replaced the 1 in rownames(slist[[1]]) with 6 as I instructed the program to plot the 6th run in plotQMultiline()

slist <- readQ(files=sfiles) inds <- read.delim("mylabels.txt",header=FALSE,stringsAsFactors=FALSE) rownames(slist[[6]]) <- inds$V1 plotQMultiline(slist[c(6)], lpp=7, spl=70, useindlab=T, imgtype="pdf")

Thanks for your help

Markus

From: Roy Francis [mailto:notifications@github.com] Sent: 27 January 2017 16:50 To: royfrancis/pophelper Cc: Markus Ruhsam; Author Subject: Re: [royfrancis/pophelper] Change sample names in plotQMultiline (#3)

Sorry for the delay, but your files do seem to work for me. I tried one file. I used the code below. See attached figure.

library(pophelper)

read structure file

slist <- readQ(files="20000_run_6_f")

plot using numeric numbering

plotQMultiline(slist,useindlab=F)

read new labels

inds <- read.delim("mylabels.txt",header=FALSE,stringsAsFactors=FALSE)

add labels as rownames to qlist

rownames(slist[[1]]) <- inds$V1

plot with new labels.

plotQMultiline(slist,useindlab=T)

[https://cloud.githubusercontent.com/assets/5083500/22379296/02c777b0-e4b9-11e6-8691-a8c6ec6bcffc.png]https://cloud.githubusercontent.com/assets/5083500/22379296/02c777b0-e4b9-11e6-8691-a8c6ec6bcffc.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/royfrancis/pophelper/issues/3#issuecomment-275713480, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWI7Fg6ijn6-72vK2Bb0aTYdg_tRk9Qqks5rWiBLgaJpZM4LrH3M.

The Royal Botanic Garden Edinburgh is a charity registered in Scotland (No SC007983)