Skip to content

Instantly share code, notes, and snippets.

@mtholder
Created April 23, 2017 14:52
Show Gist options
  • Select an option

  • Save mtholder/dc9c225dcda9a1d93859065d2245ecd0 to your computer and use it in GitHub Desktop.

Select an option

Save mtholder/dc9c225dcda9a1d93859065d2245ecd0 to your computer and use it in GitHub Desktop.
finds taxonomy only tips in the open tree synth. companion to https://gist.github.com/mtholder/924dd1da9e6bc2775d2d6fe88acade8f
#!/bin/bash
# works on the unpacked dir that is posted under the link
# text "All pipeline outputs " on the release page.
# E.g. the release page https://tree.opentreeoflife.org/about/synthesis-release/v9.1
# points to http://files.opentreeoflife.org/synthesis/opentree9.1/opentree9.1_output.tgz
# as its versions of "All pipeline outputs"
#
# I downloaded that, unpacked it, and provide the path to that dir as the only
# argument to this script.
#
# Unfortunately, I also use the latest version of otcetera to grab the OTT Ids from
# the tips of trees and get the union of that set of IDs.
#
script_name="$(basename $0)"
orig_dir="$(dirname $0)"
synth_dir="${1}"
if test -z ${synth_dir} ; then
echo "Expected a dir name of a synthesis directory."
exit 1
fi
if ! test -d "${synth_dir}" ; then
echo "synthesis directory \"${synth_dir}\" does not exist."
exit 1
fi
ef='err-find-taxonomy-only.txt'
# We will use
rm -f "${ef}"
function finish {
if test -f "${ef}" ; then
cat "${ef}"
fi
}
trap finish EXIT
cfl=cleaned_phylo_tree_filepaths.txt
echo "${script_name}: getting filepaths to (post cleaning) phylo trees as ${cfl} ..."
ls "${synth_dir}/cleaned_phylo/"*.tre | sed -E '/-taxonomy.tre$/d' > "${cfl}" 2>"${ef}" || exit
rm "${ef}"
pt=phylo-tip-ott-ids.txt
echo "${script_name}: getting sorted list of IDs used as terminals in phylogenies (post cleaning) as ${pt} ..."
otc-set-of-ids -t "-f${cfl}" 2>"${ef}" | sort > "${pt}" || exit
rm -f "${ef}"
st=synth-tip-ott-ids.txt
echo "${script_name}: getting sorted list of IDs used as terminal taxa in synth tree ${st} ..."
otc-set-of-ids -t "${synth_dir}/labelled_supertree/labelled_supertree.tre" 2>"${ef}" | sort > "${st}" || exit
rm -f "${ef}"
tot=taxonomy-only-synth-tips.txt
echo "${script_name}: using comm to get a list of synth tip that were not phylo tips ${tot} ..."
comm -1 -3 "${pt}" "${st}" 2>"${ef}" > "${tot}" || exit
rm -f "${ef}"
echo
echo "${script_name}: SUCCESS. See ${tot} for the list of IDs for tips that are taxonomy-only."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment