diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..30c5a28 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,85 @@ +# Contributor Covenant Code of Conduct +To ensure a welcoming experience for our entire community, this project adheres to the [Contributor Covenant code of conduct](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html). By participating, you are expected to uphold this code. Please report unacceptable behavior to evogytis@gmail.com. + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of actions. + +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the project community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, +available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 1a4ca19..e3e9c78 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ for k in myTree.Objects: ## samogitia - + [`samogitia.py`](samogitia.py) is the heavy-lifting, tree file-wrangling script in the collection. It’s main role is to parse BEAST tree files, use baltic to create tree data structures, which samogitia then manipulates to create BEAST-like log files that can usually be imported into [Tracer](http://tree.bio.ed.ac.uk/software/tracer/) or used in another program. @@ -69,7 +69,7 @@ for k in myTree.Objects: ## austechia - + [`austechia.ipynb`](austechia.ipynb) is the fancy Jupyter notebook that takes tree files, usually MCC trees from BEAST, and plots them. It is meant to be part teaching tool to get people to think about how trees are plotted, to allow for highly customisable representations of trees (e.g. Fig 6 in my [MERS-CoV paper](http://dx.doi.org/10.1093/ve/vev023)) and to improve the aesthetics situation in phylogenetics. @@ -77,7 +77,7 @@ for k in myTree.Objects: ## galindia - + [`galindia.ipynb`](galindia.ipynb) is a notebook that uses baltic to plot JSONs from [nextstrain.org](nextstrain.org) in order to allow customisable, static, publication-ready figures for phylogenies coming from nextstrain's augur pipeline. @@ -85,7 +85,7 @@ for k in myTree.Objects: ## curonia - + [`curonia.ipynb`](curonia.ipynb) generalises the [notebook](https://github.com/ebov/space-time/blob/master/Scripts/notebooks/EBOV_phylogeography_animation.ipynb) used to animate the [spread of Ebola virus in West Africa](https://www.youtube.com/watch?v=j4Ut4krp8GQ). This notebook should require minimal manual editing to produce similarly styled animation of other study systems. diff --git a/baltic/__init__.py b/baltic/__init__.py new file mode 100644 index 0000000..cc447b5 --- /dev/null +++ b/baltic/__init__.py @@ -0,0 +1 @@ +from .baltic import * diff --git a/baltic.py b/baltic/baltic.py similarity index 99% rename from baltic.py rename to baltic/baltic.py index 3246c13..485d556 100644 --- a/baltic.py +++ b/baltic/baltic.py @@ -2,6 +2,10 @@ import datetime as dt from functools import reduce +__all__ = ['decimalDate', 'convertDate', 'reticulation', # make from baltic import * safe + 'clade', 'node', 'tree', + 'make_tree', 'make_treeJSON', 'loadJSON', 'loadNexus', 'loadNewick'] + sys.setrecursionlimit(9001) def decimalDate(date,fmt="%Y-%m-%d",variable=False): diff --git a/samogitia.py b/baltic/samogitia.py similarity index 98% rename from samogitia.py rename to baltic/samogitia.py index 54591eb..8dcfbcc 100644 --- a/samogitia.py +++ b/baltic/samogitia.py @@ -43,7 +43,7 @@ def overlap(a,b): upper=int(upper) try: - for line in open('banner_samogitia.txt','r'): + for line in open('../docs/banner_samogitia.txt','r'): sys.stderr.write('%s'%(line)) except: pass @@ -118,7 +118,7 @@ def overlap(a,b): elif k.name in Conakry_tips: tmrcas['B'].append(k.numName) tmrcas['C'].append(k.numName) - + outfile.write('\t%s'%('\t'.join(sorted(tmrcas.keys())))) ########################################### if 'transitions' in analyses: @@ -198,7 +198,7 @@ def overlap(a,b): if len(targetLeft)==0 and len(queryLeft)<=score[required]: ## all of query tips must be descended from common ancestor, every extra descendant of common ancestor not in query contributes to a score nodes[required]=k ## if score improved - assign new common ancestor score[required]=len(queryLeft) ## score is extra descendants not in the list of known tips - + outTMRCA=['%.6f'%(nodes[n].absoluteTime) for n in sorted(nodes.keys())] ## fetch absoluteTime of each identified common ancestor outfile.write('\t%s'%('\t'.join(outTMRCA))) ################################################### @@ -216,7 +216,7 @@ def overlap(a,b): t=min(map(bt.decimalDate,[dateCerberus.search(x).group(1) for x in all_leaves]))-k.absoluteTime+halfBranch else: t=halfBranch - + outSharp.append('(%d,%d,%.4f)'%(N,S,t)) outfile.write('\t%s'%('\t'.join(outSharp))) ################################################### @@ -247,18 +247,18 @@ def overlap(a,b): if [ch.traits[traitName] for ch in k.children].count(kloc)>0: proceed=True #print k.index,k.parent.index,k.traits,k.parent.traits,k.traits[traitName] - + if proceed==True: ## if at least one valid tip and no hanging nodes subtree=copy.deepcopy(ll.traverseWithinTrait(k,traitName)) subtree_leaves=[x.name for x in subtree if isinstance(x,bt.leaf)] - + if len(subtree_leaves)>0: mostRecentTip=max([bt.decimalDate(x.strip("'").split('|')[-1]) for x in subtree_leaves]) while sum([len(nd.children)-sum([1 if ch in subtree else 0 for ch in nd.children]) for nd in subtree if isinstance(nd,bt.node) and nd.index!='Root'])>0: ## keep removing nodes as long as there are nodes with children that are not entirely within subtree for nd in sorted([q for q in subtree if isinstance(q,bt.node)],key=lambda x:(sum([1 if ch in subtree else 0 for ch in x.children]),x.height)): ## iterate over nodes in subtree, starting with ones that have fewest valid children and are more recent - + child_status=[1 if ch in subtree else 0 for ch in nd.children] ## check how many children of current node are under the right trait value - + if sum(child_status)<2 and nd.index!='Root': ## if less than 2 children in subtree (i.e. not all children are under the same trait state) #print 'removing: %d, children in: %s'%(nd.index,[location_to_country[ch.traits[traitName]] for ch in nd.children]) grand_parent=nd.parent ## fetch grandparent of node to be removed @@ -298,14 +298,14 @@ def overlap(a,b): ################################################### outfile.write('\n') ## newline for post-burnin tree treecount+=1 ## increment tree counter - ################################################################################ + ################################################################################ if treecount==threshold: ## tree passed progress bar threshold timeTakenSoFar=dt.datetime.now()-begin ## time elapsed timeElapsed=float(divmod(timeTakenSoFar.total_seconds(),60)[0]+(divmod(timeTakenSoFar.total_seconds(),60)[1])/float(60)) timeRate=float(divmod(timeTakenSoFar.total_seconds(),60)[0]*60+divmod(timeTakenSoFar.total_seconds(),60)[1])/float(treecount+1) ## rate at which trees have been processed processingRate.append(timeRate) ## remember rate ETA=(sum(processingRate)/float(len(processingRate))*(Ntrees-treecount))/float(60)/float(60) ## estimate how long it'll take, given mean processing rate - + excessiveTrees=treecount if treecount>=10000: excessiveTrees=10000 @@ -315,7 +315,7 @@ def overlap(a,b): else: reportElapsed=timeElapsed ## keep minutes reportUnit='m' - + sys.stderr.write('\r') ## output progress bar sys.stderr.write("[%-30s] %4d%% trees: %5d elapsed: %5.2f%1s ETA: %5.2fh (%6.1e s/tree)" % ('='*(excessiveTrees/progress_update),treecount/float(Ntrees)*100.0,treecount,reportElapsed,reportUnit,ETA,processingRate[-1])) sys.stderr.flush() @@ -325,4 +325,4 @@ def overlap(a,b): if 'End;' in line: pass outfile.close() -sys.stderr.write('\nDone!\n') ## done! \ No newline at end of file +sys.stderr.write('\nDone!\n') ## done! diff --git a/austechia.ipynb b/docs/austechia.ipynb similarity index 100% rename from austechia.ipynb rename to docs/austechia.ipynb diff --git a/curonia.ipynb b/docs/curonia.ipynb similarity index 100% rename from curonia.ipynb rename to docs/curonia.ipynb diff --git a/banner_samogitia.txt b/docs/figures/banner_samogitia.txt similarity index 100% rename from banner_samogitia.txt rename to docs/figures/banner_samogitia.txt diff --git a/figures/coa_austechia.png b/docs/figures/coa_austechia.png similarity index 100% rename from figures/coa_austechia.png rename to docs/figures/coa_austechia.png diff --git a/figures/coa_curonia.jpg b/docs/figures/coa_curonia.jpg similarity index 100% rename from figures/coa_curonia.jpg rename to docs/figures/coa_curonia.jpg diff --git a/figures/coa_galindia.jpg b/docs/figures/coa_galindia.jpg similarity index 100% rename from figures/coa_galindia.jpg rename to docs/figures/coa_galindia.jpg diff --git a/figures/coa_samogitia.jpg b/docs/figures/coa_samogitia.jpg similarity index 100% rename from figures/coa_samogitia.jpg rename to docs/figures/coa_samogitia.jpg diff --git a/figures/ebola.jpg b/docs/figures/ebola.jpg similarity index 100% rename from figures/ebola.jpg rename to docs/figures/ebola.jpg diff --git a/figures/mers.jpg b/docs/figures/mers.jpg similarity index 100% rename from figures/mers.jpg rename to docs/figures/mers.jpg diff --git a/galindia.ipynb b/docs/galindia.ipynb similarity index 100% rename from galindia.ipynb rename to docs/galindia.ipynb diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0348de3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +numpy>=1.17 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..d02314c --- /dev/null +++ b/setup.py @@ -0,0 +1,25 @@ +from setuptools import setup, find_packages + +with open("README.md", "rb") as fh: + long_description = fh.read().decode() + +with open("requirements.txt") as fh: + requirements = fh.read().splitlines() + +setup( + name="baltic", + version="0.1.0", + packages=find_packages(), + url="https://github.com/evogytis/baltic", + # license="", + author="Gytis Dudas", + author_email="gytisdudas@gmail.com", + description="Lightweight package for analyzing, manipulating and visualizing annotated phylogenetic trees", + long_description=long_description, + long_description_content_type="text/markdown", + install_requires=requirements, + # python_requires=">=3.6.*", + include_package_data=False, + zip_safe=False, + # classifiers=[], +)