


# Do some set up to set environmental variables
# Will save typing, errors, grey hair

KG=/external/diskA/magd/1k/populations

CEU=$KG/CEU
YRI=$KG/YRI
LWK=$KG/LWK
BSO=/global/publicpopdata/BSO/b2t01
KS=/global/publicpopdata/schlebusch/KS1
DDD=/home/scott/SNP/biallele/pilot0_raw_SNPs
# Let's make a list of all the SNPs of all the files we want to handle


for x in $CEU $YRI $LWK $BSO $KS $DDD; do
   echo $x
   BASE=`basename $x`;
   cut -f 2 $x.bim | sort  > $BASE.allsnps
   uniq $BASE.allsnps > $BASE.snps
   uniq -d $BASE.allsnps > $BASE.dups
   /bin/rm $BASE.allsnps
done

touch bad.snps
cat *dups > badsnps.lst

mkdir -p local

def makecopies():
   # Now make copies of the data sets only using 
   for x in $CEU $YRI $LWK $BSO $KS $DDD; do
      echo $x
      BASE=`basename $x`;
      plink --bfile $x --extract $DDD.snps --exclude badsnps.lst\
	    --make-bed --out local/${BASE}
   done


for x in `ls *snps`; do
    for y in `ls *snps`; do
       if [ $x != $y ]; then
          echo "$x $y  `comm -1 -2 $x $y | wc -l`
       fi
    done
done

makecopies()


