├── data └── .gitignore ├── lib ├── __init__.py └── .gitignore ├── scripts ├── .gitignore └── polya_diff.py ├── .gitignore ├── snakelib ├── .gitignore └── utils.snake ├── COPYRIGHT ├── ONT_logo.png ├── env.yml ├── config.yml ├── Snakefile ├── coastguard.yml ├── README.md └── LICENSE.md /data/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /snakelib/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | 2 | (c) 2019 Oxford Nanopore Technologies Ltd. 3 | 4 | -------------------------------------------------------------------------------- /ONT_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanoporetech/pipeline-polya-diff/HEAD/ONT_logo.png -------------------------------------------------------------------------------- /env.yml: -------------------------------------------------------------------------------- 1 | channels: 2 | - conda-forge 3 | - bioconda 4 | dependencies: 5 | - pandas 6 | - seaborn 7 | - statsmodels 8 | -------------------------------------------------------------------------------- /config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | ## General pipeline parameters: 3 | 4 | # Name of the pipeline: 5 | pipeline: "pipeline-polya-diff" 6 | # ABSOLUTE path to directory holding the working directory: 7 | workdir_top: "Workspaces" 8 | # Repository URL: 9 | repo: "https://github.com/nanoporetech/pipeline-polya-diff" 10 | 11 | ## Pipeline-specific parameters: 12 | 13 | # Control tail estimates 14 | control_tails: 15 | wt_1: "wt-1/tails/filtered_tails.tsv" 16 | wt_2: "wt-2/tails/filtered_tails.tsv" 17 | 18 | # Treated tail estimates 19 | treated_tails: 20 | mut_1: "mut1/tails/filtered_tails.tsv" 21 | mut_2: "mut2/tails/filtered_tails.tsv" 22 | 23 | # Minimum reads per transcript 24 | min_reads_per_transcript: 10 25 | 26 | # Generate per-transcript plots 27 | per_transcript_plots: "true" 28 | 29 | # Threads 30 | threads: 50 31 | 32 | -------------------------------------------------------------------------------- /snakelib/utils.snake: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | def generate_help(sfile): 4 | """Parse out target and help message from file.""" 5 | handler = open(sfile, "r") 6 | for line in handler: 7 | match = re.match(r'^rule\s+([a-zA-Z_-]+):.*?## (.*)$$', line) 8 | if match: 9 | target, help = match.groups() 10 | print("%-20s %s" % (target, help)) 11 | 12 | rule help: ## print list of all targets with help 13 | input: 14 | workflow.included 15 | run: 16 | print("--------------------------------------------") 17 | [generate_help(sfile) for sfile in input] 18 | print("--------------------------------------------") 19 | 20 | rule clean_workdir: ## delete working directory. WARNING: all data will be lost! 21 | input: 22 | wdir = {WORKDIR} 23 | shell: "rm -r {input.wdir}" 24 | 25 | rule info: ## print pipeline information 26 | params: 27 | name = config["pipeline"], 28 | wdir = WORKDIR, 29 | repo = config["repo"], 30 | run: 31 | print("Pipeline name: ", params.name) 32 | print("Pipeline working directory: ", params.wdir) 33 | print("Pipeline results directory: ", params.res) 34 | print("Pipeline repository: ", params.repo) 35 | 36 | -------------------------------------------------------------------------------- /Snakefile: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | import pandas as pd 4 | from os import path 5 | 6 | if not workflow.overwrite_configfile: 7 | configfile: "config.yml" 8 | workdir: path.join(config["workdir_top"], config["pipeline"]) 9 | 10 | WORKDIR = path.join(config["workdir_top"], config["pipeline"]) 11 | SNAKEDIR = path.dirname(workflow.snakefile) 12 | 13 | include: "snakelib/utils.snake" 14 | 15 | rule dump_versions: 16 | output: 17 | ver = "versions.txt" 18 | conda: "env.yml" 19 | shell:""" 20 | command -v conda > /dev/null && conda list > {output.ver} 21 | """ 22 | 23 | rule merge_tsvs: 24 | params: 25 | control = config["control_tails"], 26 | treated = config["treated_tails"] 27 | output: 28 | mt = "merged/all_tails.tsv" 29 | run: 30 | dfs = [] 31 | for sample, tsv in params.control.items(): 32 | df = pd.read_csv(tsv, sep="\t") 33 | df['sample'] = sample 34 | df['group'] = "control" 35 | dfs.append(df) 36 | for sample, tsv in params.treated.items(): 37 | df = pd.read_csv(tsv, sep="\t") 38 | df['sample'] = sample 39 | df['group'] = "treatment" 40 | dfs.append(df) 41 | adf = pd.concat(dfs) 42 | adf.to_csv(output.mt, sep="\t", index=False) 43 | 44 | rule polya_diff: 45 | input: 46 | tails = rules.merge_tsvs.output.mt 47 | params: 48 | x = config["per_transcript_plots"], 49 | min_cov = config["min_reads_per_transcript"], 50 | pdf = "report/polya_diff_report.pdf", 51 | output: 52 | pdf = "report/polya_diff_report.pdf", 53 | global_tsv = "report/polya_diff_global.tsv", 54 | tr_tsv = "report/polya_diff_per_transcript.tsv", 55 | conda: "env.yml" 56 | shell:""" 57 | X="" 58 | if [ {params.x} == "true" ]; 59 | then 60 | X="-x" 61 | fi 62 | {SNAKEDIR}/scripts/polya_diff.py -i {input.tails} -g {output.global_tsv} -t {output.tr_tsv} -r {params.pdf} $X -c {params.min_cov} 63 | """ 64 | 65 | 66 | rule all: 67 | input: 68 | ver = rules.dump_versions.output.ver, 69 | report = rules.polya_diff.output.pdf, 70 | global_tsv = rules.polya_diff.output.global_tsv, 71 | -------------------------------------------------------------------------------- /coastguard.yml: -------------------------------------------------------------------------------- 1 | settings: 2 | environ: 3 | working_directory: . 4 | temporary_directory: '' 5 | output_directory: '' 6 | custom: 7 | Baywatch: 8 | name: 'Poly(A) tail length shift analysis' 9 | description: | 10 | This pipeline takes the output file tails/filtered_tails.tsv generated by pipeline-polya-ng (which uses nanopolish) from multiple control and treated samples and performs analysis on shifts in poly(A) tail lengths. 11 | The differences in tail length are analysed on the global level and transcript level using the Mann–Whitney U test. 12 | fields: 13 | - label: Minimum reads per transcript 14 | description: Minimum reads per transcript 15 | path: workflow.data.min_reads_per_transcript.path 16 | fieldType: number 17 | value: 10 18 | - label: Generate per-transcript plots 19 | description: Generate per-transcript plots 20 | path: workflow.data.per_transcript_plots.path 21 | fieldType: boolean 22 | value: true 23 | - label: Threads 24 | description: Threads 25 | path: workflow.data.threads.path 26 | fieldType: number 27 | value: 50 28 | workflow: 29 | data: 30 | KEYS_control_tails: 31 | - wt_1 32 | - wt_2 33 | control_tails: 34 | - class: File 35 | path: '' 36 | - class: File 37 | path: '' 38 | KEYS_treated_tails: 39 | - mut_1 40 | - mut_2 41 | treated_tails: 42 | - class: File 43 | path: '' 44 | - class: File 45 | path: '' 46 | min_reads_per_transcript: 10 47 | per_transcript_plots: true 48 | threads: 50 49 | steps: 50 | - Process: 51 | name: 'Poly(A) tail length shift analysis' 52 | HostSNK: 53 | target: all 54 | cores: 5 55 | location: 56 | class: Directory 57 | path: . 58 | config_template: 59 | class: File 60 | path: config.yml 61 | inputs: 62 | - path: data.control_tails 63 | confpath: control_tails 64 | names: data.KEYS_control_tails 65 | remap: samples 66 | - path: data.treated_tails 67 | confpath: treated_tails 68 | names: data.KEYS_treated_tails 69 | remap: samples 70 | - path: data.min_reads_per_transcript 71 | confpath: min_reads_per_transcript 72 | - path: data.per_transcript_plots 73 | confpath: per_transcript_plots 74 | - path: data.threads 75 | confpath: threads 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![ONT_logo](/ONT_logo.png) 2 | ----------------------------- 3 | 4 | Pipeline for testing shifts in poly(A) tail lengths estimated by nanopolish 5 | =========================================================================== 6 | 7 | This pipeline takes the output file `tails/filtered_tails.tsv` generated by [pipeline-polya-ng](https://github.com/nanoporetech/pipeline-polya-ng) (which uses [nanopolish](https://github.com/jts/nanopolish)) from multiple control and treated samples and performs analysis on shifts in poly(A) tail lengths. 8 | 9 | The differences in tail length are analysed on the global level and transcript level using the [Mann–Whitney U test](https://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U_test). 10 | 11 | Getting Started 12 | =============== 13 | 14 | ## Input 15 | 16 | The input files and parameters are specified in `config.yml`: 17 | 18 | - `control_tails` - YAML dictionary with the tail estimates from the control samples. The keys are sample names and values are paths to the input files (e.g. `wt1: "/path/to/filtered_tails.tsv`"`). 19 | - `treated_tails` - YAML dictionary with the tail estimates from the treated samples. 20 | - `min_reads_per_transcript` - minimum reads per transcript per sample. 21 | - `per_transcript_plots` - generate per-transcript plots (true or false). 22 | 23 | ## Output 24 | 25 | - `merged/all_tails.tsv` - all input data merged into a single data frame. 26 | - `report/`: 27 | - `polya_diff_global.tsv` - summary of global poly(A) tail length distribution in control and treated samples. 28 | - `polya_diff_per_transcript.tsv` - per-transcript poly(A) tail shift testing results. 29 | - `polya_diff_report.pdf` - global and per-transcript testing plots. 30 | 31 | 32 | ## Dependencies 33 | 34 | - [miniconda](https://conda.io/miniconda.html) - install it according to the [instructions](https://conda.io/docs/user-guide/install/index.html). 35 | - [snakemake](https://anaconda.org/bioconda/snakemake) install using `conda`. 36 | - [pandas](https://anaconda.org/conda-forge/pandas) - install using `conda`. 37 | - The rest of the dependencies are automatically installed using the `conda` feature of `snakemake`. 38 | 39 | ## Layout 40 | 41 | * `README.md` 42 | * `Snakefile` - master snakefile 43 | * `config.yml` - YAML configuration file 44 | * `snakelib/` - snakefiles collection included by the master snakefile 45 | * `lib/` - python files included by analysis scripts and snakefiles 46 | * `scripts/` - analysis scripts 47 | * `data/` - input data needed by pipeline - use with caution to avoid bloated repo 48 | * `results/` - pipeline results to be commited - use with caution to avoid bloated repo 49 | 50 | ## Installation 51 | 52 | Clone the repository: 53 | 54 | ```bash 55 | git clone https://github.com/nanoporetech/pipeline-polya-diff 56 | ``` 57 | 58 | ## Usage: 59 | 60 | Edit `config.yml` to set the input datasets and parameters, then issue: 61 | 62 | ```bash 63 | snakemake --use-conda -j all 64 | ``` 65 | 66 | Help 67 | ==== 68 | 69 | ## Licence and Copyright 70 | 71 | (c) 2019 Oxford Nanopore Technologies Ltd. 72 | 73 | This Source Code Form is subject to the terms of the Mozilla Public 74 | License, v. 2.0. If a copy of the MPL was not distributed with this 75 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 76 | 77 | ## FAQs and tips 78 | 79 | ## References and Supporting Information 80 | 81 | ### Research Release 82 | 83 | Research releases are provided as technology demonstrators to provide early access to features or stimulate Community development of tools. Support for this software will be minimal and is only provided directly by the developers. Feature requests, improvements, and discussions are welcome and can be implemented by forking and pull requests. However much as we would like to rectify every issue and piece of feedback users may have, the developers may have limited resource for support of this software. Research releases may be unstable and subject to rapid iteration by Oxford Nanopore Technologies. 84 | 85 | 86 | -------------------------------------------------------------------------------- /scripts/polya_diff.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import argparse 5 | import sys 6 | import numpy as np 7 | import scipy 8 | from scipy import stats 9 | from statsmodels.stats.multitest import multipletests 10 | import pandas as pd 11 | from collections import OrderedDict 12 | import matplotlib 13 | matplotlib.use('Agg') 14 | from matplotlib import pyplot as plt 15 | from matplotlib.backends.backend_pdf import PdfPages 16 | from matplotlib import cm 17 | import seaborn as sns 18 | 19 | # Parse command line arguments: 20 | parser = argparse.ArgumentParser( 21 | description='Overview report of poly(A) tail lengths.') 22 | parser.add_argument( 23 | '-i', metavar='input', type=str, help="Input TSV.", required=True) 24 | parser.add_argument( 25 | '-g', metavar='global', type=str, help="Global results TSV.", required=True) 26 | parser.add_argument( 27 | '-t', metavar='per_tr', type=str, help="Per transcript results TSV.", required=True) 28 | parser.add_argument( 29 | '-c', metavar='min_cov', type=int, help="Minimum coverage.", required=True) 30 | parser.add_argument( 31 | '-r', metavar='report', type=str, help="Report PDF.", required=True) 32 | parser.add_argument('-x', action="store_true", 33 | help="Plot per-transcript distributions.", default=False) 34 | 35 | 36 | def _make_distplot(data, title, label, xlab, ylab, pages): 37 | """ Make distplot with median. """ 38 | ax = sns.distplot(data, kde=False, hist_kws={ 39 | "label": label}, norm_hist=False) 40 | ax.set_title(title) 41 | ax.set_xlabel(xlab) 42 | ax.set_xlabel(xlab) 43 | ax.legend(loc='best') 44 | pages.savefig() 45 | plt.clf() 46 | 47 | 48 | def _make_boxplot(df, by, title, pages, showfliers=False, mdf=None): 49 | """ Make box plot. """ 50 | ax = sns.boxplot(x='sample', y='polya_length', hue=by, 51 | showfliers=showfliers, data=df) 52 | ax.set_title(title) 53 | pages.savefig() 54 | plt.clf() 55 | 56 | 57 | def _make_boxplot2(df, title, pages, showfliers=False, mdf=None): 58 | """ Make box plot2. """ 59 | ax = sns.boxplot(x='group', y='polya_length', 60 | showfliers=showfliers, data=df) 61 | mdf_d = OrderedDict() 62 | 63 | for r in mdf.itertuples(): 64 | mdf_d[r.Index] = r.polya_length 65 | 66 | for group, med in mdf_d.items(): 67 | ax.text(list(mdf_d.keys()).index(group), med + 0.5, np.round(med, 2), 68 | horizontalalignment='center', size='x-small', color='w', weight='semibold') 69 | ax.set_title(title) 70 | pages.savefig() 71 | plt.clf() 72 | 73 | 74 | def _corrfunc(x, y, **kws): 75 | r, p = stats.pearsonr(x, y) 76 | ax = plt.gca() 77 | ax.annotate("r = {:.3f} p={:.3f}".format(r, p), 78 | xy=(.1, .9), xycoords=ax.transAxes) 79 | 80 | 81 | def _make_pairplots(df, title, pages): 82 | """ Make pair plots. """ 83 | controls = df[df.group == 'control']['sample'].unique() 84 | treatments = df[df.group == 'treatment']['sample'].unique() 85 | v = df[['contig', 'sample', 'polya_length']] 86 | v = v.reset_index().pivot_table( 87 | index=['contig'], columns='sample', values='polya_length').reset_index() 88 | v = v.groupby('contig').median() 89 | sns.pairplot(v[controls].dropna(), plot_kws={ 90 | 's': 5, 'alpha': 0.65}).map_lower(_corrfunc) 91 | plt.subplots_adjust(top=0.9) 92 | plt.suptitle("Per-transcript tail length medians: control.") 93 | pages.savefig() 94 | plt.clf() 95 | sns.pairplot(v[treatments].dropna(), plot_kws={ 96 | 's': 5, 'alpha': 0.65}).map_lower(_corrfunc) 97 | plt.suptitle("Per-transcript tail length medians: treatment.") 98 | plt.subplots_adjust(top=0.9) 99 | plt.suptitle(title) 100 | pages.savefig() 101 | plt.clf() 102 | 103 | 104 | def _filter_medians(mdf, min_cov, pages): 105 | total_tr = len(mdf) 106 | pos = (mdf['count']['control'] >= min_cov) & ( 107 | mdf['count']['treatment'] > min_cov) 108 | pass_tr = sum(pos) 109 | mdf_flt = mdf[pos] 110 | d = pd.DataFrame(OrderedDict( 111 | [('Category', ["Pass", "Fail"]), ('Count', [pass_tr, total_tr - pass_tr])])) 112 | d.plot.bar(x='Category', y='Count', 113 | title="Filtering for transcripts with counts >= {}".format(min_cov)) 114 | plt.tight_layout() 115 | pages.savefig() 116 | plt.clf() 117 | return mdf_flt.copy() 118 | 119 | 120 | if __name__ == '__main__': 121 | args = parser.parse_args() 122 | pages = PdfPages(args.r) 123 | sns.set_style("whitegrid") 124 | 125 | tails = pd.read_csv(args.i, sep="\t") 126 | mdf = tails[['contig', 'polya_length', 'group']].groupby( 127 | ['contig', 'group']).agg(['median', 'count']) 128 | mdf = mdf.unstack(level=-1) 129 | mdf.columns = mdf.columns.droplevel() 130 | 131 | mdf_flt = _filter_medians(mdf, args.c, pages) 132 | mdf_flt.loc[:, ('median', 'diff')] = mdf_flt.loc[ 133 | :, ('median', 'treatment')].values - mdf_flt.loc[:, ('median', 'control')].values 134 | mdf_flt = mdf_flt.sort_index(axis=1).copy() 135 | 136 | trs = mdf_flt.index.unique() 137 | 138 | tails_flt = tails[tails.contig.isin(trs)] 139 | _make_boxplot(tails[['contig', 'group', 'sample', 'polya_length']], 140 | by='group', title="Boxplot overview (no outliers).", pages=pages) 141 | _make_boxplot(tails_flt[['contig', 'group', 'sample', 'polya_length']], by='group', 142 | title="Boxplot overview after filtering (no outliers).", pages=pages) 143 | _make_pairplots(tails_flt[['contig', 'group', 'sample', 'polya_length']], 144 | title="Data overview after filtering.", pages=pages) 145 | 146 | gu, gp = stats.mannwhitneyu(tails_flt[tails_flt.group == "control"].polya_length.values, tails_flt[ 147 | tails_flt.group == "treatment"].polya_length.values, alternative="two-sided") 148 | title = "Global dist. (no outliers): p-value={:.3f} U={:.3f}".format( 149 | gp, gu) 150 | tails_flt_med = tails_flt[ 151 | ['group', 'polya_length']].groupby('group').median() 152 | 153 | _make_boxplot2(df=tails_flt, title=title, pages=pages, 154 | showfliers=False, mdf=tails_flt_med) 155 | pd.DataFrame({'control': tails_flt_med.loc['control'].polya_length, 'treatment': tails_flt_med.loc['treatment'].polya_length, 'diff': tails_flt_med.loc[ 156 | 'treatment'].polya_length - tails_flt_med.loc['control'].polya_length, 'p-value': [gp], 'U': [gu]}).to_csv(args.g, sep="\t", index=False) 157 | 158 | ulist, plist = [], [] 159 | for tr in trs: 160 | trd = tails_flt[tails_flt.contig == tr] 161 | u, p = stats.mannwhitneyu(trd[trd.group == "control"].polya_length.values, trd[ 162 | trd.group == "treatment"].polya_length.values, alternative="two-sided") 163 | ulist.append(u) 164 | plist.append(p) 165 | 166 | mdf_flt['u'] = ulist 167 | mdf_flt['p-value'] = plist 168 | mdf_flt['FDR'] = multipletests(plist, method="fdr_bh")[1] 169 | mdf_flt = mdf_flt.sort_values(by='FDR') 170 | mdf_flt.to_csv(args.t, sep="\t", index=True) 171 | 172 | _make_distplot(mdf_flt[('median', 'diff')].values, title="Distribution of median differences", label=mdf_flt[ 173 | ('median', 'diff')].median(), xlab="Tail length difference (treatment - control)", ylab="Count", pages=pages) 174 | _make_distplot(mdf_flt[mdf_flt.FDR < 0.05][('median', 'diff')].values, title="Distribution of median differences: FDR < 0.05", label=mdf_flt[ 175 | mdf_flt.FDR < 0.05][('median', 'diff')].median(), xlab="Tail length difference (treatment - control)", ylab="Count", pages=pages) 176 | 177 | if args.x: 178 | for tr in mdf_flt.index: 179 | tr_data = tails_flt[['contig', 'group', 'polya_length']].set_index('contig').loc[ 180 | tr] 181 | title = "{} (no outliers): FDR={:.3f} U={:.3f}".format( 182 | tr, mdf_flt.loc[tr]['FDR'].values[0], mdf_flt.loc[tr]['u'].values[0]) 183 | _make_boxplot2(df=tr_data, title=title, pages=pages, 184 | showfliers=False, mdf=tr_data.groupby('group').median()) 185 | 186 | pages.close() 187 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | (c) 2019 Oxford Nanopore Technologies Ltd. 6 | 7 | 8 | Mozilla Public License Version 2.0 9 | ================================== 10 | 11 | ### 1. Definitions 12 | 13 | **1.1. “Contributor”** 14 | means each individual or legal entity that creates, contributes to 15 | the creation of, or owns Covered Software. 16 | 17 | **1.2. “Contributor Version”** 18 | means the combination of the Contributions of others (if any) used 19 | by a Contributor and that particular Contributor's Contribution. 20 | 21 | **1.3. “Contribution”** 22 | means Covered Software of a particular Contributor. 23 | 24 | **1.4. “Covered Software”** 25 | means Source Code Form to which the initial Contributor has attached 26 | the notice in Exhibit A, the Executable Form of such Source Code 27 | Form, and Modifications of such Source Code Form, in each case 28 | including portions thereof. 29 | 30 | **1.5. “Incompatible With Secondary Licenses”** 31 | means 32 | 33 | * **(a)** that the initial Contributor has attached the notice described 34 | in Exhibit B to the Covered Software; or 35 | * **(b)** that the Covered Software was made available under the terms of 36 | version 1.1 or earlier of the License, but not also under the 37 | terms of a Secondary License. 38 | 39 | **1.6. “Executable Form”** 40 | means any form of the work other than Source Code Form. 41 | 42 | **1.7. “Larger Work”** 43 | means a work that combines Covered Software with other material, in 44 | a separate file or files, that is not Covered Software. 45 | 46 | **1.8. “License”** 47 | means this document. 48 | 49 | **1.9. “Licensable”** 50 | means having the right to grant, to the maximum extent possible, 51 | whether at the time of the initial grant or subsequently, any and 52 | all of the rights conveyed by this License. 53 | 54 | **1.10. “Modifications”** 55 | means any of the following: 56 | 57 | * **(a)** any file in Source Code Form that results from an addition to, 58 | deletion from, or modification of the contents of Covered 59 | Software; or 60 | * **(b)** any new file in Source Code Form that contains any Covered 61 | Software. 62 | 63 | **1.11. “Patent Claims” of a Contributor** 64 | means any patent claim(s), including without limitation, method, 65 | process, and apparatus claims, in any patent Licensable by such 66 | Contributor that would be infringed, but for the grant of the 67 | License, by the making, using, selling, offering for sale, having 68 | made, import, or transfer of either its Contributions or its 69 | Contributor Version. 70 | 71 | **1.12. “Secondary License”** 72 | means either the GNU General Public License, Version 2.0, the GNU 73 | Lesser General Public License, Version 2.1, the GNU Affero General 74 | Public License, Version 3.0, or any later versions of those 75 | licenses. 76 | 77 | **1.13. “Source Code Form”** 78 | means the form of the work preferred for making modifications. 79 | 80 | **1.14. “You” (or “Your”)** 81 | means an individual or a legal entity exercising rights under this 82 | License. For legal entities, “You” includes any entity that 83 | controls, is controlled by, or is under common control with You. For 84 | purposes of this definition, “control” means **(a)** the power, direct 85 | or indirect, to cause the direction or management of such entity, 86 | whether by contract or otherwise, or **(b)** ownership of more than 87 | fifty percent (50%) of the outstanding shares or beneficial 88 | ownership of such entity. 89 | 90 | 91 | ### 2. License Grants and Conditions 92 | 93 | #### 2.1. Grants 94 | 95 | Each Contributor hereby grants You a world-wide, royalty-free, 96 | non-exclusive license: 97 | 98 | * **(a)** under intellectual property rights (other than patent or trademark) 99 | Licensable by such Contributor to use, reproduce, make available, 100 | modify, display, perform, distribute, and otherwise exploit its 101 | Contributions, either on an unmodified basis, with Modifications, or 102 | as part of a Larger Work; and 103 | * **(b)** under Patent Claims of such Contributor to make, use, sell, offer 104 | for sale, have made, import, and otherwise transfer either its 105 | Contributions or its Contributor Version. 106 | 107 | #### 2.2. Effective Date 108 | 109 | The licenses granted in Section 2.1 with respect to any Contribution 110 | become effective for each Contribution on the date the Contributor first 111 | distributes such Contribution. 112 | 113 | #### 2.3. Limitations on Grant Scope 114 | 115 | The licenses granted in this Section 2 are the only rights granted under 116 | this License. No additional rights or licenses will be implied from the 117 | distribution or licensing of Covered Software under this License. 118 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 119 | Contributor: 120 | 121 | * **(a)** for any code that a Contributor has removed from Covered Software; 122 | or 123 | * **(b)** for infringements caused by: **(i)** Your and any other third party's 124 | modifications of Covered Software, or **(ii)** the combination of its 125 | Contributions with other software (except as part of its Contributor 126 | Version); or 127 | * **(c)** under Patent Claims infringed by Covered Software in the absence of 128 | its Contributions. 129 | 130 | This License does not grant any rights in the trademarks, service marks, 131 | or logos of any Contributor (except as may be necessary to comply with 132 | the notice requirements in Section 3.4). 133 | 134 | #### 2.4. Subsequent Licenses 135 | 136 | No Contributor makes additional grants as a result of Your choice to 137 | distribute the Covered Software under a subsequent version of this 138 | License (see Section 10.2) or under the terms of a Secondary License (if 139 | permitted under the terms of Section 3.3). 140 | 141 | #### 2.5. Representation 142 | 143 | Each Contributor represents that the Contributor believes its 144 | Contributions are its original creation(s) or it has sufficient rights 145 | to grant the rights to its Contributions conveyed by this License. 146 | 147 | #### 2.6. Fair Use 148 | 149 | This License is not intended to limit any rights You have under 150 | applicable copyright doctrines of fair use, fair dealing, or other 151 | equivalents. 152 | 153 | #### 2.7. Conditions 154 | 155 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 156 | in Section 2.1. 157 | 158 | 159 | ### 3. Responsibilities 160 | 161 | #### 3.1. Distribution of Source Form 162 | 163 | All distribution of Covered Software in Source Code Form, including any 164 | Modifications that You create or to which You contribute, must be under 165 | the terms of this License. You must inform recipients that the Source 166 | Code Form of the Covered Software is governed by the terms of this 167 | License, and how they can obtain a copy of this License. You may not 168 | attempt to alter or restrict the recipients' rights in the Source Code 169 | Form. 170 | 171 | #### 3.2. Distribution of Executable Form 172 | 173 | If You distribute Covered Software in Executable Form then: 174 | 175 | * **(a)** such Covered Software must also be made available in Source Code 176 | Form, as described in Section 3.1, and You must inform recipients of 177 | the Executable Form how they can obtain a copy of such Source Code 178 | Form by reasonable means in a timely manner, at a charge no more 179 | than the cost of distribution to the recipient; and 180 | 181 | * **(b)** You may distribute such Executable Form under the terms of this 182 | License, or sublicense it under different terms, provided that the 183 | license for the Executable Form does not attempt to limit or alter 184 | the recipients' rights in the Source Code Form under this License. 185 | 186 | #### 3.3. Distribution of a Larger Work 187 | 188 | You may create and distribute a Larger Work under terms of Your choice, 189 | provided that You also comply with the requirements of this License for 190 | the Covered Software. If the Larger Work is a combination of Covered 191 | Software with a work governed by one or more Secondary Licenses, and the 192 | Covered Software is not Incompatible With Secondary Licenses, this 193 | License permits You to additionally distribute such Covered Software 194 | under the terms of such Secondary License(s), so that the recipient of 195 | the Larger Work may, at their option, further distribute the Covered 196 | Software under the terms of either this License or such Secondary 197 | License(s). 198 | 199 | #### 3.4. Notices 200 | 201 | You may not remove or alter the substance of any license notices 202 | (including copyright notices, patent notices, disclaimers of warranty, 203 | or limitations of liability) contained within the Source Code Form of 204 | the Covered Software, except that You may alter any license notices to 205 | the extent required to remedy known factual inaccuracies. 206 | 207 | #### 3.5. Application of Additional Terms 208 | 209 | You may choose to offer, and to charge a fee for, warranty, support, 210 | indemnity or liability obligations to one or more recipients of Covered 211 | Software. However, You may do so only on Your own behalf, and not on 212 | behalf of any Contributor. You must make it absolutely clear that any 213 | such warranty, support, indemnity, or liability obligation is offered by 214 | You alone, and You hereby agree to indemnify every Contributor for any 215 | liability incurred by such Contributor as a result of warranty, support, 216 | indemnity or liability terms You offer. You may include additional 217 | disclaimers of warranty and limitations of liability specific to any 218 | jurisdiction. 219 | 220 | 221 | ### 4. Inability to Comply Due to Statute or Regulation 222 | 223 | If it is impossible for You to comply with any of the terms of this 224 | License with respect to some or all of the Covered Software due to 225 | statute, judicial order, or regulation then You must: **(a)** comply with 226 | the terms of this License to the maximum extent possible; and **(b)** 227 | describe the limitations and the code they affect. Such description must 228 | be placed in a text file included with all distributions of the Covered 229 | Software under this License. Except to the extent prohibited by statute 230 | or regulation, such description must be sufficiently detailed for a 231 | recipient of ordinary skill to be able to understand it. 232 | 233 | 234 | ### 5. Termination 235 | 236 | **5.1.** The rights granted under this License will terminate automatically 237 | if You fail to comply with any of its terms. However, if You become 238 | compliant, then the rights granted under this License from a particular 239 | Contributor are reinstated **(a)** provisionally, unless and until such 240 | Contributor explicitly and finally terminates Your grants, and **(b)** on an 241 | ongoing basis, if such Contributor fails to notify You of the 242 | non-compliance by some reasonable means prior to 60 days after You have 243 | come back into compliance. Moreover, Your grants from a particular 244 | Contributor are reinstated on an ongoing basis if such Contributor 245 | notifies You of the non-compliance by some reasonable means, this is the 246 | first time You have received notice of non-compliance with this License 247 | from such Contributor, and You become compliant prior to 30 days after 248 | Your receipt of the notice. 249 | 250 | **5.2.** If You initiate litigation against any entity by asserting a patent 251 | infringement claim (excluding declaratory judgment actions, 252 | counter-claims, and cross-claims) alleging that a Contributor Version 253 | directly or indirectly infringes any patent, then the rights granted to 254 | You by any and all Contributors for the Covered Software under Section 255 | 2.1 of this License shall terminate. 256 | 257 | **5.3.** In the event of termination under Sections 5.1 or 5.2 above, all 258 | end user license agreements (excluding distributors and resellers) which 259 | have been validly granted by You or Your distributors under this License 260 | prior to termination shall survive termination. 261 | 262 | 263 | ### 6. Disclaimer of Warranty 264 | 265 | > Covered Software is provided under this License on an “as is” 266 | > basis, without warranty of any kind, either expressed, implied, or 267 | > statutory, including, without limitation, warranties that the 268 | > Covered Software is free of defects, merchantable, fit for a 269 | > particular purpose or non-infringing. The entire risk as to the 270 | > quality and performance of the Covered Software is with You. 271 | > Should any Covered Software prove defective in any respect, You 272 | > (not any Contributor) assume the cost of any necessary servicing, 273 | > repair, or correction. This disclaimer of warranty constitutes an 274 | > essential part of this License. No use of any Covered Software is 275 | > authorized under this License except under this disclaimer. 276 | 277 | ### 7. Limitation of Liability 278 | 279 | > Under no circumstances and under no legal theory, whether tort 280 | > (including negligence), contract, or otherwise, shall any 281 | > Contributor, or anyone who distributes Covered Software as 282 | > permitted above, be liable to You for any direct, indirect, 283 | > special, incidental, or consequential damages of any character 284 | > including, without limitation, damages for lost profits, loss of 285 | > goodwill, work stoppage, computer failure or malfunction, or any 286 | > and all other commercial damages or losses, even if such party 287 | > shall have been informed of the possibility of such damages. This 288 | > limitation of liability shall not apply to liability for death or 289 | > personal injury resulting from such party's negligence to the 290 | > extent applicable law prohibits such limitation. Some 291 | > jurisdictions do not allow the exclusion or limitation of 292 | > incidental or consequential damages, so this exclusion and 293 | > limitation may not apply to You. 294 | 295 | 296 | ### 8. Litigation 297 | 298 | Any litigation relating to this License may be brought only in the 299 | courts of a jurisdiction where the defendant maintains its principal 300 | place of business and such litigation shall be governed by laws of that 301 | jurisdiction, without reference to its conflict-of-law provisions. 302 | Nothing in this Section shall prevent a party's ability to bring 303 | cross-claims or counter-claims. 304 | 305 | 306 | ### 9. Miscellaneous 307 | 308 | This License represents the complete agreement concerning the subject 309 | matter hereof. If any provision of this License is held to be 310 | unenforceable, such provision shall be reformed only to the extent 311 | necessary to make it enforceable. Any law or regulation which provides 312 | that the language of a contract shall be construed against the drafter 313 | shall not be used to construe this License against a Contributor. 314 | 315 | 316 | ### 10. Versions of the License 317 | 318 | #### 10.1. New Versions 319 | 320 | Mozilla Foundation is the license steward. Except as provided in Section 321 | 10.3, no one other than the license steward has the right to modify or 322 | publish new versions of this License. Each version will be given a 323 | distinguishing version number. 324 | 325 | #### 10.2. Effect of New Versions 326 | 327 | You may distribute the Covered Software under the terms of the version 328 | of the License under which You originally received the Covered Software, 329 | or under the terms of any subsequent version published by the license 330 | steward. 331 | 332 | #### 10.3. Modified Versions 333 | 334 | If you create software not governed by this License, and you want to 335 | create a new license for such software, you may create and use a 336 | modified version of this License if you rename the license and remove 337 | any references to the name of the license steward (except to note that 338 | such modified license differs from this License). 339 | 340 | #### 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses 341 | 342 | If You choose to distribute Source Code Form that is Incompatible With 343 | Secondary Licenses under the terms of this version of the License, the 344 | notice described in Exhibit B of this License must be attached. 345 | 346 | ## Exhibit A - Source Code Form License Notice 347 | 348 | This Source Code Form is subject to the terms of the Mozilla Public 349 | License, v. 2.0. If a copy of the MPL was not distributed with this 350 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 351 | 352 | If it is not possible or desirable to put the notice in a particular 353 | file, then You may include the notice in a location (such as a LICENSE 354 | file in a relevant directory) where a recipient would be likely to look 355 | for such a notice. 356 | 357 | You may add additional accurate notices of copyright ownership. 358 | 359 | ## Exhibit B - “Incompatible With Secondary Licenses” Notice 360 | 361 | This Source Code Form is "Incompatible With Secondary Licenses", as 362 | defined by the Mozilla Public License, v. 2.0. 363 | 364 | 365 | --------------------------------------------------------------------------------