From e6ee9bdb5c3a632b0b9de544f64380b0714e5169 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 7 Oct 2015 11:03:47 +0100 Subject: [PATCH] JAL-1499 corrected domainend parsing, add gene name to domain desc --- src/jalview/io/MegaFile.java | 24 ++++++++++++++---------- test/jalview/io/MegaFileTest.java | 18 +++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/jalview/io/MegaFile.java b/src/jalview/io/MegaFile.java index 58961f8..c7caa3b 100644 --- a/src/jalview/io/MegaFile.java +++ b/src/jalview/io/MegaFile.java @@ -362,22 +362,26 @@ public class MegaFile extends AlignFile protected void processGeneOrDomain(String gene, String domain, String property, String codonStart) { + boolean domainEnd = "domainend".equalsIgnoreCase(property); + /* - * If we have been processing a Gene or Domain, and this does not continue - * it, then close it off (generate sequence features for it) + * If we have been processing a Domain or Gene, and this does not continue + * it, then close it off (generate sequence features for it). Do Domain + * first as it is in the context of the enclosing gene if any. */ - if (this.currentGene != null && !this.currentGene.equals(gene)) - { - createFeature(GENE, currentGene, geneStart); - } if (this.currentDomain != null) { - if (!this.currentDomain.equals(domain) - || "domainend".equalsIgnoreCase(property)) + if (!this.currentDomain.equals(domain) || domainEnd) { - createFeature(DOMAIN, currentDomain, domainStart); + String description = currentDomain + + (currentGene == null ? "" : " (" + currentGene + ")"); + createFeature(DOMAIN, description, domainStart); } } + if (this.currentGene != null && !this.currentGene.equals(gene)) + { + createFeature(GENE, currentGene, geneStart); + } /* * and if we have declared a Gene or Domain which does not continue the @@ -393,7 +397,7 @@ public class MegaFile extends AlignFile } currentGene = gene; - currentDomain = domain; + currentDomain = domainEnd ? null : domain; } /** diff --git a/test/jalview/io/MegaFileTest.java b/test/jalview/io/MegaFileTest.java index 14cb27e..2766610 100644 --- a/test/jalview/io/MegaFileTest.java +++ b/test/jalview/io/MegaFileTest.java @@ -655,24 +655,24 @@ public class MegaFileTest for (SequenceI seq : seqs) { SequenceFeature[] sfs = seq.getSequenceFeatures(); // features are added in the order in which their end is found - // (Gene before Domain when they end together) + // (Domain before Gene when they end together) assertEquals(5, sfs.length); // TODO settle which way round type/description go! - assertEquals("Exon1", sfs[0].type); + assertEquals("Exon1 (Adh)", sfs[0].type); assertEquals("Domain", sfs[0].description); assertEquals(7, sfs[0].begin); assertEquals(12, sfs[0].end); - assertEquals("Intron1", sfs[1].type); + assertEquals("Intron1 (Adh)", sfs[1].type); assertEquals("Domain", sfs[1].description); assertEquals(13, sfs[1].begin); assertEquals(18, sfs[1].end); - assertEquals("Adh", sfs[2].type); - assertEquals("Gene", sfs[2].description); - assertEquals(7, sfs[2].begin); + assertEquals("Exon2 (Adh)", sfs[2].type); + assertEquals("Domain", sfs[2].description); + assertEquals(19, sfs[2].begin); assertEquals(24, sfs[2].end); - assertEquals("Exon2", sfs[3].type); - assertEquals("Domain", sfs[3].description); - assertEquals(19, sfs[3].begin); + assertEquals("Adh", sfs[3].type); + assertEquals("Gene", sfs[3].description); + assertEquals(7, sfs[3].begin); assertEquals(24, sfs[3].end); assertEquals("BindingSite", sfs[4].type); assertEquals("Domain", sfs[4].description); -- 1.7.10.2