Attempt to be robust to not having an alignment in our RunXml file
[htsworkflow.git] / docs / Conv_CaltechDB_Nov112008.txt
1 Conversion SQLs for Caltech DB (schema of 2008Aug08 @ 5:06 PM) 
2 ______________________________________________________________
3
4
5 Step by step do the following:
6
7 ''' Note: Instead of '?' you can put one of your machine names.
8 sqlite> ALTER TABLE fctracker_flowcell ADD cluster_mac_id varchar(50) NOT NULL DEFAULT '?';
9 sqlite> ALTER TABLE fctracker_flowcell ADD seq_mac_id varchar(50) NOT NULL DEFAULT '?';
10 sqlite> ALTER TABLE fctracker_library RENAME TO PREV_fctracker_library;
11
12 Now, do a syncdb. The output should look like this (assuming you have migrated to the new models.py):
13 sh-3.2# pym syncdb
14 Creating table fctracker_cellline
15 Creating table fctracker_library
16 Creating table fctracker_primer
17 Creating table fctracker_antibody
18 Creating table fctracker_condition
19 Creating table exp_track_datarun
20 Creating table exp_track_flowcell
21 Creating table analys_track_project
22 Creating table analys_track_task
23 Creating table htsw_reports_progressreport
24 Installing index for fctracker.Library model
25 Failed to install index for fctracker.Library model: index fctracker_library_library_species_id already existsInstalling index for fctracker.Primer model
26 Installing index for fctracker.Antibody model
27 Installing index for exp_track.DataRun model
28 Installing index for exp_track.FlowCell model
29 Installing index for analys_track.Task model
30 Installing index for htsw_reports.ProgressReport model
31 sh-3.2# 
32
33 ''' Copy all records from "fctracker_flowcell" to "exp_track_flowcell" table. (Why? Because, Flowcell table moves now from the "fctracker" to the "exp_track" component). 
34 sqlite> insert into experiments_flowcell select * from fctracker_flowcell;
35
36 ''' Now to fctracker_library, a bit more complex case
37
38 '''Back to the sqlite prompt..
39 sqlite> insert into samples_cellline (cellline_name,notes) values('Unknown','Unknown');
40 sqlite> insert into samples_condition (condition_name,notes) values('Unknown','Unknown');
41 ''' Now we can put 1 in these fields for the Library insert.
42 ''' Note: avg_lib_size field is missing in Caltech DB (although it's in the models.py Trac), so I put default value 225.
43
44 ''' Now the actual migration to the new fctracker_library table
45 ''' (This version looses data, the current Nov 11, 2008 schema, has made_for as a one to many 
46 ''' relationship to the auth_user table, instead of being a text field. Here I just assigned
47 ''' the made for to a (semi)-random user.
48 sqlite> INSERT INTO samples_library (library_id,library_name,library_species_id,experiment_type,cell_line_id,condition_id,replicate,made_by,creation_date,made_for_id,stopping_point,amplified_from_sample_id,undiluted_concentration,ten_nM_dilution,successful_pM,avg_lib_size,notes) select library_id,library_name,library_species_id,'unknown',1,1,1,made_by,creation_date,12,stopping_point,amplified_from_sample_id,undiluted_concentration,ten_nM_dilution,successful_pM,0,notes from PREV_fctracker_library; 
49
50 ''' Set the right values for "experiment_type"
51 sqlite> update samples_library set experiment_type = "RNA-seq" where library_idin (select library_id from prev_fctracker_library where RNASeq = 1);
52 ''' YOU CAN ADD SIMILAR SQL CMD TO SET THE VALUE FOR "avg_lib_size" FIELD (WHICH IS NOW SET TO 0) ...  
53
54 ----------------------------------------------------------------------------------------
55 THAT SHOULD BE IT --- NOW YOUR WEB SITE SHOULD SUCESSFULY LOAD THE NEW DB WITH YOUR DATA.
56
57 2009 Jan 13 
58
59 I had a working database and then merged in a few more changes from
60 stanford. I ended up needing to do the following:
61
62 alter table analysis_task add task_params varchar(200) null;
63 alter table samples_cellline add nickname varchar(20) null;
64 alter table samples_condition add nickname varchar(20) null;
65
66 Those changes might happen automatically when reconverting from our 
67 original database, or they might not.
68
69 CREATE TABLE "samples_library_tags" (
70     "id" integer NOT NULL PRIMARY KEY,
71     "library_id" varchar(30) NOT NULL REFERENCES "samples_library" ("library_id"),
72     "tag_id" integer NOT NULL REFERENCES "samples_tag" ("id"),
73     UNIQUE ("library_id", "tag_id")
74 )
75 ;
76