Skip to content

Commit

Permalink
feat: deployed pypi test package
Browse files Browse the repository at this point in the history
  • Loading branch information
dmartmillan committed Oct 8, 2021
1 parent 1848574 commit e14974a
Show file tree
Hide file tree
Showing 51 changed files with 112 additions and 127 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
recursive-exclude tests *
recursive-exclude plugins *
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
Run test:

```bash
python3 -m unittest discover -s test
python3 -m unittest discover -s tests
```
43 changes: 0 additions & 43 deletions main.py

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from typing import List
from yaml import safe_load, YAMLError

from src.annotation.builder import AnnotationTypesBuilders
from src.config.config_annotation import (AnnotationGeneralKeys,
AnnotationKeys,
AnnotationTypes,
ExcludesKeys,
DEFAULT_FORMAT)
from openvariant.annotation.builder import AnnotationTypesBuilders
from openvariant.config.config_annotation import (AnnotationGeneralKeys,
AnnotationKeys,
AnnotationTypes,
ExcludesKeys,
DEFAULT_FORMAT)


def _read_annotation_file(path: str) -> dict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from functools import partial
from typing import List, Tuple, Callable, Any

from src.config.config_annotation import AnnotationTypes, AnnotationKeys
from openvariant.config.config_annotation import AnnotationTypes, AnnotationKeys


class Builder:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from os.path import basename, dirname
from typing import Tuple, Any, List, Optional, Union, Callable

from src.annotation.builder import Builder
from openvariant.annotation.builder import Builder


def _get_text_by_field(x: List, line: List, original_header: List, func: Builder or None):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/task/cat.py → openvariant/task/cat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from src.annotation.annotation import Annotation
from src.utils.format_line import format_line
from src.utils.where import parse_where, skip
from src.variant.variant import Variant
from openvariant.annotation.annotation import Annotation
from openvariant.utils.format_line import format_line
from openvariant.utils.where import parse_where, skip
from openvariant.variant.variant import Variant


def cat(base_path: str, annotation_path: str, where=None) -> None:
Expand Down
8 changes: 4 additions & 4 deletions src/task/count.py → openvariant/task/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from tqdm import tqdm

from src.annotation.annotation import Annotation
from src.task.find import find_files
from src.utils.where import parse_where, skip
from src.variant.variant import Variant
from openvariant.annotation.annotation import Annotation
from openvariant.task.find import find_files
from openvariant.utils.where import parse_where, skip
from openvariant.variant.variant import Variant


def _count_task(selection: Tuple[str, Annotation], group_by: str, where: str) -> Tuple[int, Union[dict, None]]:
Expand Down
4 changes: 2 additions & 2 deletions src/task/find.py → openvariant/task/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from typing import Generator
from copy import deepcopy

from src.annotation.annotation import Annotation, merge_annotations_structure
from openvariant.annotation.annotation import Annotation, merge_annotations_structure

from src.config.config_annotation import ANNOTATION_EXTENSION, DEFAULT_RECURSIVE
from openvariant.config.config_annotation import ANNOTATION_EXTENSION, DEFAULT_RECURSIVE


def _get_annotation_file(annotation: Annotation, file_name: str, file_path: str, base_path: str) -> \
Expand Down
10 changes: 5 additions & 5 deletions src/task/groupby.py → openvariant/task/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from tqdm import tqdm

from src.annotation.annotation import Annotation
from src.task.find import find_files
from src.utils.logger import log
from src.utils.where import skip, parse_where
from src.variant.variant import Variant
from openvariant.annotation.annotation import Annotation
from openvariant.task.find import find_files
from openvariant.utils.logger import log
from openvariant.utils.where import skip, parse_where
from openvariant.variant.variant import Variant


def _get_unique_values(file_path, annotation, key) -> Set:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List

from src.config.config_annotation import AnnotationFormat
from openvariant.config.config_annotation import AnnotationFormat


def format_line(line: List[str], out_format: str) -> str:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/variant/variant.py → openvariant/variant/variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import re
from typing import Generator, TextIO, List

from src.annotation.annotation import Annotation
from src.annotation.parser import AnnotationTypesParsers
from src.config.config_annotation import AnnotationFormat, AnnotationGeneralKeys, ExcludesKeys
from src.utils.logger import log
from openvariant.annotation.annotation import Annotation
from openvariant.annotation.parser import AnnotationTypesParsers
from openvariant.config.config_annotation import AnnotationFormat, AnnotationGeneralKeys, ExcludesKeys
from openvariant.utils.logger import log


def _base_parser(lines: TextIO) -> Generator[int, str, None]:
Expand Down
10 changes: 5 additions & 5 deletions plugins/liftover/liftover.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from liftover import get_lifter
#from liftover import get_lifter


def liftover(text: str) -> str:
converter = get_lifter('hg19', 'hg38')
chrom = '1'
pos = int(text)
#converter = get_lifter('hg19', 'hg38')
#chrom = '1'
#pos = int(text)

return converter[chrom][pos][0][1]
return text #converter[chrom][pos][0][1]
10 changes: 10 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from setuptools import setup, find_packages

setup(
name="open-variant",
version="0.0.2",
author="BBGLab - Barcelona Biomedical Genomics Lab",
packages=find_packages(exclude=['*.tests', '*.tests.*', 'tests.*', 'tests', 'plugins']),
include_package_data=True,
install_requires=['pyyaml'],
)
25 changes: 0 additions & 25 deletions test/test_task/test_find.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ annotation:
# - 'Data'
#- type: 'mapping'
# field: 'F'
# mappingFile: 'test/data/ex.tsv'
# mappingFile: 'tests/data/ex.tsv'
# mappingField: 'DONOR'

exclude:
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions tests/data/meta.bbginfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pattern = "*.maf"
recursive = True

[annotations]
GENOMEREF = "hg19"
#FILTERS = "('internal', 'FILTER')"
#SAMPLE = "('filename', '([^.*]+)\.purple.somatic.vcf.gz')"
#SAMPLE = "('mapping', 'SETNAME', 'metadata_intogen.tsv', 'setName', 'sampleId')"
#DONOR = "('mapping', 'SAMPLE', 'metadata_intogen.tsv', 'sampleId', 'patientId')"
PLATFORM = "WGS"
YEAR = "2020"
#CANCER = "('mapping', 'SAMPLE', 'metadata_intogen.tsv', 'sampleId', 'TUMOR_TYPE')"
#DATASET = "HARTWIG_{PLATFORM}_{CANCER}_{YEAR}"

[excludes]
# Exclude variants that didn't pass the quality control checks
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 13 additions & 13 deletions test/test_task/test_count.py → tests/test_task/test_count.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
import unittest

from src.task.count import count
from openvariant.task.count import count


class TestCount(unittest.TestCase):

# Count functionality
def test_count(self):
res = count('./test/data/', 'test/data/task_test.yaml', quite=True)
res = count('./tests/data/', 'tests/data/task_test.yaml', quite=True)
self.assertEqual(res[0], 42130, "Count number not matching")
self.assertEqual(res[1], {}, "Count groups not matching")

def test_invalid_count(self):
with self.assertRaises(FileNotFoundError):
res = count('test/data/no-exist', 'test/data/no-exist.yaml', quite=True)
res = count('tests/data/no-exist', 'tests/data/no-exist.yaml', quite=True)

# Using where attribute
def test_count_equal_where(self):
res = count('./test/data/', 'test/data/task_test.yaml', where="DATASET == \"acc\"", quite=True)
res = count('./tests/data/', 'tests/data/task_test.yaml', where="DATASET == \"acc\"", quite=True)
self.assertEqual(res[0], 11660, "Count number not matching")
self.assertEqual(res[1], {}, "Count groups not matching")

def test_count_non_equal_where(self):
res = count('./test/data/', 'test/data/task_test.yaml', where="DATASET != \"acc\"", quite=True)
res = count('./tests/data/', 'tests/data/task_test.yaml', where="DATASET != \"acc\"", quite=True)
self.assertEqual(res[0], 30470, "Count number not matching")
self.assertEqual(res[1], {}, "Count groups not matching")

def test_count_little_than_where(self):
res = count('./test/data/', 'test/data/task_test.yaml', where="A < 52366244", quite=True)
res = count('./tests/data/', 'tests/data/task_test.yaml', where="A < 52366244", quite=True)
self.assertEqual(res[0], 17734, "Count number not matching")
self.assertEqual(res[1], {}, "Count groups not matching")

def test_count_leq_than_where(self):
res = count('./test/data/', 'test/data/task_test.yaml', where="A <= 52366244", quite=True)
res = count('./tests/data/', 'tests/data/task_test.yaml', where="A <= 52366244", quite=True)
self.assertEqual(res[0], 17735, "Count number not matching")
self.assertEqual(res[1], {}, "Count groups not matching")

def test_count_great_than_where(self):
res = count('./test/data/', 'test/data/task_test.yaml', where="A > 52366244", quite=True)
res = count('./tests/data/', 'tests/data/task_test.yaml', where="A > 52366244", quite=True)
self.assertEqual(res[0], 24395, "Count number not matching")
self.assertEqual(res[1], {}, "Count groups not matching")

def test_count_geq_than_where(self):
res = count('./test/data/', 'test/data/task_test.yaml', where="A >= 52366244", quite=True)
res = count('./tests/data/', 'tests/data/task_test.yaml', where="A >= 52366244", quite=True)
self.assertEqual(res[0], 24396, "Count number not matching")
self.assertEqual(res[1], {}, "Count groups not matching")

def test_count_no_exist_where(self):
res = count('./test/data/', 'test/data/task_test.yaml', where="NO_EXIST == \"no_exist\"", quite=True)
res = count('./tests/data/', 'tests/data/task_test.yaml', where="NO_EXIST == \"no_exist\"", quite=True)
self.assertEqual(res[0], 0, "Count number not matching")
self.assertEqual(res[1], {}, "Count groups not matching")

def test_count_bad_syntax_where(self):
with self.assertRaises(ValueError):
count('./test/data/', 'test/data/task_test.yaml', where="NO_EXIST = \"no_exist\"", quite=True)
count('./tests/data/', 'tests/data/task_test.yaml', where="NO_EXIST = \"no_exist\"", quite=True)

# Using group by attribute
def test_count_group_by(self):
res = count('./test/data/', 'test/data/task_test.yaml', group_by="DATASET", quite=True)
res = count('./tests/data/', 'tests/data/task_test.yaml', group_by="DATASET", quite=True)
self.assertEqual(res[0], 42130, "Count number not matching")
self.assertEqual(res[1], {'kich': 3268, 'chol': 4500, 'meso': 3980, 'laml': 8313, 'acc': 11660, 'ucs': 10409},
"Count groups not matching")

def test_count_invalid_group_by(self):
res = count('./test/data/', 'test/data/task_test.yaml', group_by="NO_EXIST", quite=True)
res = count('./tests/data/', 'tests/data/task_test.yaml', group_by="NO_EXIST", quite=True)
self.assertEqual(res[0], 0, "Count number not matching")
self.assertEqual(res[1], {}, "Count groups not matching")

Expand Down
25 changes: 25 additions & 0 deletions tests/test_task/test_find.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest
from os import getcwd

from openvariant.annotation.annotation import Annotation
from openvariant.task.find import find_files


class TestFind(unittest.TestCase):

def test_find_files(self):
res_expect = {'tests/data/example2/KICH.maf', 'tests/data/example2/LAML.maf', 'tests/data/example1/ACC.maf',
'tests/data/example1/CHOL.maf', 'tests/data/example3/MESO.maf', 'tests/data/example3/UCS.maf'}

annotation = Annotation('tests/data/example.yaml')
res = set([f for f, a in list(find_files('tests/data', annotation))])
self.assertEqual(res, res_expect)

def test_invalid_find_files(self):
annotation = Annotation('tests/data/example.yaml')
with self.assertRaises(FileNotFoundError):
set([f for f, a in list(find_files('tests/data/no-exist', annotation))])


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit e14974a

Please sign in to comment.