13.11.20

PLINK STRUCTURE output to NTSYS PCOMC input

#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

#make the .ntb file
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;

4.3.20

Bash one-liner to calculate md5sum by line, using Python

python -c "exec(\"import hashlib, sys\nfor line in sys.stdin:\n\tprint hashlib.md5(line).hexdigest()\")" <<<123$'\n'456


Output (includes newline):
ba1f2511fc30423bdbb183fe33f3dd0f
d2d362cdc6579390f1c0617d74a7913d