diff --git a/misc-scripts/regulatory_regions/RegulatoryFeatureParser/BaseParser.pm b/misc-scripts/regulatory_regions/RegulatoryFeatureParser/BaseParser.pm index d357d437fdbc36da806c3084531105f1919a99c7..b55e3d7c1ad5d24bbe95cb8185014432442a2baf 100644 --- a/misc-scripts/regulatory_regions/RegulatoryFeatureParser/BaseParser.pm +++ b/misc-scripts/regulatory_regions/RegulatoryFeatureParser/BaseParser.pm @@ -35,9 +35,14 @@ sub delete_existing { $sth = $db_adaptor->dbc->prepare("DELETE rfeat FROM regulatory_feature rfeat, analysis a WHERE a.analysis_id=rfeat.analysis_id AND LOWER(a.analysis_id)=?"); $sth->execute($t); - # delete search regions of this type - $sth = $db_adaptor->dbc->prepare("DELETE FROM regulatory_search_region WHERE type=?"); - $sth->execute($t); + # Delete search regions; they have a different analysis_id + my $sr_type = $type . "_search"; + die "Can't find analysis for $sr_type " unless validate_type($db_adaptor, $sr_type); + my $anal_sth = $db_adaptor->dbc->prepare("SELECT analysis_id FROM analysis WHERE LOWER(logic_name)=?"); + $anal_sth->execute($sr_type); + my $anal = ($anal_sth->fetchrow_array())[0]; + $sth = $db_adaptor->dbc->prepare("DELETE FROM regulatory_search_region WHERE analysis_id=?"); + $sth->execute($anal); } @@ -127,7 +132,7 @@ sub upload_features_and_factors { my $factor_sth = $dbc->prepare("INSERT INTO regulatory_factor (regulatory_factor_id, name, type) VALUES(?,?,?)"); my $feature_object_sth = $dbc->prepare("INSERT INTO regulatory_feature_object (regulatory_feature_id, ensembl_object_type, ensembl_object_id, influence, evidence) VALUES(?,?,?,?,?)"); - my $sr_sth = $dbc->prepare("INSERT INTO regulatory_search_region (name, seq_region_id, seq_region_start, seq_region_end, seq_region_strand, ensembl_object_type, ensembl_object_id, type ) VALUES(?,?,?,?,?,?,?,?)"); + my $sr_sth = $dbc->prepare("INSERT INTO regulatory_search_region (name, seq_region_id, seq_region_start, seq_region_end, seq_region_strand, ensembl_object_type, ensembl_object_id, analysis_id ) VALUES(?,?,?,?,?,?,?,?)"); print "Uploading " . scalar(@{$objects->{FEATURES}}) . " features ...\n"; @@ -171,7 +176,7 @@ sub upload_features_and_factors { $search_region->{STRAND}, $search_region->{ENSEMBL_OBJECT_TYPE}, $search_region->{ENSEMBL_OBJECT_ID}, - $search_region->{TYPE}); + $search_region->{ANALYSIS_ID}); } diff --git a/misc-scripts/regulatory_regions/RegulatoryFeatureParser/cisred.pm b/misc-scripts/regulatory_regions/RegulatoryFeatureParser/cisred.pm index 6b3935c89777d4d993658a7d77355f9ca8f30d98..04cbbe6573305bf3a921390f9c29a96ccb0d1506 100644 --- a/misc-scripts/regulatory_regions/RegulatoryFeatureParser/cisred.pm +++ b/misc-scripts/regulatory_regions/RegulatoryFeatureParser/cisred.pm @@ -103,16 +103,19 @@ sub parse { close(GROUP_SIZES); # ---------------------------------------- - # Analysis + # Analysis - need one for each type of feature + my %analysis; - my $analysis = $analysis_adaptor->fetch_by_logic_name("cisRed"); + foreach my $anal ("cisRed", "cisred_search") { # TODO - add other types as necessary - if (!$analysis) { - print STDERR "Can't get analysis for cisRed, skipping\n"; - next; - } + my $analysis_obj = $analysis_adaptor->fetch_by_logic_name($anal); + + die "Can't get analysis for $anal, skipping" if (!$analysis_obj); - my $analysis_id = $analysis->dbID(); + $analysis{$anal} = $analysis_obj->dbID(); + print "Analysis ID for $anal is " . $analysis{$anal} . "\n"; + + } # ---------------------------------------- # Parse motifs.txt file @@ -136,7 +139,7 @@ sub parse { $feature{NAME} = "craHsap" . $motif_id; $feature{INFLUENCE} = "unknown"; # TODO - what does cisRed store? - $feature{ANALYSIS_ID} = $analysis_id; + $feature{ANALYSIS_ID} = $analysis{cisRed}; # ---------------------------------------- # Factor @@ -224,7 +227,7 @@ sub parse { close FILE; - # ---------------------------------------- + # ---------------------------------------- # Search regions # read search_regions.txt from same location as $file my $search_regions_file = dirname($file) . "/search_regions.txt"; @@ -258,7 +261,7 @@ sub parse { $search_region{STRAND} = ($strand =~ /\+/ ? 1 : -1); $search_region{ENSEMBL_OBJECT_TYPE} = 'Gene'; $search_region{ENSEMBL_OBJECT_ID} = $gene_id; - $search_region{TYPE} = 'cisred'; + $search_region{ANALYSIS_ID} = $analysis{cisred_search}; push @search_regions, \%search_region; } diff --git a/sql/table.sql b/sql/table.sql index f7ceb51f955bdce7344565d20a276819686bd8c8..f4248f651f69ebaf6eeb53494a20f06efc09781c 100755 --- a/sql/table.sql +++ b/sql/table.sql @@ -1310,7 +1310,7 @@ CREATE TABLE regulatory_search_region ( seq_region_strand TINYINT NOT NULL, ensembl_object_type ENUM( 'Transcript', 'Translation', 'Gene') NOT NULL, ensembl_object_id INT, # FK to gene/transcript/translation - type ENUM('cisred_search', 'cisred_mask', 'unknown'), + analysis_id INT NOT NULL, # FK to analysis PRIMARY KEY (regulatory_search_region_id), KEY rsr_idx (regulatory_search_region_id),