Skip to content

Commit

Permalink
modules and filter tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
cmatKhan committed Dec 12, 2023
1 parent 97dbb98 commit 735dd6d
Show file tree
Hide file tree
Showing 18 changed files with 642 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ class BindingFilter(django_filters.FilterSet):
id = django_filters.NumberFilter()
pk = django_filters.NumberFilter()
regulator = django_filters.NumberFilter()
regulator_locus_tag = django_filters.CharFilter(field_name="regulator__locus_tag", lookup_expr="iexact")
regulator_symbol = django_filters.CharFilter(field_name="regulator__symbol", lookup_expr="iexact")
regulator_locus_tag = django_filters.CharFilter(field_name="regulator__regulator__locus_tag", lookup_expr="iexact")
regulator_symbol = django_filters.CharFilter(field_name="regulator__regulator__symbol", lookup_expr="iexact")
batch = django_filters.CharFilter(lookup_expr="iexact")
# pylint: enable=R0801
replicate = django_filters.NumberFilter()
source = django_filters.NumberFilter()
source_orig_id = django_filters.CharFilter(lookup_expr="iexact")
strain = django_filters.CharFilter(lookup_expr="iexact")
lab = django_filters.CharFilter(field_name="source__lab", lookup_expr="iexact")
assay = django_filters.CharFilter(field_name="source__assay", lookup_expr="iexact")
workflow = django_filters.CharFilter(field_name="source__workflow", lookup_expr="iexact")
Expand All @@ -32,6 +33,7 @@ class Meta:
"replicate",
"source",
"source_orig_id",
"strain",
"lab",
"assay",
"workflow",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ class ExpressionFilter(django_filters.FilterSet):
id = django_filters.NumberFilter()
pk = django_filters.NumberFilter()
regulator = django_filters.NumberFilter()
regulator_locus_tag = django_filters.CharFilter(field_name="regulator__locus_tag", lookup_expr="iexact")
regulator_symbol = django_filters.CharFilter(field_name="regulator__symbol", lookup_expr="iexact")
regulator_locus_tag = django_filters.CharFilter(field_name="regulator__regulator__locus_tag", lookup_expr="iexact")
regulator_symbol = django_filters.CharFilter(field_name="regulator__regulator__symbol", lookup_expr="iexact")
batch = django_filters.CharFilter(field_name="batch", lookup_expr="iexact")
# pylint: enable=R0801
replicate = django_filters.NumberFilter()
control = django_filters.CharFilter(lookup_expr="iexact")
mechanism = django_filters.CharFilter(lookup_expr="iexact")
restriction = django_filters.CharFilter(lookup_expr="iexact")
time = django_filters.NumberFilter(field_name="time")
source = django_filters.CharFilter(lookup_expr="iexact")
source = django_filters.NumberFilter()
lab = django_filters.CharFilter(field_name="source__lab", lookup_expr="iexact")
assay = django_filters.CharFilter(field_name="source__assay", lookup_expr="iexact")
workflow = django_filters.CharFilter(field_name="source__workflow", lookup_expr="iexact")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ class ExpressionManualQCFilter(django_filters.FilterSet):
expression = django_filters.NumberFilter()
strain_verified = django_filters.ChoiceFilter(choices=[("yes", "yes"), ("no", "no"), ("unverified", "unverified")])
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")
batch = django_filters.CharFilter(field_name="expression__batch", lookup_expr="iexact")
replicate = django_filters.NumberFilter(field_name="expression__replicate")
control = django_filters.CharFilter(field_name="expression__control", lookup_expr="iexact")
mechanism = django_filters.CharFilter(field_name="expression__mechanism", lookup_expr="iexact")
restriction = django_filters.CharFilter(field_name="expression__restriction", lookup_expr="iexact")
time = django_filters.NumberFilter(field_name="expression__time")
source = django_filters.CharFilter(field_name="expression__source", lookup_expr="iexact")
source = django_filters.NumberFilter(field_name="expression__source__id")
lab = django_filters.CharFilter(field_name="expression__source__lab", lookup_expr="iexact")
assay = django_filters.CharFilter(field_name="expression__source__assay", lookup_expr="iexact")
workflow = django_filters.CharFilter(field_name="expression__source__workflow", lookup_expr="iexact")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ExpressionSourceFilter(django_filters.FilterSet):
id = django_filters.NumberFilter()
pk = django_filters.NumberFilter()
fileformat_id = django_filters.NumberFilter()
fileformat = django_filters.CharFilter(field_name="fileformat_id__fileformat", lookup_expr="iexact")
fileformat = django_filters.CharFilter(field_name="fileformat__fileformat", lookup_expr="iexact")
lab = django_filters.CharFilter(lookup_expr="iexact")
assay = django_filters.CharFilter(lookup_expr="iexact")
workflow = django_filters.CharFilter(lookup_expr="iexact")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class GenomicFeatureFilter(django_filters.FilterSet):
end = django_filters.NumberFilter()
strand = django_filters.CharFilter(lookup_expr="exact")
type = django_filters.CharFilter(lookup_expr="iexact")
gene_biotype = django_filters.CharFilter(lookup_expr="iexact")
biotype = django_filters.CharFilter(lookup_expr="iexact")
locus_tag = django_filters.CharFilter(lookup_expr="iexact")
gene = django_filters.CharFilter(lookup_expr="iexact")
symbol = django_filters.CharFilter(lookup_expr="iexact")
source = django_filters.CharFilter(lookup_expr="iexact")
alias = django_filters.CharFilter(lookup_expr="iexact")
note = django_filters.CharFilter(lookup_expr="iexact")
Expand All @@ -24,9 +24,9 @@ class Meta:
"end",
"strand",
"type",
"gene_biotype",
"biotype",
"locus_tag",
"gene",
"symbol",
"source",
"alias",
"note",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ class PromoterSetSigFilter(django_filters.FilterSet):
id = django_filters.NumberFilter()
pk = django_filters.NumberFilter()
binding = django_filters.NumberFilter()
promoter_id = django_filters.NumberFilter()
promoter_name = django_filters.CharFilter(field_name="promoter_id__name", lookup_expr="iexact")
background_id = django_filters.NumberFilter(field_name="background_id")
promoter = django_filters.NumberFilter()
promoter_name = django_filters.CharFilter(field_name="promoter__name", lookup_expr="iexact")
background = django_filters.NumberFilter()
background_name = django_filters.CharFilter(field_name="background_id__name", lookup_expr="iexact")
regulator_locus_tag = django_filters.CharFilter(field_name="binding__regulator__locus_tag", lookup_expr="iexact")
regulator_symbol = django_filters.CharFilter(field_name="binding__regulator__symbol", lookup_expr="iexact")
regulator_locus_tag = django_filters.CharFilter(
field_name="binding__regulator__regulator__locus_tag", lookup_expr="iexact"
)
regulator_symbol = django_filters.CharFilter(
field_name="binding__regulator__regulator__symbol", lookup_expr="iexact"
)
batch = django_filters.CharFilter(field_name="binding__batch", lookup_expr="iexact")
replicate = django_filters.NumberFilter(field_name="binding__replicate")
source = django_filters.NumberFilter(field_name="binding__source")
Expand Down
12 changes: 12 additions & 0 deletions yeastregulatorydb/regulatory_data/api/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .BindingFilter import BindingFilter
from .BindingManualQCFilter import BindingManualQCFilter
from .BindingSourceFilter import BindingSourceFilter
from .CallingCardsBackgroundFilter import CallingCardsBackgroundFilter
from .ExpressionFilter import ExpressionFilter
from .ExpressionManualQCFilter import ExpressionManualQCFilter
from .ExpressionSourceFilter import ExpressionSourceFilter
from .FileFormatFilter import FileFormatFilter
from .GenomicFeatureFilter import GenomicFeatureFilter
from .PromoterSetFilter import PromoterSetFilter
from .PromoterSetSigFilter import PromoterSetSigFilter
from .RegulatorFilter import RegulatorFilter
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ class Meta:
fields = "__all__"

def get_background_id(self, obj):
return obj.background_id.id if obj.background_id else "undefined"
return obj.background.id if obj.background else "undefined"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.8 on 2023-12-12 18:50

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("regulatory_data", "0001_initial"),
]

operations = [
migrations.RenameField(
model_name="bindingsource",
old_name="fileformat_id",
new_name="fileformat",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.8 on 2023-12-12 18:53

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("regulatory_data", "0002_rename_fileformat_id_bindingsource_fileformat"),
]

operations = [
migrations.RenameField(
model_name="expressionsource",
old_name="fileformat_id",
new_name="fileformat",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.8 on 2023-12-12 21:56

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("regulatory_data", "0003_rename_fileformat_id_expressionsource_fileformat"),
]

operations = [
migrations.RenameField(
model_name="promotersetsig",
old_name="background_id",
new_name="background",
),
migrations.RenameField(
model_name="promotersetsig",
old_name="promoter_id",
new_name="promoter",
),
migrations.AlterField(
model_name="expression",
name="control",
field=models.CharField(
choices=[("undefined", "undefined"), ("wt", "wt"), ("wt_meta", "wt_meta")],
default="undefined",
help_text="Intended for micro-array data, this field records the control strain used to generate the relative intensity data",
),
),
]
6 changes: 6 additions & 0 deletions yeastregulatorydb/regulatory_data/models/BaseModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ class MyModel(BaseModel):
class Meta:
abstract = True

def save(self, *args, **kwargs):
# If the record is being created, set the modifier to the uploader
if self._state.adding:
self.modifier = self.uploader
super().save(*args, **kwargs)


@receiver(pre_save, sender=BaseModel)
def update_modified_date(sender, instance, **kwargs): # pylint: disable=unused-argument
Expand Down
2 changes: 1 addition & 1 deletion yeastregulatorydb/regulatory_data/models/BindingSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BindingSource(BaseModel):
Store binding data source information
"""

fileformat_id = models.ForeignKey(
fileformat = models.ForeignKey(
"FileFormat",
on_delete=models.CASCADE,
help_text="Foreign key to the FileFormat table",
Expand Down
2 changes: 1 addition & 1 deletion yeastregulatorydb/regulatory_data/models/Expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Expression(BaseModel, FileUploadMixin):
)
replicate = models.PositiveIntegerField(default=1, help_text="Replicate number")
control = models.CharField(
choices=[("undefined", "undefined"), ("wt", "wt"), ("wt_mata", "wt_mata")],
choices=[("undefined", "undefined"), ("wt", "wt"), ("wt_meta", "wt_meta")],
default="undefined",
help_text="Intended for micro-array data, this field records the "
"control strain used to generate the relative intensity data",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ExpressionSource(BaseModel):
Store expression data source information
"""

fileformat_id = models.ForeignKey(
fileformat = models.ForeignKey(
"FileFormat", on_delete=models.CASCADE, help_text="foreign key to the fileformat table"
)
lab = models.CharField(
Expand Down
9 changes: 3 additions & 6 deletions yeastregulatorydb/regulatory_data/models/PromoterSetSig.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class PromoterSetSig(BaseModel, FileUploadMixin):
"""

binding = models.ForeignKey("Binding", on_delete=models.CASCADE, help_text="foreign key to the 'Binding' table")
promoter_id = models.ForeignKey(
promoter = models.ForeignKey(
"PromoterSet", on_delete=models.CASCADE, help_text="foreign key to the 'promoter' table"
)
# note: in the serializer, when a user makes a GET request, a null value
# is transformed to the string 'undefined' prior to returning to client
background_id = models.ForeignKey(
background = models.ForeignKey(
"CallingCardsBackground",
on_delete=models.CASCADE,
blank=True,
Expand All @@ -34,10 +34,7 @@ class PromoterSetSig(BaseModel, FileUploadMixin):
file = models.FileField(upload_to="temp", help_text="A file which stores data on " "regulator/DNA interaction")

def __str__(self):
return (
f"pk:{self.pk};binding:{self.binding};"
f"promoter_id:{self.promoter_id};background_id:{self.background_id}"
)
return f"pk:{self.pk};binding:{self.binding};" f"promoter_id:{self.promoter};background:{self.background}"

class Meta:
db_table = "promotersetsig"
Expand Down
25 changes: 16 additions & 9 deletions yeastregulatorydb/regulatory_data/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import faker
from factory import Faker, SubFactory
from factory import Faker, LazyFunction, SubFactory
from factory.django import DjangoModelFactory, FileField

from yeastregulatorydb.users.tests.factories import UserFactory
Expand All @@ -23,6 +23,13 @@
fake = faker.Faker()


def sentence_with_max_chars(max_chars=100):
sentence = fake.sentence(nb_words=10)
if len(sentence) > max_chars:
sentence = sentence[:max_chars].rsplit(" ", 1)[0] + "."
return sentence


class ChrMapFactory(DjangoModelFactory):
uploader = SubFactory(UserFactory)
modifier = SubFactory(UserFactory)
Expand Down Expand Up @@ -97,7 +104,7 @@ class Meta:
class ExpressionSourceFactory(DjangoModelFactory):
uploader = SubFactory(UserFactory)
modifier = SubFactory(UserFactory)
fileformat_id = SubFactory(FileFormatFactory)
fileformat = SubFactory(FileFormatFactory)
lab = Faker("word")
assay = Faker("word")
workflow = Faker("word")
Expand All @@ -107,7 +114,7 @@ class ExpressionSourceFactory(DjangoModelFactory):

class Meta:
model = ExpressionSource
django_get_or_create = ["fileformat_id"]
django_get_or_create = ["fileformat"]


class ExpressionFactory(DjangoModelFactory):
Expand Down Expand Up @@ -158,7 +165,7 @@ class Meta:
class BindingSourceFactory(DjangoModelFactory):
uploader = SubFactory(UserFactory)
modifier = SubFactory(UserFactory)
fileformat_id = SubFactory(FileFormatFactory)
fileformat = SubFactory(FileFormatFactory)
lab = Faker("pystr", max_chars=20)
assay = Faker("pystr", max_chars=20)
workflow = Faker("pystr", max_chars=50)
Expand All @@ -168,7 +175,7 @@ class BindingSourceFactory(DjangoModelFactory):

class Meta:
model = BindingSource
django_get_or_create = ["fileformat_id", "lab", "assay", "workflow"]
django_get_or_create = ["fileformat", "lab", "assay", "workflow"]


class BindingFactory(DjangoModelFactory):
Expand Down Expand Up @@ -211,7 +218,7 @@ class PromoterSetFactory(DjangoModelFactory):
modifier = SubFactory(UserFactory)
name = Faker("pystr", max_chars=10)
file = FileField(filename="testfile.bed.gz")
notes = Faker("sentence", nb_words=10)
notes = LazyFunction(sentence_with_max_chars)

class Meta:
model = PromoterSet
Expand All @@ -222,11 +229,11 @@ class PromoterSetSigFactory(DjangoModelFactory):
uploader = SubFactory(UserFactory)
modifier = SubFactory(UserFactory)
binding = SubFactory(BindingFactory)
promoter_id = SubFactory(PromoterSetFactory)
background_id = SubFactory(CallingCardsBackgroundFactory)
promoter = SubFactory(PromoterSetFactory)
background = SubFactory(CallingCardsBackgroundFactory)
filetype = SubFactory(FileFormatFactory)
file = FileField(filename="testfile.tsv.gz")

class Meta:
model = PromoterSetSig
django_get_or_create = ["binding", "promoter_id", "background_id"]
django_get_or_create = ["binding", "promoter", "background"]
Loading

0 comments on commit 735dd6d

Please sign in to comment.