99599c7130790107ff0de9f043930da6aa7fddf1
angie
  Mon Nov 16 16:35:58 2020 -0800
Scripts for automating SARS-CoV-2 Phylogeny tracks (refs #26530): fetching
sequences and metadata from several public sources, mapping GISAID IDs to
public seq IDs, downloading the latest release of the phylogenetic tree from
github.com/roblanf/sarscov2phylo/ , making VCFs from GISAID and public
sequences, and using github.com/yatisht/usher to resolve ambiguous alleles,
make protobuf files for hgPhyloPlace, and add public sequences that have not
been mapped to GISAID sequences to the sarscov2phylo tree for a comprehensive
public tree+VCF.

This is still not fully otto-mated because certain crucial inputs like
GISAID sequences still must be downloaded using a web browser, but the goal
is to automate as much as possible and maybe someday have it fully cron-driven.

There are two main top-level scripts which call other scripts, which may in turn
call scripts, in this hierarchy:

updateIdMapping.sh
getCogUk.sh
getNcbi.sh
searchAllSarsCov2BioSample.sh
bioSampleIdToText.sh
bioSampleTextToTab.pl
gbMetadataAddBioSample.pl
fixNcbiFastaNames.pl

updateSarsCov2Phylo.sh
getRelease.sh
processRelease.sh
cladeLineageColors.pl
mapPublic.sh
extractUnmappedPublic.sh
addUnmappedPublic.sh

many of the above:
util.sh

publicCredits.sh will hopefully be folded into updateSarsCov2Phylo.sh when I
figure out how to automate fetching of author/institution metadata from NCBI
and COG-UK.

diff --git src/hg/utils/otto/sarscov2phylo/addUnmappedPublic.sh src/hg/utils/otto/sarscov2phylo/addUnmappedPublic.sh
new file mode 100755
index 0000000..2cc1b8a
--- /dev/null
+++ src/hg/utils/otto/sarscov2phylo/addUnmappedPublic.sh
@@ -0,0 +1,83 @@
+#!/bin/bash
+set -beEu -x -o pipefail
+
+#	Do not modify this script, modify the source tree copy:
+#	kent/src/hg/utils/otto/sarscov2phylo/addUnmappedPublic.sh
+
+usage() {
+    echo "usage: $0 releaseLabel"
+}
+
+if [ $# != 1 ]; then
+  usage
+  exit 1
+fi
+
+releaseLabel=$1
+
+echo "releaseLabel=$releaseLabel"
+
+# Inputs from previous script (extractUnmappedPublic.sh)
+alignedFa=unmapped.aligned.fasta
+renaming=unmapped.renaming
+
+ref2bit=/hive/data/genomes/wuhCor1/wuhCor1.2bit
+usherDir=~angie/github/usher
+usher=$usherDir/build/usher
+matToVcf=$usherDir/build/matToVcf
+
+scriptDir=$(dirname "${BASH_SOURCE[0]}")
+
+source $scriptDir/util.sh
+
+# Make VCF -- first without masking, for hgTracks
+time cat <(twoBitToFa $ref2bit stdout) $alignedFa \
+| faToVcf stdin stdout \
+| vcfRenameAndPrune stdin $renaming stdout \
+| gzip -c \
+    > unmapped.vcf.gz
+# Use usher to add unmapped public sequences to tree of mapped subset and infer missing/ambig bases.
+time $usher -u -T 50 \
+    -v unmapped.vcf.gz \
+    -i public-$releaseLabel.notMasked.pb \
+    -o public-$releaseLabel.all.notMasked.pb \
+    >& usher.addUnmappedPublic.log
+$matToVcf -i public-$releaseLabel.all.notMasked.pb -v public-$releaseLabel.all.vcf
+ls -l public-$releaseLabel.all.vcf
+wc -l public-$releaseLabel.all.vcf
+bgzip -f public-$releaseLabel.all.vcf
+tabix -p vcf public-$releaseLabel.all.vcf.gz
+
+# Then with masking for usher/hgPhyloPlace:
+time vcfFilter -excludeVcf=mask.vcf unmapped.vcf.gz \
+| gzip -c \
+    > unmapped.masked.vcf.gz
+time $usher -u -T 50 \
+    -v unmapped.masked.vcf.gz \
+    -i public-$releaseLabel.masked.pb \
+    -o public-$releaseLabel.all.masked.pb \
+    >& usher.addUnmappedPublic.log
+mv uncondensed-final-tree.nh public-$releaseLabel.all.nh
+
+# Make allele-frequency-filtered versions
+# Disregard pipefail just for this pipe because head prevents the cat from completing:
+set +o pipefail
+sampleCount=$(zcat public-$releaseLabel.all.vcf.gz | head | grep ^#CHROM | sed -re 's/\t/\n/g' \
+              | tail -n+10 | wc -l)
+set -o pipefail
+minAc001=$(( (($sampleCount + 999) / 1000) ))
+vcfFilter -minAc=$minAc001 -rename public-$releaseLabel.all.vcf.gz \
+    > public-$releaseLabel.all.minAf.001.vcf
+wc -l public-$releaseLabel.all.minAf.001.vcf
+bgzip -f public-$releaseLabel.all.minAf.001.vcf
+tabix -p vcf public-$releaseLabel.all.minAf.001.vcf.gz
+
+minAc01=$(( (($sampleCount + 99) / 100) ))
+vcfFilter -minAc=$minAc01 -rename public-$releaseLabel.all.minAf.001.vcf.gz \
+    > public-$releaseLabel.all.minAf.01.vcf
+wc -l public-$releaseLabel.all.minAf.01.vcf
+bgzip -f public-$releaseLabel.all.minAf.01.vcf
+tabix -p vcf public-$releaseLabel.all.minAf.01.vcf.gz
+
+#*** TODO: add colors... run nextclade?  run pangolin??
+#*** just use mutations in vcf and/or paths in tree??