Skip to content

Commit

Permalink
all basic functionality has minimal testing and passing
Browse files Browse the repository at this point in the history
  • Loading branch information
cmatKhan committed Dec 20, 2023
1 parent 07c4c47 commit aa6ee05
Show file tree
Hide file tree
Showing 38 changed files with 556 additions and 205 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:
- name: Checkout Code Repository
uses: actions/checkout@v4

run: |
ENCODED=$(echo "${{ secrets.ENVS_FILE }}")
echo "Encoded length: ${#ENCODED}"
echo "$ENCODED" | base64 -d > envs.tar.gz
tar -xzvf envs.tar.gz
run: |
ENCODED=$(echo "${{ secrets.ENVS_FILE }}")
echo "Encoded length: ${#ENCODED}"
echo "$ENCODED" | base64 -d > envs.tar.gz
tar -xzvf envs.tar.gz
- name: Build the Stack
run: docker compose -f local.yml build
Expand Down
2 changes: 2 additions & 0 deletions config/api_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
GenomicFeatureViewSet,
PromoterSetSigViewSet,
PromoterSetViewSet,
RankResponseViewSet,
RegulatorViewSet,
)
from yeastregulatorydb.users.api.views import UserViewSet
Expand All @@ -34,6 +35,7 @@
router.register("genomicfeature", GenomicFeatureViewSet)
router.register("promotersetsig", PromoterSetSigViewSet)
router.register("promoterset", PromoterSetViewSet)
router.register("rankresponse", RankResponseViewSet)
router.register("regulator", RegulatorViewSet)


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[flake8]
max-line-length = 119
exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules,venv,.venv
extend-ignore = E203
extend-ignore = E203,E731

[pycodestyle]
max-line-length = 119
Expand Down
51 changes: 41 additions & 10 deletions yeastregulatorydb/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
BindingFactory,
BindingManualQCFactory,
CallingCardsBackgroundFactory,
ChrMapFactory,
DataSourceFactory,
ExpressionFactory,
ExpressionManualQCFactory,
FileFormatFactory,
GenomicFeatureFactory,
PromoterSetFactory,
PromoterSetSigFactory,
RankResponseFactory,
RegulatorFactory,
)
from yeastregulatorydb.users.models import User
Expand Down Expand Up @@ -156,8 +156,16 @@ def datasource(db) -> DataSource:
def fileformat(db) -> QuerySet:
# harb, hu both csvs
format_dict = {
"array": ({"gene_id": "int", "effect": "float", "pval": "float"}, ",", "effect", "pval"),
"qbed": ({"chr": "str", "start": "int", "end": "int", "depth": "int", "strand": "str"}, "\t", "none", "none"),
"array": ({"gene_id": "int", "effect": "float", "pval": "float"}, ",", "effect", 0.0, "pval", 1.0, "none"),
"qbed": (
{"chr": "str", "start": "int", "end": "int", "depth": "int", "strand": "str"},
"\t",
"none",
0.0,
"none",
1.0,
"none",
),
"chipexo_allevents": (
{
"chr": "str",
Expand All @@ -170,7 +178,10 @@ def fileformat(db) -> QuerySet:
},
",",
"YPD_log2Fold",
0.0,
"YPD_log2P",
1.0,
"none",
),
"chipexo_promoter_sig": (
{
Expand All @@ -188,6 +199,7 @@ def fileformat(db) -> QuerySet:
0.0,
"min_pval",
1.0,
"name",
),
"cc_promoter_sig": (
{
Expand All @@ -209,6 +221,7 @@ def fileformat(db) -> QuerySet:
0.0,
"poisson_pval",
1.0,
"name",
),
"kemmeren": (
{"gene_id": "int", "M": "float", "Madj": "float", "A": "float", "pval": "float"},
Expand All @@ -217,6 +230,7 @@ def fileformat(db) -> QuerySet:
0.0,
"pval",
1.0,
"gene_id",
),
"mcisaac": (
{
Expand All @@ -233,6 +247,7 @@ def fileformat(db) -> QuerySet:
0.0,
"none",
1.0,
"gene_id",
),
"bed6": (
{"chr": "str", "start": "int", "end": "int", "name": "str", "score": "float", "strand": "str"},
Expand All @@ -241,27 +256,31 @@ def fileformat(db) -> QuerySet:
0.0,
"none",
1.0,
"name",
),
"rank_response_summary": (
"rankresponse": (
{
"feature": "str",
"expression_effect": "int",
"expression_pvalue": "int",
"binding_effect": "str",
"binding_pvalue": "str",
"expression_effect": "float",
"expression_pvalue": "float",
"expression_source": "str",
"binding_effect": "float",
"binding_pvalue": "float",
"binding_source": "str",
"responsive": "int",
"ran_bin": "float",
"rank_bin": "int",
"random": "float",
},
",",
"none",
0.0,
"none",
1.0,
"feature",
),
}
for key, value in format_dict.items():
fields, separator, effect, effect_thres, pval, pval_thres = value
fields, separator, effect, effect_thres, pval, pval_thres, feature_identifier_col = value
FileFormatFactory.create(
fileformat=key,
fields=fields,
Expand All @@ -270,6 +289,7 @@ def fileformat(db) -> QuerySet:
default_effect_threshold=effect_thres,
pval_col=pval,
default_pvalue_threshold=pval_thres,
feature_identifier_col=feature_identifier_col,
)
return FileFormat.objects.all()

Expand Down Expand Up @@ -318,6 +338,7 @@ def harbison_datasource(db, fileformat: QuerySet) -> DataSource:
def hu_datasource(db, fileformat: QuerySet) -> DataSource:
array = fileformat.filter(fileformat="array").first()
content = {
"id": 101,
"name": "hu_reimann_tfko",
"fileformat": array,
"lab": "hu",
Expand All @@ -344,12 +365,14 @@ def kemmeren_datasource(db, fileformat: QuerySet) -> DataSource:
def mcisaac_datasource(db, fileformat: QuerySet) -> DataSource:
mcisaac = fileformat.filter(fileformat="mcisaac").first()
content = {
"id": 102,
"name": "mcisaac_oe",
"fileformat": mcisaac,
"lab": "mcisaac",
"assay": "overexpression",
"workflow": "none",
}
return DataSourceFactory(**content)


@pytest.fixture
Expand Down Expand Up @@ -384,3 +407,11 @@ def promotersetsig(db) -> PromoterSetSig:
def regulator(db) -> Regulator:
hap5_genomic_feature = GenomicFeatureFactory(locus_tag="YOR358W", symbol="HAP5")
return RegulatorFactory(id=1, regulator=hap5_genomic_feature)


@pytest.fixture
def rankresponse(db, regulator: Regulator) -> QuerySet:
binding = BindingFactory(regulator=regulator)
expression = ExpressionFactory(regulator=regulator)
promotersetsig = PromoterSetSigFactory(binding=binding)
return RankResponseFactory(promotersetsig=promotersetsig, expression=expression)
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ class RankResponseFilter(django_filters.FilterSet):
expression_id = django_filters.NumberFilter(field_name="expression__id")
expression_source = django_filters.CharFilter(field_name="expression__source__name", lookup_expr="iexact")
regulator_locus_tag = django_filters.CharFilter(
field_name="expression__regulator__locus_tag", lookup_expr="iexact"
field_name="expression__regulator__regulator__locus_tag", lookup_expr="iexact"
)
regulator_symbol = django_filters.CharFilter(
field_name="expression__regulator__regulator__symbol", lookup_expr="iexact"
)
regulator_symbol = django_filters.CharFilter(field_name="expression__regulator__symbol", lookup_expr="iexact")
expression_effect_threshold = django_filters.NumberFilter()
expression_pvalue_threshold = django_filters.NumberFilter()
normalized = django_filters.BooleanFilter()
significant_response = django_filters.BooleanFilter()

class Meta:
model = RankResponse
Expand All @@ -34,4 +37,5 @@ class Meta:
"expression_effect_threshold",
"expression_pvalue_threshold",
"normalized",
"significant_response",
]
16 changes: 16 additions & 0 deletions yeastregulatorydb/regulatory_data/api/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,20 @@
from .GenomicFeatureFilter import GenomicFeatureFilter
from .PromoterSetFilter import PromoterSetFilter
from .PromoterSetSigFilter import PromoterSetSigFilter
from .RankResponseFilter import RankResponseFilter
from .RegulatorFilter import RegulatorFilter

__all__ = [
"BindingFilter",
"BindingManualQCFilter",
"CallingCardsBackgroundFilter",
"DataSourceFilter",
"ExpressionFilter",
"ExpressionManualQCFilter",
"FileFormatFilter",
"GenomicFeatureFilter",
"PromoterSetFilter",
"PromoterSetSigFilter",
"RankResponseFilter",
"RegulatorFilter",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pandas as pd
from django.conf import settings
from rest_framework import serializers

from ...models.PromoterSet import PromoterSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"GenomicFeatureSerializer",
"PromoterSetSerializer",
"PromoterSetSigSerializer",
"RankResponseSerializer" "RegulatorSerializer",
"RankResponseSerializer",
"RegulatorSerializer",
]
6 changes: 3 additions & 3 deletions yeastregulatorydb/regulatory_data/api/views/BindingViewSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def perform_create(self, serializer):
task_type = "callingcards_promoter_sig"

if task_type:
lock_id = f"add_data_lock"
acquire_lock = lambda: cache.add(lock_id, True, timeout=60 * 60)
release_lock = lambda: cache.delete(lock_id)
lock_id = "add_data_lock"
acquire_lock = lambda: cache.add(lock_id, True, timeout=60 * 60) # flake8: noqa: E731
release_lock = lambda: cache.delete(lock_id) # flake8: noqa: E731

if acquire_lock():
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from celery import chain
from django.core.cache import cache
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import viewsets
Expand Down Expand Up @@ -32,9 +31,9 @@ def perform_create(self, serializer):
).values_list("id", flat=True)

# Create a chain of tasks for each promotersetsig_id
lock_id = f"add_data_lock"
acquire_lock = lambda: cache.add(lock_id, True, timeout=60 * 60)
release_lock = lambda: cache.delete(lock_id)
lock_id = "add_data_lock"
acquire_lock = lambda: cache.add(lock_id, True, timeout=60 * 60) # flake8: noqa: E731
release_lock = lambda: cache.delete(lock_id) # flake8: noqa: E731

if acquire_lock():
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PromoterSetViewSet(UpdateModifiedMixin, viewsets.ModelViewSet):
def perform_create(self, serializer):
instance = serializer.save()

lock_id = f"add_data_lock"
lock_id = "add_data_lock"
acquire_lock = lambda: cache.add(lock_id, True, timeout=60 * 60)
release_lock = lambda: cache.delete(lock_id)

Expand Down
2 changes: 2 additions & 0 deletions yeastregulatorydb/regulatory_data/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .GenomicFeatureViewSet import GenomicFeatureViewSet
from .PromoterSetSigViewSet import PromoterSetSigViewSet
from .PromoterSetViewSet import PromoterSetViewSet
from .RankResponseViewSet import RankResponseViewSet
from .RegulatorViewSet import RegulatorViewSet

__all__ = [
Expand All @@ -23,5 +24,6 @@
"GenomicFeatureViewSet",
"PromoterSetSigViewSet",
"PromoterSetViewSet",
"RankResponseViewSet",
"RegulatorViewSet",
]
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def bulk_upload(self, request):
file_mapping = {file.name: file for file in files}

df = pd.read_csv(csv_file)
if not "file" in df.columns:
if "file" not in df.columns:
return Response("Column 'file' not found in CSV", status=status.HTTP_400_BAD_REQUEST)

serializer_list = []
Expand Down
4 changes: 4 additions & 0 deletions yeastregulatorydb/regulatory_data/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from .BulkUploadForm import BulkUploadForm

__all__ = [
"BulkUploadForm",
]
Loading

0 comments on commit aa6ee05

Please sign in to comment.