#!/bin/sh
## THIS SET OF R SCRIPTS SHOWS YOU HOW TO OPERATE ON YOUR OWN "PRE-DEFINED" POPULATION LABELS
## IT ALSO CREATES "CONTINENTAL FORCING FILES" THAT MAKE MERGE SOME INDIVIDUALS TO INCREASE POWER AND 
## WORK WITH A SET OF INDIVIDUALS OF INTEREST (e.g. Figure 5 of Lawson et al PLoS 2012)
## YOU HAVE TO BE ABLE TO READ AND EDIT "R" SCRIPTS TO GET MUCH OUT OF THIS UNFORTUNATELY. 
## THE FILE FORMATS ARE ALL DOCUMENTED IN THE FINESTRUCTURE MANUAL
##
## The below is the commands I used.  You can do all of this on Windows too with only minor tweaks 
## - run the scripts in R then run the gui as normal.  you might have to manually enter all the file names.
## THE ONLY FILE YOU NEED INITIALLY IS THE ".chunkcounts.out" FILE - THE REST ARE GENERATED HERE

## READ THESE R SCRIPTS FOR MORE DETAILS:
Rscript ../makeLabelledPopulations.R # Use this to work with populations formed from the known labels, e.g. for PCA or just as a seed state to speed up mcmc

Rscript ../makeContinentPopulations.R # Use this to merge individuals into continents

## Wanting to do PCA/ explore the similarity matrix for the whole dataset, colouring by labelled populations?
finestructure -m T -T 1 -t 20000 AllHGDPexample.chunkcounts.out AllHGDPlabelledPopulations.xml AllHGDPlabelledPopulations.tree.xml
finegui -c AllHGDPexample.chunkcounts.out -m AllHGDPlabelledPopulations.xml -t AllHGDPlabelledPopulations.tree.xml &
# Now follow the instructions in ../makeLabelledPopulations.R for getting a pca plot

## Wantiong to do PCA by first merging all 
finestructure -m T -T 1 -t 20000 -F AllHGDPContPopEurope.force AllHGDPexample.chunkcounts.out AllHGDPContPopEurope.xml AllHGDPContPopEurope.tree.xml
finegui -F AllHGDPContPopEurope.force -c AllHGDPexample.chunkcounts.out -m AllHGDPContPopEurope.xml -t AllHGDPContPopEurope.tree.xml &
# Now follow the instructions in ../makeContinentPopulations.R for getting a pca plot

############################
## NOTE: you are supposed to rerun CHROMOCOMBINE to obtain "c" values for the continental analyses
## but I haven't provided you with all the files needed for the HGDP dataset 
## This is because I have to rerun the HGDP with our current ChromoPainter version to get files in the right format.
## Therefore you can't use this as a starting point for the HGDP data, sorry.
## I will fix this in the future - let me know if this is something you would like to work with.
