Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'ind' and 'k' attributes lost while merging (mergeQ) #59

Open
konopinski opened this issue Apr 24, 2020 · 2 comments
Open

'ind' and 'k' attributes lost while merging (mergeQ) #59

konopinski opened this issue Apr 24, 2020 · 2 comments
Labels
enhancement Additional functionality

Comments

@konopinski
Copy link

Hi,

I love the package so much I made a small pipeline to automatically analyse Structure runs. While plotting I had a small issue with fonts ("font family was not found in Windows database" or so) but solved it with extrafonts package (font_import(), loadfonts()) but this is just to let you and others know as this is more general issue with graphs in R.

My issue is like in title. In the pipeline I wrote the sequence is:
readQ(file, indlabfromfile = TRUE)
alignK()
mergeQ()

The first two commands retain "ind" and "k" attributes but after 'mergeQ' the attributes disappear, which is reported as warning message while plotting (plotQ). It's not a big deal but warnings are disturbing for users and I just wanted to let you know.

Anyway it is possible to add the attributes manually but it's a bit tricky (I cannot find a way to use lapply for that purpose)

MK

@konopinski konopinski changed the title Loses 'ind' and 'k' attributes while merging (mergeQ) ind' and 'k' attributes lost while merging (mergeQ) Apr 24, 2020
@konopinski konopinski changed the title ind' and 'k' attributes lost while merging (mergeQ) 'ind' and 'k' attributes lost while merging (mergeQ) Apr 24, 2020
@royfrancis
Copy link
Owner

Hi,
Thanks for the comments. Hmm.. The font issue is supposed to be optional for using external fonts using the extrafonts package. For normal use, it shouldn't matter. When do you get this message "font family was not found in Windows database"?
Thanks for the note on attributes. I will look into that.
Thanks :)

@konopinski
Copy link
Author

The pipeline is as follows:

### I did some testing of different Structure setup:
StructDir <- "d:/R/Dzik/Structure/"
projects <- list.dirs(paste0(StructDir),full.names =FALSE,recursive = FALSE)
### Structure file contains all the information in extra columns
### including geo references:
geo <- read.table(file=paste0(StructDir,"project_data"),header = TRUE,
                sep = "\t", stringsAsFactors = FALSE, row.names = 1)[c(2,6,7)]
### and so, all the projects are analysed in this loop:
for (i in projects){
  structFiles <- list.files(path=paste0(StructDir,i,"/Results/"),
                      full.names = TRUE)
  Structs <- pophelper::readQ(files = structFiles, 
                      filetype = "structure", indlabfromfile = TRUE)
  qAligned <- alignK(Structs)
  qTable <- tabulateQ(qAligned)
  qSummary <- summariseQ(qTable)
### To see if everything goes right the summary is exported to a file:
  write.table(qSummary,file=paste0("Summary_",i,".xls"),
                      sep = "\t",quote = FALSE)

  evan <- evannoMethodStructure(qSummary,returnplot = TRUE, 
                      returndata = TRUE, exportplot = TRUE, 
                      outputfilename = paste0("Evanno_",i), imgtype = "pdf",
                      basesize = 6,xaxisbreaks = unique(qTable[,"k"]))
### K is picked automatically. Still I always check the pdf plot
  K = evan$data[which(evan$data[,"deltaK"]==max(evan$data[,"deltaK"],
                      na.rm = TRUE)),"k"]
### In this line the attributes are lost
  qMerged <- mergeQ(qAligned)

### ... so I kick them back in
  for (j in 1:length(qSummary[,1])){
    attr(qMerged[[j]],"ind") <- qSummary[j,"ind"]
    attr(qMerged[[j]],"k") <- qSummary[j,"k"]}

### ... and the plot is...
  plotQ(qMerged[K],imgtype = "pdf", returnplot = TRUE, width = 30, height =6, 
                      outputfilename = paste0("StrBarplot_",i,"_K",K), 
                      grplabsize=3.5, showindlab=FALSE, useindlab = TRUE, 
                      grplab = geo[1], basesize = 15)
}
### so I get the plot in file, while on the screen:
# 
# Drawing plot ...
# StrBarplot_ac_Loc_PI_lamPop_alphPop_metro100_K2.pdf exported.
# $plot
# $plot[[1]]
# TableGrob (4 x 1) "arrange": 2 grobs
#   z     cells    name           grob
# 1 1 (1-3,1-1) arrange gtable[layout]
# 2 2 (4-4,1-1) arrange gtable[layout]
# 
# 
# $data
# $data$qlist
# [1] NA
# 
# $data$grplab
# [1] NA
# 
# 
# Warning message:
# In grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) :
#   rodzina czcionek nie została znaleziona w bazie czcionek systemu Windows
[the font family was not found in Windows database (in Polish ;)]

Does this help?

@royfrancis royfrancis added the enhancement Additional functionality label Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Additional functionality
Projects
None yet
Development

No branches or pull requests

2 participants