Skip to content

Commit

Permalink
Merge pull request #117 from McTavishLab/repeat
Browse files Browse the repository at this point in the history
Repeat
  • Loading branch information
snacktavish committed Jun 24, 2020
2 parents 66d45fe + fe606bb commit 1c49642
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 104 deletions.
72 changes: 72 additions & 0 deletions bin/find_trees.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python
import argparse
from opentree import OT



parser = argparse.ArgumentParser()
parser.add_argument("-t","--taxon_name", help="Name of search taxon")
parser.add_argument("-ott","--ott_id", help="Name of search taxon")
parser.add_argument("-tb","--treebase", action = 'store_true', help="Rturn studies with treebase data only")
parser.add_argument("-o","--output", help="Output file path")
args = parser.parse_args()


if args.taxon_name:
try:
ottid = OT.get_ottid_from_name(args.taxon_name)
except:
sys.stdout.write("no match to taxon name. Try finding your taxon on tree.opentreeoflife.org and inputting the taxon id using -ott")


#sys.stdout.write("OTT id of {}")
phylesystem_studies_resp = OT.find_trees(ottid, search_property ='ot:ottId')


studies = dict()
trees = dict()
treebase_studies = set()
for study in phylesystem_studies_resp.response_dict['matched_studies']:
study_id = study['ot:studyId']
studies[study_id] = dict()
study_info = OT.get_study(study_id)
nexson = study_info.response_dict['data']
data_deposit = nexson['nexml'].get(u'^ot:dataDeposit')
data_deposit_url = 'None'
if data_deposit:
data_deposit_url = data_deposit[u'@href']
studies[study_id]['data_deposit_url'] = data_deposit_url
if 'treebase' in data_deposit_url:
treebase_studies.add(study_id)
trees[study_id] = []
for tree in study['matched_trees']:
treeid = tree['ot:treeId']
trees[study_id].append(treeid)
cites = []
studies[study_id]['opentree_url'] = "https://tree.opentreeoflife.org/curator/study/view/{}".format(study_id)
studies[study_id]['reference'] = nexson['nexml'].get('^ot:studyPublicationReference', 'no ref')
studies[study_id]['doi'] = nexson['nexml'].get('^ot:studyPublication', 'no study pub')


cites_phyl = "Members of {} present in the following studies in the OpenTree Phylesystem\n".format(args.taxon_name)


if args.treebase:
cites_phyl = cites_phyl + "Only returning studies with TreeBase links\n"

for study_id in studies:
if args.treebase and study_id not in treebase_studies:
continue
cites_phyl = cites_phyl + "\nStudy {} tree(s) {}\n".format(study_id, ', '.join(trees[study_id]))
cites_phyl = cites_phyl + "OpenTreeUrl: " + studies[study_id]['opentree_url'] + '\n'
cites_phyl = cites_phyl + "Reference: " + studies[study_id]['reference'] + '\n'
cites_phyl = cites_phyl + "Data Deposit URL: " + studies[study_id]['data_deposit_url'] + '\n'


if args.output:
ofi = open(args.output, 'w')
ofi.write(cites_phyl)
else:
print(cites_phyl)


12 changes: 10 additions & 2 deletions bin/physcraper_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,23 @@
boot_reps = 100



run = 1
if args.repeat:
rundir_path = scraper.rundir
blast_dir ="{}/blast_run_{}".format(workdir, scraper.data.tag)
if not os.path.exists(blast_dir):
os.mkdir(blast_dir)
scraper.blast_subdir = blast_dir
scraper.calculate_final_tree(boot_reps = boot_reps)
to_be_blasted = [otu.label for otu in scraper.data.aln if (scraper.data.otu_dict[otu.label]['^physcraper:ingroup'] == True and scraper.data.otu_dict[otu.label]['^physcraper:last_blasted']==None)]
to_be_blasted = [otu.label for otu in scraper.data.aln if ((scraper.data.otu_dict[otu.label]['^physcraper:ingroup'] == True) and (scraper.data.otu_dict[otu.label]['^physcraper:last_blasted']==None))]
while len(to_be_blasted) >= 1:
run += 1
os.rename(scraper.rundir, rundir_path+"_"+str(run))
os.mkdir(scraper.rundir)
scraper.run_blast_wrapper()
scraper.calculate_final_tree(boot_reps = boot_reps)
to_be_blasted = [otu.label for otu in scraper.data.aln if (scraper.data.otu_dict[otu.label]['^physcraper:ingroup'] == True and scraper.data.otu_dict[otu.label]['^physcraper:last_blasted']==None)]
to_be_blasted = [otu.label for otu in scraper.data.aln if ((scraper.data.otu_dict[otu.label]['^physcraper:ingroup'] == True) and (scraper.data.otu_dict[otu.label]['^physcraper:last_blasted']==None))]
elif not args.no_estimate_tree:
#scraper.read_blast_wrapper()
scraper.calculate_final_tree(boot_reps = boot_reps)
Expand Down
16 changes: 16 additions & 0 deletions bin/tree_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,27 @@

args = parser.parse_args()


try:
assert(args.outputdir)
except AssertionError:
sys.stderr.write("ERROR: Output directory (-o) is required.\n")
sys.exit(-1)


comparisondir = args.outputdir
if not os.path.exists(comparisondir):
os.mkdir(comparisondir)


if args.results_dir:
assert(os.path_exists(args.results_dir)), "Results directory {} not found\n".format(args.results_dir)
else:
assert(os.path_exists(args.original_tree)), "Original tree {} not found\n".format(args.original_tree)
assert(os.path_exists(args.updated_tree)), "Updated tree {} not found\n".format(args.updated_tree)
assert(os.path_exists(args.otu_info)), "Otu_info {} not found\n".format(args.otu_info)


tns = dendropy.TaxonNamespace()


Expand Down
66 changes: 0 additions & 66 deletions docs/Concat.md

This file was deleted.

30 changes: 0 additions & 30 deletions docs/FilterBlast.md

This file was deleted.

3 changes: 1 addition & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# -- Project information -----------------------------------------------------

project = 'physcraper'
copyright = '2018, McTavish Lab'
copyright = '2020, McTavish Lab'
author = 'McTavish Lab'

# The short X.Y version
Expand All @@ -46,7 +46,6 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'm2r',
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
Expand Down
2 changes: 1 addition & 1 deletion docs/source/how_to_start.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
How to start
============

.. mdinclude:: ../../cruft/How_to_start.md
.. mdinclude:: ../Tutorial.md

2 changes: 1 addition & 1 deletion physcraper/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from physcraper import AWSWWW

_VERBOSE = 1
_DEBUG = 0
_DEBUG = 1
def debug(msg):
"""short debugging command
"""
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pytest
pytest-cov
pytest-xdist

m2r; python_version > '2.7.13'
m2r
recommonmark

#past
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
author='Emily Jane McTavish',
author_email='ejmctavish@gmail.com',
packages=['physcraper'],
scripts=['bin/physcraper_run.py'],
scripts=['bin/physcraper_run.py',
'bin/tree_comparison.py'],
install_requires=[]
)

0 comments on commit 1c49642

Please sign in to comment.