#create input for NTSYS/PCOMC from *strct_in files
f="ApolloLeafCASDENfbpQ30snp.str0505.recode.strct_in"; # STRUCTURE output file from PLINK
ncl=$(head -1 "$f" | awk -F' ' '{print NF}'); #calculate number of loci from 1st line of *strct_in
nrw=$(tail -n +3 "$f" | wc -l); #number of samples
ntbfn="ALLCS"; #NTSYS input file name
echo "*simgend d=row c=band o="$ntbfn".nts r=Dist"$ntbfn".nts
*dcenter o=Dist"$ntbfn".nts r=Dcent"$ntbfn".nts
*eigen o=Dcent"$ntbfn".nts n="$nrw" r=proj"$ntbfn".nts" > "$ntbfn".ntb;
unix2dos "$ntbfn".ntb;
#make the .nts file
#create header
r="1 "$nrw"B $(( $ncl * 2 ))L 1 -9"; #matrix description line
s=""; #locus description line
for i in $(seq 1 1 $ncl);
do s+=$i"a "$i"b ";
done;
header=$(echo "$r"; echo "$s" | sed 's/ $//');
#create data matrix
labs=$(tail -n +3 "$f" | cut -d' ' -f1);
matx=$(tail -n +3 "$f" | cut -d' ' -f3- | sed 's/0/-9/g');
matxx=$(paste -d' ' <(echo "$labs") <(echo "$matx"));
echo "$header"$'\n'"$matxx" > "$ntbfn".nts; #assemble the .nts file
unix2dos "$ntbfn".nts;
No comments:
Post a Comment