<xs:attribute name="source" type="xs:string"/>
<xs:attribute name="version" type="xs:string"/>
<xs:attribute name="accessionId" type="xs:string"/>
+ <xs:attribute name="locus" type="xs:boolean" default="false">
+ <xs:annotation>
+ <xs:documentation>
+ true for gene locus mapping, source=species, version=assembly, accession=chromosome
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
return;
}
- MapList newMap = targetToFrom.traverse(fromLoci.getMap());
+ MapList newMap = targetToFrom.traverse(fromLoci.getMapping());
if (newMap != null)
{
public class DBRefEntry implements DBRefEntryI
{
- /*
- * the mapping to chromosome (genome) is held as an instance with
- * source = speciesId
- * version = assemblyId
- * accessionId = "chromosome:" + chromosomeId
- * map = mapping from sequence to reference assembly
- */
- public static final String CHROMOSOME = "chromosome";
-
String source = "";
String version = "";
}
return true;
}
-
- /**
- * Mappings to chromosome are held with accessionId as "chromosome:id"
- *
- * @return
- */
- public boolean isChromosome()
- {
- return accessionId != null && accessionId.startsWith(CHROMOSOME + ":");
- }
}
*
* @return
*/
- MapList getMap();
+ MapList getMapping();
}
--- /dev/null
+package jalview.datamodel;
+
+import jalview.util.MapList;
+
+/**
+ * A specialisation of DBRefEntry used to hold the chromosomal coordinates for a
+ * (typically gene) sequence
+ * <ul>
+ * <li>field <code>source</code> is used to hold a species id e.g. human</li>
+ * <li>field <code>version</code> is used to hold assembly id e.g GRCh38</li>
+ * <li>field <code>accession</code> is used to hold the chromosome id</li>
+ * <li>field <code>map</code> is used to hold the mapping from sequence to
+ * chromosome coordinates</li>
+ * </ul>
+ *
+ * @author gmcarstairs
+ *
+ */
+public class GeneLocus extends DBRefEntry implements GeneLociI
+{
+ /**
+ * Constructor adapts species, assembly, chromosome to DBRefEntry source,
+ * version, accession, respectively, and saves the mapping of sequence to
+ * chromosomal coordinates
+ *
+ * @param speciesId
+ * @param assemblyId
+ * @param chromosomeId
+ * @param mapping
+ */
+ public GeneLocus(String speciesId, String assemblyId, String chromosomeId,
+ Mapping mapping)
+ {
+ super(speciesId, assemblyId, chromosomeId, mapping);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param speciesId
+ * @param assemblyId
+ * @param chromosomeId
+ */
+ public GeneLocus(String speciesId, String assemblyId, String chromosomeId)
+ {
+ this(speciesId, assemblyId, chromosomeId, null);
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ return o instanceof GeneLocus && super.equals(o);
+ }
+
+ @Override
+ public MapList getMapping()
+ {
+ return map == null ? null : map.getMap();
+ }
+
+ /**
+ * Answers the species identifier e.g. "human", stored as field <code>source</code> of
+ * DBRefEntry
+ */
+ @Override
+ public String getSpeciesId()
+ {
+ return getSource();
+ }
+
+ /**
+ * Answers the genome assembly id e.g. "GRCh38", stored as field
+ * <code>version</code> of DBRefEntry
+ */
+ @Override
+ public String getAssemblyId()
+ {
+ return getVersion();
+ }
+
+ /**
+ * Answers the chromosome identifier e.g. "X", stored as field
+ * <code>accession</code> of DBRefEntry
+ */
+ @Override
+ public String getChromosomeId()
+ {
+ return getAccessionId();
+ }
+
+}
public void setGeneLoci(String speciesId, String assemblyId,
String chromosomeId, MapList map)
{
- addDBRef(new DBRefEntry(speciesId, assemblyId, DBRefEntry.CHROMOSOME
- + ":" + chromosomeId, new Mapping(map)));
+ addDBRef(new GeneLocus(speciesId, assemblyId, chromosomeId,
+ new Mapping(map)));
}
/**
{
for (final DBRefEntry ref : refs)
{
- if (ref.isChromosome())
+ if (ref instanceof GeneLociI)
{
- return new GeneLociI()
- {
- @Override
- public String getSpeciesId()
- {
- return ref.getSource();
- }
-
- @Override
- public String getAssemblyId()
- {
- return ref.getVersion();
- }
-
- @Override
- public String getChromosomeId()
- {
- // strip off "chromosome:" prefix to chrId
- return ref.getAccessionId().substring(
- DBRefEntry.CHROMOSOME.length() + 1);
- }
-
- @Override
- public MapList getMap()
- {
- return ref.getMap().getMap();
- }
- };
+ return (GeneLociI) ref;
}
}
}
import jalview.api.FeatureColourI;
import jalview.api.FeatureSettingsModelI;
import jalview.datamodel.AlignmentI;
-import jalview.datamodel.DBRefEntry;
import jalview.datamodel.GeneLociI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
EnsemblFeatureType.exon, EnsemblFeatureType.cds,
EnsemblFeatureType.variation };
+ private static final String CHROMOSOME = "chromosome";
+
/**
* Default constructor (to use rest.ensembl.org)
*/
if (geneLoci != null)
{
seq.setGeneLoci(geneLoci.getSpeciesId(), geneLoci.getAssemblyId(),
- geneLoci.getChromosomeId(), geneLoci.getMap());
+ geneLoci.getChromosomeId(), geneLoci.getMapping());
}
else
{
return false;
}
String[] tokens = description.split(":");
- if (tokens.length == 6 && tokens[0].startsWith(DBRefEntry.CHROMOSOME))
+ if (tokens.length == 6 && tokens[0].startsWith(CHROMOSOME))
{
String ref = tokens[1];
String chrom = tokens[2];
return;
}
- MapList geneMapping = loci.getMap();
+ MapList geneMapping = loci.getMapping();
List<int[]> exons = mapping.getFromRanges();
List<int[]> transcriptLoci = new ArrayList<>();
import jalview.bin.Cache;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.GeneLociI;
+import jalview.datamodel.GeneLocus;
+import jalview.datamodel.Mapping;
import jalview.util.MapList;
import java.io.BufferedReader;
fromEnd });
List<int[]> toRange = Collections.singletonList(new int[] { toStart,
toEnd });
- final MapList map = new MapList(fromRange, toRange, 1, 1);
- return new GeneLociI()
- {
-
- @Override
- public String getSpeciesId()
- {
- return species == null ? "" : species;
- }
-
- @Override
- public String getAssemblyId()
- {
- return assembly;
- }
-
- @Override
- public String getChromosomeId()
- {
- return chromosome;
- }
-
- @Override
- public MapList getMap()
- {
- return map;
- }
- };
+ final Mapping map = new Mapping(
+ new MapList(fromRange, toRange, 1, 1));
+ return new GeneLocus(species == null ? "" : species, assembly,
+ chromosome, map);
} catch (NullPointerException | NumberFormatException e)
{
Cache.log.error("Error looking up gene loci: " + e.getMessage());
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefSource;
import jalview.datamodel.GeneLociI;
+import jalview.datamodel.GeneLocus;
+import jalview.datamodel.Mapping;
import jalview.util.MapList;
import java.io.BufferedReader;
final String chr = chromosome;
List<int[]> fromRange = Collections.singletonList(new int[] { 1,
fromEnd });
- final MapList map = new MapList(fromRange, regions, 1, 1);
- return new GeneLociI()
- {
-
- @Override
- public String getSpeciesId()
- {
- return species == null ? "" : species;
- }
-
- @Override
- public String getAssemblyId()
- {
- return as;
- }
-
- @Override
- public String getChromosomeId()
- {
- return chr;
- }
-
- @Override
- public MapList getMap()
- {
- return map;
- }
- };
+ Mapping mapping = new Mapping(new MapList(fromRange, regions, 1, 1));
+ return new GeneLocus(species == null ? "" : species, as, chr,
+ mapping);
} catch (IOException | ParseException | NumberFormatException e)
{
// ignore
seq.getLength());
if (geneLoci != null)
{
- MapList map = geneLoci.getMap();
+ MapList map = geneLoci.getMapping();
int mappedFromLength = MappingUtils.getLength(map.getFromRanges());
if (mappedFromLength == seq.getLength())
{
seq.setGeneLoci(geneLoci.getSpeciesId(), geneLoci.getAssemblyId(),
- geneLoci.getChromosomeId(), geneLoci.getMap());
+ geneLoci.getChromosomeId(), map);
retrievedLoci.put(dbref, geneLoci);
return true;
}
seq.getLength());
if (geneLoci != null)
{
- MapList map = geneLoci.getMap();
+ MapList map = geneLoci.getMapping();
int mappedFromLength = MappingUtils.getLength(map.getFromRanges());
if (mappedFromLength == seq.getLength())
{
seq.setGeneLoci(geneLoci.getSpeciesId(), geneLoci.getAssemblyId(),
- geneLoci.getChromosomeId(), geneLoci.getMap());
+ geneLoci.getChromosomeId(), map);
retrievedLoci.put(dbref, geneLoci);
return true;
}
import jalview.api.FeatureColourI;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.DBRefSource;
+import jalview.datamodel.GeneLociI;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.util.MessageManager;
@Override
public int compare(DBRefEntry ref1, DBRefEntry ref2)
{
- if (ref1.isChromosome())
+ if (ref1 instanceof GeneLociI)
{
return -1;
}
- if (ref2.isChromosome())
+ if (ref2 instanceof GeneLociI)
{
return 1;
}
String species = seqCoords.getSpeciesId();
String chromosome = seqCoords.getChromosomeId();
String seqRef = seqCoords.getAssemblyId();
- MapList map = seqCoords.getMap();
+ MapList map = seqCoords.getMapping();
if (!vcfSpeciesMatchesSequence(vcfAssembly, species))
{
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.GeneLocus;
import jalview.datamodel.GraphLine;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.Point;
parentseq = jds;
}
}
+
+ /*
+ * save any dbrefs; special subclass GeneLocus is flagged as 'locus'
+ */
if (dbrefs != null)
{
for (int d = 0; d < dbrefs.length; d++)
{
DBRef dbref = new DBRef();
- dbref.setSource(dbrefs[d].getSource());
- dbref.setVersion(dbrefs[d].getVersion());
- dbref.setAccessionId(dbrefs[d].getAccessionId());
- if (dbrefs[d].hasMap())
+ DBRefEntry dbRefEntry = dbrefs[d];
+ dbref.setSource(dbRefEntry.getSource());
+ dbref.setVersion(dbRefEntry.getVersion());
+ dbref.setAccessionId(dbRefEntry.getAccessionId());
+ if (dbRefEntry instanceof GeneLocus)
{
- Mapping mp = createVamsasMapping(dbrefs[d].getMap(), parentseq,
+ dbref.setLocus(true);
+ }
+ if (dbRefEntry.hasMap())
+ {
+ Mapping mp = createVamsasMapping(dbRefEntry.getMap(), parentseq,
jds, recurse);
dbref.setMapping(mp);
}
- // vamsasSeq.addDBRef(dbref);
vamsasSeq.getDBRef().add(dbref);
}
}
return datasetId;
}
+ /**
+ * Add any saved DBRefEntry's to the sequence. An entry flagged as 'locus' is
+ * constructed as a special subclass GeneLocus.
+ *
+ * @param datasetSequence
+ * @param sequence
+ */
private void addDBRefs(SequenceI datasetSequence, Sequence sequence)
{
for (int d = 0; d < sequence.getDBRef().size(); d++)
{
DBRef dr = sequence.getDBRef().get(d);
- jalview.datamodel.DBRefEntry entry = new jalview.datamodel.DBRefEntry(
- dr.getSource(), dr.getVersion(), dr.getAccessionId());
+ DBRefEntry entry;
+ if (dr.isLocus())
+ {
+ entry = new GeneLocus(dr.getSource(), dr.getVersion(),
+ dr.getAccessionId());
+ }
+ else
+ {
+ entry = new DBRefEntry(dr.getSource(), dr.getVersion(),
+ dr.getAccessionId());
+ }
if (dr.getMapping() != null)
{
entry.setMap(addMapping(dr.getMapping()));
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2018.12.20 at 11:47:26 AM GMT
+// Generated on: 2019.02.06 at 10:59:19 AM GMT
//
* <attribute name="source" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="version" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="accessionId" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="locus" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
* </restriction>
* </complexContent>
* </complexType>
* <attribute name="source" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="version" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="accessionId" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="locus" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
* </restriction>
* </complexContent>
* </complexType>
protected String version;
@XmlAttribute(name = "accessionId")
protected String accessionId;
+ @XmlAttribute(name = "locus")
+ protected Boolean locus;
/**
* Gets the value of the mapping property.
this.accessionId = value;
}
+ /**
+ * Gets the value of the locus property.
+ *
+ * @return
+ * possible object is
+ * {@link Boolean }
+ *
+ */
+ public boolean isLocus() {
+ if (locus == null) {
+ return false;
+ } else {
+ return locus;
+ }
+ }
+
+ /**
+ * Sets the value of the locus property.
+ *
+ * @param value
+ * allowed object is
+ * {@link Boolean }
+ *
+ */
+ public void setLocus(Boolean value) {
+ this.locus = value;
+ }
+
}
}
* transcript 'CDS' is 10-16, 17-21
* which is 'gene' 158-164, 210-214
*/
- MapList toMap = toLoci.getMap();
+ MapList toMap = toLoci.getMapping();
assertEquals(1, toMap.getFromRanges().size());
assertEquals(2, toMap.getFromRanges().get(0).length);
assertEquals(1, toMap.getFromRanges().get(0)[0]);
AlignmentUtils.transferGeneLoci(from, map, to);
assertEquals("GRCh38", toLoci.getAssemblyId());
assertEquals("7", toLoci.getChromosomeId());
- toMap = toLoci.getMap();
+ toMap = toLoci.getMapping();
assertEquals("[ [1, 12] ] 1:1 to [ [158, 164] [210, 214] ]",
toMap.toString());
}
import jalview.api.ViewStyleI;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.GeneLocus;
import jalview.datamodel.HiddenSequences;
+import jalview.datamodel.Mapping;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.PDBEntry.Type;
import jalview.datamodel.SequenceCollectionI;
import jalview.schemes.StrandColourScheme;
import jalview.schemes.TCoffeeColourScheme;
import jalview.structure.StructureImportSettings;
+import jalview.util.MapList;
import jalview.util.matcher.Condition;
import jalview.viewmodel.AlignmentViewport;
.getAlignViewport(),
"Didn't restore correct view association for the PCA view");
}
+
+ /**
+ * Test save and reload of DBRefEntry including GeneLocus in project
+ *
+ * @throws Exception
+ */
+ @Test(groups = { "Functional" })
+ public void testStoreAndRecoverGeneLocus() throws Exception
+ {
+ Desktop.instance.closeAll_actionPerformed(null);
+ String seqData = ">P30419\nACDE\n>X1235\nGCCTGTGACGAA";
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqData,
+ DataSourceType.PASTE);
+ assertNotNull(af, "Didn't read in the example file correctly.");
+
+ AlignmentViewPanel ap = Desktop.getAlignmentPanels(null)[0];
+ SequenceI pep = ap.getAlignment().getSequenceAt(0);
+ SequenceI cds = ap.getAlignment().getSequenceAt(1);
+
+ /*
+ * give 'protein' a dbref to self, a dbref with map to CDS,
+ * and a dbref with map to gene 'locus'
+ */
+ DBRefEntry dbref1 = new DBRefEntry("Uniprot", "1", "P30419", null);
+ pep.addDBRef(dbref1);
+ Mapping cdsmap = new Mapping(cds,
+ new MapList(new int[]
+ { 1, 4 }, new int[] { 1, 12 }, 1, 3));
+ DBRefEntry dbref2 = new DBRefEntry("EMBLCDS", "2", "X1235", cdsmap);
+ pep.addDBRef(dbref2);
+ Mapping locusmap = new Mapping(null,
+ new MapList(new int[]
+ { 1, 4 }, new int[] { 2674123, 2674135 }, 1, 3));
+ DBRefEntry dbref3 = new GeneLocus("human", "GRCh38", "5", locusmap);
+ pep.addDBRef(dbref3);
+
+ File tfile = File.createTempFile("testStoreAndRecoverGeneLocus",
+ ".jvp");
+ try
+ {
+ new Jalview2XML(false).saveState(tfile);
+ } catch (Throwable e)
+ {
+ Assert.fail("Didn't save the state", e);
+ }
+ Desktop.instance.closeAll_actionPerformed(null);
+
+ new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
+ DataSourceType.FILE);
+ AlignmentViewPanel rap = Desktop.getAlignmentPanels(null)[0];
+ SequenceI rpep = rap.getAlignment().getSequenceAt(0);
+ assertEquals(rpep.getName(), "P30419");
+ DBRefEntry[] dbrefs = rpep.getDBRefs();
+ assertEquals(dbrefs.length, 3);
+ DBRefEntry dbRef = dbrefs[0];
+ assertFalse(dbRef instanceof GeneLocus);
+ assertNull(dbRef.getMap());
+ assertEquals(dbRef, dbref1);
+
+ /*
+ * restored dbrefs with mapping have a different 'map to'
+ * sequence but otherwise match the original dbrefs
+ */
+ dbRef = dbrefs[1];
+ assertFalse(dbRef instanceof GeneLocus);
+ assertTrue(dbRef.equalRef(dbref2));
+ assertNotNull(dbRef.getMap());
+ SequenceI rcds = rap.getAlignment().getSequenceAt(1);
+ assertSame(dbRef.getMap().getTo(), rcds);
+ // compare MapList but not map.to
+ assertEquals(dbRef.getMap().getMap(), dbref2.getMap().getMap());
+
+ /*
+ * GeneLocus map.to is null so can compare Mapping objects
+ */
+ dbRef = dbrefs[2];
+ assertTrue(dbRef instanceof GeneLocus);
+ assertEquals(dbRef, dbref3);
+ }
}