Skip to content

Commit

Permalink
Fixed bug with GFF3 loader when adding relationships for children tha…
Browse files Browse the repository at this point in the history
…t start at the same coordinate
  • Loading branch information
spficklin committed Jan 28, 2021
1 parent a453a45 commit 2811ee8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
3 changes: 2 additions & 1 deletion docs/user_guide/example_genomics/genomes_genes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Enter the following:
"File", "Upload the file name Citrus_sinensis-orange1.1g015632m.g.gff3"
"Analysis", "Whole Genome Assembly and Annotation of Citrus sinensis"
"Organism", "Citrus sinensis"
"Landmark Type", "supercontig"
"All other options", "leave as default"

Finally, click the Import GFF3 file button. You'll notice a job was submitted to the jobs subsystem. Now, to complete the process we need the job to run. We'll do this manually:
Expand Down Expand Up @@ -78,7 +79,7 @@ You should see output similar to the following:
Step 22 of 26: Insert feature ontology terms...
Step 23 of 26: Insert 'derives_from' relationships...
Step 24 of 26: Insert Targets...
Step 25 of 26: Associate features with analysis....
Step 25 of 26: Associate features with analysis....
Step 26 of 26: Adding sequences data (Skipped: none available)...

Done.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class so__transcript extends ChadoField {
$results = chado_query($sql, [':feature_id' => $record->feature_id]);
$i = 0;
while ($transcript = $results->fetchObject()) {
dpm($transcript);
// Get the location of this mRNA.
$sql = "
SELECT FL.*, F.name as srcfeature_name
Expand Down
51 changes: 29 additions & 22 deletions tripal_chado/includes/TripalImporter/GFF3Importer.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2033,29 +2033,30 @@ class GFF3Importer extends TripalImporter {
$batch_num = 1;
$sql = '';
$args = [];
foreach ($this->parent_lookup as $parent => $children) {
foreach ($this->parent_lookup as $parent => $starts) {
$total++;
$i++;

$parent_feature = $this->getCachedFeature($this->features[$parent]['findex']);
$parent_uniquename = $parent_feature['uniquename'];
$parent_feature_id = $this->features[$parent_uniquename]['feature_id'];
if (!$parent_feature['skipped']) {

foreach ($children as $child_findex) {
$j++;
$child_feature = $this->getCachedFeature($child_findex);
$child_uniquename = $child_feature['uniquename'];
$child_feature_id = $this->features[$child_uniquename]['feature_id'];
$type_id = $part_of;
if ($child_feature['type'] == 'polypeptide' or $child_feature['type'] == 'protein') {
$type_id = $derives_from;
foreach ($starts as $start => $children) {
foreach ($children as $child_findex) {
$j++;
$child_feature = $this->getCachedFeature($child_findex);
$child_uniquename = $child_feature['uniquename'];
$child_feature_id = $this->features[$child_uniquename]['feature_id'];
$type_id = $part_of;
if ($child_feature['type'] == 'polypeptide' or $child_feature['type'] == 'protein') {
$type_id = $derives_from;
}
$sql .= "(:subject_id_$j, :object_id_$j, :type_id_$j, :rank_$j),\n";
$args[":subject_id_$j"] = $child_feature_id;
$args[":object_id_$j"] = $parent_feature_id;
$args[":type_id_$j"] = $type_id;
$args[":rank_$j"] = $this->features[$child_uniquename]['rank'];
}
$sql .= "(:subject_id_$j, :object_id_$j, :type_id_$j, :rank_$j),\n";
$args[":subject_id_$j"] = $child_feature_id;
$args[":object_id_$j"] = $parent_feature_id;
$args[":type_id_$j"] = $type_id;
$args[":rank_$j"] = $this->features[$child_uniquename]['rank'];
}
}

Expand Down Expand Up @@ -2151,7 +2152,12 @@ class GFF3Importer extends TripalImporter {
// Place features in order that they appear by their start coordinates.
$parent = $feature['parent'];
$start = $feature['start'];
$this->parent_lookup[$parent][$start] = $info['findex'];
// We can have multiple children that start at the same location
// so we'll store children in an array indexed by start position.
if (!array_key_exists($start, $this->parent_lookup[$parent])) {
$this->parent_lookup[$parent][$start] = [];
}
$this->parent_lookup[$parent][$start][] = $info['findex'];
}
$this->setItemsHandled($i);
}
Expand All @@ -2168,15 +2174,16 @@ class GFF3Importer extends TripalImporter {
$this->setItemsHandled(0);
$this->setTotalItems(count(array_keys($this->parent_lookup)));
$i = 0;
foreach ($this->parent_lookup as $parent => $children) {
$starts = array_keys($children);
foreach ($this->parent_lookup as $parent => $starts) {
$starts = array_keys($starts);
sort($starts);
$j = 0;
foreach ($starts as $start) {
$child_findex = $children[$start];
$child = $this->getCachedFeature($child_findex);
$this->features[$child['uniquename']]['rank'] = $j;
$j++;
foreach ($this->parent_lookup[$parent][$start] as $child_findex) {
$child = $this->getCachedFeature($child_findex);
$this->features[$child['uniquename']]['rank'] = $j;
$j++;
}
}
$this->setItemsHandled($j);
}
Expand Down

0 comments on commit 2811ee8

Please sign in to comment.