Issue
Due to import hiccups, the gene_order
field in the features
table could be set to null
.
Assessment
To detect and assess the problem for a specific project, here is the SQL query in the MySQL console:
SELECT o.id, count(f.id) FROM organisms o JOIN features f ON o.id=f.organism_id JOIN organisms_projects op ON o.id=op.organism_id JOIN projects p ON op.project_id = p.id WHERE p.id=[PROJECT_ID] AND f.gene_order IS NULL GROUP BY o.id;
To assess such a problem site wide:
SELECT o.id, count(f.id) FROM features f JOIN organisms o ON o.id = f.organism_id WHERE f.gene_order IS NULL GROUP BY o.id;
Fix
Once you have identify the problem organisms. Get the list of organism ids in comma separated format, and then you can update the
gene_order
with the following SQL query by replacing [ORGANISM_IDS], ex: 1,2,3,4:Update features f, ( SELECT @rn:= (IF(@prev_contig=t1.contig_id, @rn+1, 1)) AS row_num, t1.id, t1.name, c.name AS contig_name, t1.contig_id, t1.organism_id, t1.gene_order, @prev_contig := t1.contig_id FROM (features t1, (SELECT @rn:=0) t2, (SELECT @prev_contig := '') t3) INNER JOIN contigs c ON c.id = t1.contig_id WHERE t1.organism_id in ([ORGANISM_IDS]) ORDER BY t1.contig_id, t1.`from` ) AS f2 SET f.gene_order = f2.row_num WHERE f.id = f2.id;