From 9f58cf48ee04813a0fd20a246d68887e49b832d4 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Wed, 4 Mar 2009 02:26:05 +0000 Subject: [PATCH] Implement experiment type as a seperate table. closes [ticket:107] also initialize the experiment type table with the conversion script --- docs/conv_caltech_v0.1_to_htsw.py | 23 +++++++++++++++++++---- htsworkflow/frontend/samples/admin.py | 8 +++++++- htsworkflow/frontend/samples/models.py | 19 +++++++------------ 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/docs/conv_caltech_v0.1_to_htsw.py b/docs/conv_caltech_v0.1_to_htsw.py index 15e6d84..2adb036 100644 --- a/docs/conv_caltech_v0.1_to_htsw.py +++ b/docs/conv_caltech_v0.1_to_htsw.py @@ -97,6 +97,19 @@ def main(cmdline=None): "notes" text NOT NULL);''') c.execute('''insert into samples_condition (condition_name,notes) values("Unknown","Unknown");''') + # create samples.experiment type + c.execute('''CREATE TABLE "samples_experimenttype" ( + "id" integer NOT NULL PRIMARY KEY, + "name" varchar(50) NOT NULL UNIQUE);''') + for et in [ ('Unknown',), + ('ChIP-seq',), + ('Sheared',), + ('RNA-seq',), + ('Methyl-seq',), + ('DIP-seq',), + ('De Novo',)]: + c.execute('insert into samples_experimenttype (name) values (?)', et) + # create samples.library c.execute('''CREATE TABLE "samples_library" ( "id" integer NOT NULL PRIMARY KEY, @@ -107,7 +120,7 @@ def main(cmdline=None): "condition_id" integer NOT NULL REFERENCES "samples_condition" ("id"), "antibody_id" integer NULL REFERENCES "samples_antibody" ("id"), "replicate" smallint unsigned NOT NULL, - "experiment_type" varchar(50) NOT NULL, + "experiment_type_id" NOT NULL REFERENCES "samples_experimenttype" ("id"), "creation_date" date NULL, "made_for" varchar(50) NOT NULL, "made_by" varchar(50) NOT NULL, @@ -119,17 +132,19 @@ def main(cmdline=None): "avg_lib_size" integer NULL, "notes" text NOT NULL);''') c.execute('''INSERT INTO samples_library - (id,library_id,library_name,library_species_id, experiment_type, + (id,library_id,library_name,library_species_id, experiment_type_id, cell_line_id,condition_id,replicate,made_by,creation_date, made_for,stopping_point,amplified_from_sample_id, undiluted_concentration,ten_nM_dilution,successful_pM, avg_lib_size,notes) -select library_id,library_id,library_name,library_species_id,"unknown", +select library_id,library_id,library_name,library_species_id, 1, 1, 1, 1, made_by,creation_date, made_for,stopping_point,amplified_from_sample_id, undiluted_concentration,ten_nM_dilution,successful_pM, 0,notes from fctracker_library;'''); - c.execute('''update samples_library set experiment_type="RNA-seq" where library_id in (select library_id from fctracker_library where RNASeq = 1);''') + c.execute('select id from samples_experimenttype where name = "RNA-seq";') + rna_seq_id = list(c)[0] + c.execute('''update samples_library set experiment_type_id=? where library_id in (select library_id from fctracker_library where RNASeq = 1);''', rna_seq_id) #c.execute('''drop table fctracker_library;''') # add many to many tables c.execute('''CREATE TABLE "samples_library_affiliations" ( diff --git a/htsworkflow/frontend/samples/admin.py b/htsworkflow/frontend/samples/admin.py index a8494f6..5967e32 100644 --- a/htsworkflow/frontend/samples/admin.py +++ b/htsworkflow/frontend/samples/admin.py @@ -1,4 +1,4 @@ -from htsworkflow.frontend.samples.models import Antibody, Cellline, Condition, Species, Affiliation, Library, Tag +from htsworkflow.frontend.samples.models import Antibody, Cellline, Condition, ExperimentType, Species, Affiliation, Library, Tag from django.contrib import admin from django.utils.translation import ugettext_lazy as _ @@ -14,6 +14,11 @@ class CelllineOptions(admin.ModelAdmin): }), ) +class ExperimentTypeOptions(admin.ModelAdmin): + model = ExperimentType + #list_display = ('name',) + #fieldsets = ( (None, { 'fields': ('name',) }), ) + class LibraryOptions(admin.ModelAdmin): date_hierarchy = "creation_date" save_as = True @@ -121,6 +126,7 @@ admin.site.register(Affiliation, AffiliationOptions) admin.site.register(Antibody, AntibodyOptions) admin.site.register(Cellline, CelllineOptions) admin.site.register(Condition, ConditionOptions) +admin.site.register(ExperimentType, ExperimentTypeOptions) admin.site.register(Library, LibraryOptions) admin.site.register(Species, SpeciesOptions) admin.site.register(Tag, TagOptions) diff --git a/htsworkflow/frontend/samples/models.py b/htsworkflow/frontend/samples/models.py index 2845e81..9301d4f 100644 --- a/htsworkflow/frontend/samples/models.py +++ b/htsworkflow/frontend/samples/models.py @@ -59,6 +59,12 @@ class Condition(models.Model): class Meta: ordering = ["condition_name"] +class ExperimentType(models.Model): + name = models.CharField(max_length=50, unique=True) + + def __unicode__(self): + return unicode(self.name) + class Tag(models.Model): tag_name = models.CharField(max_length=100, db_index=True,blank=False,null=False) TAG_CONTEXT = ( @@ -123,18 +129,7 @@ class Library(models.Model): # SQL to add column: alter table fctracker_library add column "replicate" smallint unsigned NULL; REPLICATE_NUM = ((1,1),(2,2),(3,3),(4,4)) replicate = models.PositiveSmallIntegerField(choices=REPLICATE_NUM,default=1) - - EXPERIMENT_TYPES = ( - ('INPUT_RXLCh','INPUT_RXLCh'), - ('ChIP-seq', 'ChIP-seq'), - ('Sheared', 'Sheared'), - ('RNA-seq', 'RNA-seq'), - ('Methyl-seq', 'Methyl-seq'), - ('DIP-seq', 'DIP-seq'), - ) - experiment_type = models.CharField(max_length=50, choices=EXPERIMENT_TYPES, - default='RNA-seq') - + experiment_type = models.ForeignKey(ExperimentType) creation_date = models.DateField(blank=True, null=True) made_for = models.CharField(max_length=50, blank=True, verbose_name='ChIP/DNA/RNA Made By') -- 2.30.2