# -*- coding: utf-8 -*-
from setuptools import setup

package_dir = \
{'': 'src'}

packages = \
['covsonar']

package_data = \
{'': ['*'], 'covsonar': ['data/*']}

install_requires = \
['biopython>=1.79,<1.80',
 'more-itertools>=8.7.0,<8.8.0',
 'mpire>=2.3.3,<2.4.0',
 'pandas>=1.4.0,<1.5.0',
 'pyaml>=20.4.0,<20.5.0',
 'requests>=2.28.0,<3.0.0',
 'tabulate>=0.8.9,<0.9.0',
 'tqdm>=4.59.0,<4.60.0']

entry_points = \
{'console_scripts': ['sonar = covsonar.sonar:run']}

setup_kwargs = {
    'name': 'covsonar',
    'version': '2.0.0a0',
    'description': 'A database-driven system for handling genomic sequences and screening genomic profiles.',
    'long_description': '<img src="logo.png"  width="134" height="134" align="right"><br><br><br><br><br>\n\n# covSonar2\n\ncovSonar is a database-driven system for handling genomic sequences and screening genomic profiles.\n\nWhat\'s new in covSonar V.2\n* New design\n    * Improve workflows\n    * Performance improvements\n* Exciting new features\n\t* Support multiple pathogens\n\t* Flexible in adding meta information \n* New database design\n\t* New database schema \n    * Retrieval efficiency\n\t* Significantly smaller than the previous version\n\n## 1. Prerequisites / Setup\n\ncovSonar2 has some software-environmental requirements that can most easily be met by building a custom conda environment.\n\nProceed as follows to install covSonar:\n```sh\n# download the repository to the current working directory using git \ngit clone https://github.com/rki-mf1/covsonar\n# build the custom software environment using conda [recommended]\nconda env create -n sonar2 -f covsonar/sonar.env.yml\n# activate the conda evironment if built \nconda activate sonar2\n# testing\n./covsonar/test.sh\n```\n\n## 3. Usage\n\nIn covSonar2 there are several tools that can be called via subcommands.  \n\n| subcommand | purpose                                                             |\n|------------|---------------------------------------------------------------------|\n| setup      | setup a new database.                             |\n| import     | import genome sequences and sample information to the database     |\n| list-prop  | view sample properties added to the database             | \n| add-prop    | add a sample property to the database                    |\n| delete-prop       | delete a sample property from the database |\n| match   |  get mutations profiles for given accessions                                        |\n| restore   | restore sequence(s) from the database                                         |\n| info   |  show software and database info.                                        |\n| optimize   | optimizes the database                                         |\n| db-upgrade   | upgrade a database to the latest version                                         |\n| update-lineage-info | download latest lineage information                                       |\n\nEach tool provides a help page that can be accessed with the `-h` option.\n\n```sh\n# display help page\n./sonar.py -h \n# display help page for each tool\n./sonar.py import -h \n```\n\n### 3.1 Setup database (setup ⛽)\nFirst, we have to create a new database instance.\n```sh\n./sonar.py setup --db test.db\n```\n\n, or we can create a new database instance with predefined properties.\n```sh\n./sonar.py setup --db test.db --auto-create\n```\n\nBy default, the MN908947.3 (SARS-CoV-2) is used as a reference. If we want to set up database for a different pathogen, we can add `--gbk` following with Genbank file.\n\nexample;\n```sh\n./sonar.py setup --db test.db --auto-create --gbk Ebola.gb\n```\n\n>  note 📌:  [how to download genbank file](https://ncbiinsights.ncbi.nlm.nih.gov/2017/05/08/genome-data-download-made-easy/)\n\n### 3.2 Property management (list-prop, add-prop, delete-prop)\n\nIn covSonar2, users now can arbitrarily add meta information or properties into a database to fit a specific project objective.s\n\nTo view the added properties, we can use the `list-prop` command to display all information.\n```sh\n./sonar.py list-prop --db test.db \n```\n\nTo add more properties, we can use the `add-prop` command to add meta information into the database.\n\nThe required arguments are listed below when we use `add-prop`\n* `--name`, name of sample property\n* `--descr`, description of the new property\n* `--dtype`, data type of the new property (e.g., \'integer\', \'float\', \'text\', \'date\', \'zip\')\n\n```sh\n./sonar.py add-prop --db test.db  --name SEQ_REASON --dtype text --descr "seq. reason"\n```\n> tip 🕯️:  `./sonar.py add-prop -h ` to see all available   arguments\n\n\nThe `delete-prop` command is used to delete an unwanted property from the database.\n\n```sh\n./sonar.py delete-prop --db test.db  --name SEQ_REASON\n```\n\nThe program will ask an user for confirmation of the action.\n```\nDo you really want to delete this property? [YES/no]: YES\n```\n\n### 3.3 Adding genomes and meta information to the database (import)\n\nAdd sequence with meta information \n\n```sh\n./sonar.py import --db test.db --fasta valid.fasta --tsv day.tsv --threads 64 --cache tmp_cache --cols sample=IMS_ID\n```\n\nUpdate more\n\nexample:\n```sh\n\n./sonar.py import --db test.db --fasta valid.fasta --tsv day.tsv --threads 64 --cache tmp_cache --cols sample=IMS_ID\n\n./sonar.py import --db test.db --fasta valid.fasta --tsv day.tsv --threads 64 --cache tmp_cache --cols sample=IMS_ID\n```\n\n\n`sample` \n\n### 3.4 Query genome sequences based on profiles (match)\n\nGenomic profiles can be defined to align genomes. For this purpose, the variants related to the complete genome of the SARS-CoV-2 isolate Wuhan-Hu-1 (NC_045512.2) must be expressed as follows:\n\n| type       | nucleotide level                                                  | amino acid level              |\n|-----------|-------------------------------------------------------------------|-------------------------------|\n| SNP       | ref_nuc _followed by_ ref_pos _followed by_ alt_nuc (e.g. A3451T) | protein_symbol:ref_aa _followed by_ ref_pos _followed by_ alt_aa (e.g. S:N501Y) |\n| deletion  | del:ref_pos:length_in_bp (e.g. del:3001:8)                        | protein_symbol:del:ref_pos:length_in_aa (e.g. ORF1ab:del:3001:21) | \n| insertion | ref_nuc _followed by_ ref_pos _followed by_ alt_nucs (e.g. A3451TGAT) | protein_symbol:ref_aa _followed by_ ref_pos _followed by_ alt_aas (e.g. N:A34AK)  |  \n\nThe positions refer to the reference (first nucleotide in the genome is position 1). Using the option `--profile`, multiple variant definitions can be combined into a nucleotide, amino acid or mixed profile, which means that matching genomes must have all those variations in common. In contrast, alternative variations can be defined by multiple `--profile` options. As an example, `--profile S:N501Y S:E484K` matches genomes sharing the _Nelly_ **AND** _Erik_ variation while `--profile S:N501Y --profile S:E484K` matches to genomes that share either the _Nelly_ **OR** _Erik_ variation **OR** both. Accordingly, using the option **^** profiles can be defined that have not to be present in the matched genomes. \n\n\nThere are additional options to adjust the matching.\n\n| option             | description                                                            |\n|--------------------|------------------------------------------------------------------------|\n| --count            | count matching genomes only                                            |\n\n\nexample;\n```sh\n./sonar.py match --profile S:E484K --LINEAGE B.1.1.7 --db test.db\n\n# matching B.1.1.7 genomes in DB \'test.db\' that share an additional "Erik" mutation \n./sonar.py match --profile S:E484K --LINEAGE B.1.1.7 --db test.db\n\n# as before but matching genomes are counted only\n./sonar.py match --profile S:E484K --LINEAGE B.1.1.7 --count --db test.db\n\n# matching genomes in DB \'test.db\' sharing the "Nelly" mutation\n# and that were sampled in 2020\n./sonar.py match --profile S:N501Y  --DATE 2020-01-01:2020-12-31 --db test.db\n\n# matching genomes in DB \'mydb\' sharing the "Nelly" and the "Erik" mutation but not\n# belonging to the B.1.1.7 lineage\n./sonar.py match -profile S:N501Y S:E484K --LINEAGE ^B.1.1.7 --db test.db\n```\n\n**Export to CSV/TSV/VCF file**\n\ncovSonar can return results in different formats: `--format ["csv", "tsv", "vcf"]`\n\n```sh\n# example command\n./sonar.py match --profile S:N501Y S:E484K --LINEAGE ^B.1.1.7 --db test.db --format csv -o out.csv\n\n# in vcf format\n./sonar.py match -i S:N501Y S:E484K --lineage Q.1 --db test.db --format vcf -o out.vcf\n\n# example of --sample-file \n./sonar.py match --sample-file accessions.txt --db test.db --format vcf -o out.vcf\n```\n\n\n\n#### <u>Parent-Child relationship</u>\n\n> ⚠️ This function we only test on SARS-CoV-2\n\nIf we want to search all sublineages with a given lineage, covSonar offers `--with-sublineage PROP_COLUMN` (PROP_COLUMN  means the property name that we added to our database).\n\n```sh\n./sonar.py match --profle S:E484K --LINEAGE B.1.1.7 --with-sublineage LINEAGE --count --db test.db --debug\n```\nThis query will return results (\'B.1.1.7\', \'Q.4\', \'Q.5\', \'Q.3\', \'Q.6\', \'Q.1\', \'Q.7\', \'Q.2\', \'Q.8\').\n\nBy default, we use SARS-CoV-2 lineages for this search and the file name must be `lineage.all.tsv`.\n\n**lineage-update function for SARS-CoV-2 (COVID-19) ❗**\n\nRun `update-lineage-info` flag, it will download the latest version of lineages from https://github.com/cov-lineages/pango-designation/ and install it in `lib/lineage.all.tsv`\n\n```sh\n# example command\n./sonar.py update-lineage-info\n```\n\n### 3.5 Show infos about the used sonar system and database (info)\n\nDetailed infos about the used sonar system (e.g. version, reference,  number of imported genomes, unique sequences, available metadata).\n\n```sh\n# Show infos about the used sonar system and database \'test.db\'\n./sonar.py info --db test.db \n```\n\n### 3.6 Restore genome sequences from the database (restore)\nGenome sequences can be restored from the database based on their accessions.\nThe restored sequences are combined with their original FASTA header and  shown on the screen. The screen output can be redirected to a file easily by using `>`.\n\n```sh\n# Restore genome sequences linked to accessions \'mygenome1\' and \'mygenome2\' from the \n# database \'test.db\' and write these to a fasta file named \'restored.fasta\'\n./sonar.py restore --sample mygenome1 mygenome2 --db test.db > restored.fasta\n# as before, but consider all accessions from \'accessions.txt\' (the file has to\n# contain one accession per line) \n./sonar.py restore --sample-file accessions.txt --db test.db > restored.fasta\n```\n\n### 3.7 Database management (db-upgrade, optimize)\nSometimes you might need the `optimize` command to clean the [problems](https://www.sqlite.org/lang_vacuum.html) from database operation (e.g., unused data block or storage overhead ).\n```sh\n# Show infos about the used sonar system\n./sonar.py optimize  --db test.db \n```\n\nWhen the newest version of covSonar use an old database version, covSonar will return  the following error;\n```bash\nCompatibility error: the given database is not compatible with this version of sonar (Current database version: XXX; Supported database version: XXX)\nPlease run \'sonar.py  db-upgrade\' to upgrade database\n```\n\nWe provide our database upgrade assistant to solve the problem. \n```bash \n# RUN \n./sonar.py db-upgrade --db test.db\n\n# Output\nWarning: Backup db file before upgrading, Press Enter to continue...\n\n## after pressing the Enter key\nCurrent version: 3  Upgrade to: 4\nPerform the Upgrade: file: mydb.db\nDatabase now version: 4\nSuccess: Database upgrade was successfully completed\n\n```\n⚠️ Warning: Backup the db file before upgrade.\n\n\n## How to contribute 🏗️ \n\ncovSonar has been very carefully programmed and tested, but is still in an early stage of development. You can contribute to this project by reporting problems 🐛 or writing feature requests to the [issue section](https://github.com/rki-mf1/covsonar/issues) 👨\u200d💻\n\nYour feedback is very welcome 👨\u200d🔧!\n\n---------------------------------\n\n## Contact\n\nFor business inquiries or professional support requests 🍺 please contact [Dr. Stephan Fuchs](https://www.rki.de/SharedDocs/Personen/Mitarbeiter/F/Fuchs_Stephan.html)\n\n',
    'author': 'Stephan Fuchs',
    'author_email': 'FuchsS@rki.de',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/rki-mf1/covsonar',
    'package_dir': package_dir,
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'entry_points': entry_points,
    'python_requires': '>=3.9,<4.0',
}


setup(**setup_kwargs)
