## Pophelper for Structure and fastStructure ## Please consult http://royfrancis.github.io/pophelper/#1_introduction for further details ## Examples use files located at C:\Users\brad2\OneDrive\Documents\R\win-library\3.4\pophelper\files ################################################################################## # PART 1 - Preparing Structure concensus files for plotting # ################################################################################## library(pophelper) ## set working directory (location of directory with ONLY .meanQ files from fastStructure) setwd("/Users/brad2/Desktop/Projects/CJB_Project/Genomics/Structure/StructureResultsK2to5") ## Example for fastStructure (Files from pophelper documentation)##### ## STRUCTURE files (do not use this command to read local files) sfiles <- list.files(path=system.file("files/structure",package="pophelper"), full.names=T) ## basic usage slist <- readQ(files=sfiles) readQ(files=sfiles,filetype="structure") ## select files interactively #readQ(files=choose.files(multi=TRUE)) ## check class of ouput class(slist) ## view head of first converted file head(slist[[1]]) ###################################################################### ## Read Files to be Analysed sfiles <- list.files(full.names=T) sfiles slist <- readQ(files=sfiles) slist ## EXTRA options to explore data ## tabulateQ tabq = tabulateQ(qlist=slist, writetable=TRUE, sorttable=TRUE) tabq ## summariseQ sumq = summariseQ(tabq) sumq ## Evanno method (Structure Only) evanno = evannoMethodStructure(data=sumq, writetable=TRUE, exportplot=TRUE, na.rm=TRUE, imgtype="pdf") evanno ## Run CLUMPP on the data (This will read our files and run CLUMPP) ## This will output merge files which are a censensus for a given K over X runs ## Parammode 1-3; higher if CLUMPP is taking too long (it will select one, in the case of CRB this was 3 before K=2 was added ## When k=2 was added it slowed the process tremendously by defaulting to a lower value; I set it to 3 but increased the reps) #clumppExport(qlist=slist, prefix="CLUMPP", useexe=T) clumppExport(qlist=slist, prefix="CLUMPP", useexe=T, parammode = 2, paramrep = 100) ## Collecting CLUMPP outputs (Merged runs) into a single directory collectClumppOutput(prefix="CLUMPP", filetype="merged", newdir="CollectedCLUMPP") ################################################################################# # PART 2 - Plotting your merge files in a single or multipannel plot # ################################################################################# ## Setwd to the location of the merged files; read those files ## set working directory to location with merge files setwd("/Users/brad2/Desktop/Projects/CJB_Project/Genomics/Structure/StructureResultsK2to5/CollectedCLUMPP") ## Read merge files mergfiles <- list.files(full.names=T) mergfiles merglist <- readQ(files=mergfiles) merglist ## Example for Structure (Files from pophelper documentation)##### sfiles <- list.files(path=system.file("files/structure",package="pophelper"), full.names=T) slist <- readQ(files=sfiles,indlabfromfile=T) slist threelabset <- read.delim(system.file("files/metadata.txt", package="pophelper"), header=T,stringsAsFactors=F) threelabset twolabset <- threelabset[,2:3] twolabset plotQ(slist[2:3],imgoutput="join",showindlab=T,grplab=twolabset, subsetgrp=c("Brazil","Greece"),selgrp="loc",ordergrp=T,showlegend=T, showtitle=T,showsubtitle=T,titlelab="The Great Structure", subtitlelab="The amazing population structure of your favourite organism.", height=1.6,indlabsize=2.3,indlabheight=0.08,indlabspacer=-1, barbordercolour="white",barbordersize=0,outputfilename="plotq",imgtype="png") ################################################################### ## Plot fastStructure concensus plots ## This section is for reading data file with labels if file is CSV library(readr) CJBSpeciesFile <- read_csv("/Users/brad2/Desktop/Projects/CJB_Project/Genomics/Structure/CJBSpeciesFile.csv") View(CJBSpeciesFile) ## Generate Plot (See Pophelper documentation for more info on parameters) plotQ(merglist[1:2],imgoutput="join",outputfilename="mergtest",imgtype = "pdf", showindlab=F, ordergrp = T, grplab=CJBSpeciesFile[2], selgrp = "species", grplabangle = 22, grplabsize = 0.75, grplabheight = 0.8, splabsize = 3, splab = c("K=2","K=3"), titlelab="Dinacoma Population Structure", subtitlelab="n=46; Structure analysis", showtitle=T,showsubtitle=T, grplabjust = 0.75) #plotQ(merglist,imgoutput="join",outputfilename="mergtest",imgtype = "pdf", showindlab=F, #grplab=PopLocCSV[2:3], selgrp = "range", ordergrp = T, #grplabangle = 22, grplabsize = 0.75, grplabheight = 0.8, splabsize = 3, #splab = c("K=2","K=3","K=4","K=5"), titlelab="Dinacoma Population Structure", #subtitlelab="n=46; Structure analysis", showtitle=T,showsubtitle=T, #grplabjust = 0.75) ## For Aligned Files setwd("/Users/brad2/Desktop/Projects/CRB_Project/CRB_Structure/Structure_Full") ## Collect collectClumppOutput(prefix="CLUMPP", filetype="aligned", newdir="AlignedCLUMPP") ## Setwd to the location of the aligned files; read those files setwd("/Users/brad2/Desktop/Projects/CRB_Project/CRB_Structure/Structure_Full/AlignedCLUMPP") ## Read aligned files alignfiles <- list.files(full.names=T) alignfiles ## Change the number to the align file in the "alignfiles" list for the K you wana to look at alignlist <- readQ(files=alignfiles[7]) alignlist plotQ(alignlist, imgoutput="join", outputfilename="aligned 7", imgtype = "pdf")