private AlignmentI dataset;
/*
- * true if we are searching for cross-references from nucleotide,
- * i.e. for protein sequences, false if the reverse
- */
- private boolean fromDna;
-
- /*
* the sequences for which we are seeking cross-references
*/
private SequenceI[] fromSeqs;
public CrossRef(SequenceI[] seqs, AlignmentI ds)
{
fromSeqs = seqs;
- fromDna = ds.isNucleotide();
dataset = ds.getDataset() == null ? ds : ds.getDataset();
}
* reference from another sequence in the dataset which has a cross-reference
* to a direct DBRefEntry on the given sequence</li>
* </ul>
+ *
+ * @param dna
+ * - when true, cross-references *from* dna returned. When false,
+ * cross-references *from* protein are returned
* @return
*/
- public List<String> findXrefSourcesForSequences()
+ public List<String> findXrefSourcesForSequences(boolean dna)
{
List<String> sources = new ArrayList<String>();
for (SequenceI seq : fromSeqs)
{
if (seq != null)
{
- findXrefSourcesForSequence(seq, sources);
+ findXrefSourcesForSequence(seq, dna, sources);
}
}
return sources;
* @param sources
* a list of sources to add matches to
*/
- void findXrefSourcesForSequence(SequenceI seq, List<String> sources)
+ void findXrefSourcesForSequence(SequenceI seq, boolean fromDna,
+ List<String> sources)
{
/*
* first find seq's xrefs (dna-to-peptide or peptide-to-dna)
* find sequences in the alignment which xref one of these DBRefs
* i.e. is xref-ed to a common sequence identifier
*/
- searchDatasetXrefs(seq, lrfs, rseqs, null);
+ searchDatasetXrefs(fromDna, seq, lrfs, rseqs, null);
/*
* add those sequences' (dna-to-peptide or peptide-to-dna) dbref sources
* @param source
* @return cross-referenced sequences (as dataset sequences)
*/
- public Alignment findXrefSequences(String source)
+ public Alignment findXrefSequences(String source, boolean fromDna)
{
List<SequenceI> rseqs = new ArrayList<SequenceI>();
* which have a dbref to an accession id for this sequence,
* and add them to the results
*/
- found = searchDatasetXrefs(dss, lrfs, rseqs, cf);
+ found = searchDatasetXrefs(fromDna, dss, lrfs, rseqs, cf);
}
if (xrfs == null && !found)
{
+ xref.getAccessionId());
if (matchedSeq != null)
{
- if (constructMapping(seq, matchedSeq, xref, cf))
+ if (constructMapping(seq, matchedSeq, xref, cf, fromDna))
{
found = true;
}
{
// do a bit more work - search for sequences with references matching
// xrefs on this sequence.
- found = searchDataset(dss, xref, rseqs, cf, false);
+ found = searchDataset(fromDna, dss, xref, rseqs, cf, false);
}
if (found)
{
if (retrieved != null)
{
- updateDbrefMappings(seq, xrfs, retrieved, cf);
+ updateDbrefMappings(seq, xrfs, retrieved, cf, fromDna);
for (SequenceI retrievedSequence : retrieved)
{
SequenceI retrievedDss = retrievedSequence.getDatasetSequence() == null ? retrievedSequence
* @param retrieved
* @param acf
*/
- void updateDbrefMappings(SequenceI mapFrom,
- DBRefEntry[] xrefs, SequenceI[] retrieved, AlignedCodonFrame acf)
+ void updateDbrefMappings(SequenceI mapFrom, DBRefEntry[] xrefs,
+ SequenceI[] retrieved, AlignedCodonFrame acf, boolean fromDna)
{
SequenceIdMatcher matcher = new SequenceIdMatcher(retrieved);
for (DBRefEntry xref : xrefs)
}
for (SequenceI seq : matches)
{
- constructMapping(mapFrom, seq, xref, acf);
+ constructMapping(mapFrom, seq, xref, acf, fromDna);
}
}
}
* @return
*/
boolean constructMapping(SequenceI mapFrom, SequenceI mapTo,
- DBRefEntry xref, AlignedCodonFrame mappings)
+ DBRefEntry xref, AlignedCodonFrame mappings, boolean fromDna)
{
MapList mapping = null;
* dataset (that is not equal to sequenceI) Identifies matching DBRefEntry
* based on source and accession string only - Map and Version are nulled.
*
+ * @param fromDna
+ * - true if context was searching from Dna sequences, false if
+ * context was searching from Protein sequences
* @param sequenceI
* @param lrfs
* @param rseqs
* @return true if matches were found.
*/
- private boolean searchDatasetXrefs(SequenceI sequenceI,
+ private boolean searchDatasetXrefs(boolean fromDna, SequenceI sequenceI,
DBRefEntry[] lrfs, List<SequenceI> rseqs, AlignedCodonFrame cf)
{
boolean found = false;
// add in wildcards
xref.setVersion(null);
xref.setMap(null);
- found |= searchDataset(sequenceI, xref, rseqs, cf, false);
+ found |= searchDataset(fromDna, sequenceI, xref, rseqs, cf, false);
}
return found;
}
* Searches dataset for DBRefEntrys matching the given one (xrf) and adds the
* associated sequence to rseqs
*
+ * @param fromDna
+ * true if context was searching for refs *from* dna sequence, false
+ * if context was searching for refs *from* protein sequence
* @param sequenceI
* a sequence to ignore (start point of search)
* @param xrf
* - search all references or only subset
* @return true if relationship found and sequence added.
*/
- boolean searchDataset(SequenceI sequenceI, DBRefEntry xrf,
- List<SequenceI> rseqs, AlignedCodonFrame cf, boolean direct)
+ boolean searchDataset(boolean fromDna, SequenceI sequenceI,
+ DBRefEntry xrf, List<SequenceI> rseqs, AlignedCodonFrame cf,
+ boolean direct)
{
boolean found = false;
if (dataset == null)
final boolean dna = viewport.getAlignment().isNucleotide();
List<String> ptypes = (seqs == null || seqs.length == 0) ? null
: new CrossRef(seqs, dataset)
- .findXrefSourcesForSequences();
+ .findXrefSourcesForSequences(dna);
for (final String source : ptypes)
{
* @param source
* the database to show cross-references for
*/
- protected void showProductsFor(final SequenceI[] sel, final boolean dna,
+ protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
final String source)
{
Runnable foo = new Runnable()
.getAlignment();
AlignmentI dataset = alignment.getDataset() == null ? alignment
: alignment.getDataset();
- AlignmentI xrefs = new CrossRef(sel, alignment)
- .findXrefSequences(source);
+ boolean dna = alignment.isNucleotide();
+ if (_odna!=dna)
+ {
+ System.err
+ .println("Conflict: showProducts for alignment originally "
+ + "thought to be "
+ + (_odna ? "DNA" : "Protein")
+ + " now searching for "
+ + (dna ? "DNA" : "Protein") + " Context.");
+ }
+ AlignmentI xrefs = new CrossRef(sel, dataset)
+ .findXrefSequences(source, dna);
if (xrefs == null)
{
return;
sprods[s].updatePDBIds();
}
Alignment al = new Alignment(sprods);
- al.setDataset((Alignment) dataset);
+ al.setDataset(dataset);
return al;
}
* first with no dbrefs to search
*/
sources = new CrossRef(new SequenceI[] { seq }, al)
- .findXrefSourcesForSequences();
+ .findXrefSourcesForSequences(false);
assertTrue(sources.isEmpty());
/*
seq.addDBRef(new DBRefEntry("ENSEMBL", "0", "E2349"));
seq.addDBRef(new DBRefEntry("ENSEMBLGENOMES", "0", "E2350"));
sources = new CrossRef(new SequenceI[] { seq }, al)
- .findXrefSourcesForSequences();
+ .findXrefSourcesForSequences(false);
assertEquals(4, sources.size());
assertEquals("[EMBL, EMBLCDS, GENEDB, ENSEMBL]",
sources.toString());
// TODO include ENSEMBLGENOMES in DBRefSource.DNACODINGDBS ?
al.addSequence(seq2);
sources = new CrossRef(new SequenceI[] { seq }, al)
- .findXrefSourcesForSequences();
+ .findXrefSourcesForSequences(false);
assertEquals(3, sources.size());
assertEquals("[EMBLCDS, EMBL, GENEDB]", sources.toString());
}
*/
AlignmentI al = new Alignment(new SequenceI[] { emblSeq, uniprotSeq });
Alignment xrefs = new CrossRef(new SequenceI[] { emblSeq }, al)
- .findXrefSequences("UNIPROT");
+ .findXrefSequences("UNIPROT", true);
assertEquals(1, xrefs.getHeight());
assertSame(uniprotSeq, xrefs.getSequenceAt(0));
}
*/
AlignmentI al = new Alignment(new SequenceI[] { emblSeq, uniprotSeq });
Alignment xrefs = new CrossRef(new SequenceI[] { uniprotSeq },
- al).findXrefSequences("EMBL");
+ al)
+ .findXrefSequences("EMBL", true);
assertEquals(1, xrefs.getHeight());
assertSame(emblSeq, xrefs.getSequenceAt(0));
}
*/
AlignmentI al = new Alignment(new SequenceI[] { dna1, dna2 });
Alignment xrefs = new CrossRef(new SequenceI[] { dna2 }, al)
- .findXrefSequences("UNIPROT");
+ .findXrefSequences("UNIPROT", true);
assertNull(xrefs);
}
*/
DBRefEntry dbref = new DBRefEntry("UNIPROT", "0", "P30419");
CrossRef testee = new CrossRef(al.getSequencesArray(), al);
- boolean found = testee.searchDataset(dna1, dbref, result, null, true);
+ boolean found = testee.searchDataset(true, dna1, dbref, result, null,
+ true);
assertFalse(found);
assertTrue(result.isEmpty());
* search for a protein sequence with dbref UNIPROT:Q9ZTS2
*/
dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2");
- found = testee.searchDataset(dna1, dbref, result, null, true);
+ found = testee.searchDataset(true, dna1, dbref, result, null, true);
assertTrue(found);
assertEquals(1, result.size());
assertSame(pep1, result.get(0));
*/
result.clear();
dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2");
- found = testee.searchDataset(pep1, dbref, result, null, false);
+ found = testee.searchDataset(false, pep1, dbref, result, null, false);
assertTrue(found);
assertEquals(1, result.size());
assertSame(dna1, result.get(0));
*/
AlignmentI al = new Alignment(new SequenceI[] { dna1 });
Alignment xrefs = new CrossRef(new SequenceI[] { dna1 }, al)
- .findXrefSequences("UNIPROT");
+ .findXrefSequences("UNIPROT", true);
assertEquals(2, xrefs.getHeight());
/*
*/
AlignmentI al = new Alignment(new SequenceI[] { dna1 });
Alignment xrefs = new CrossRef(new SequenceI[] { dna1 }, al)
- .findXrefSequences("UNIPROT");
+ .findXrefSequences("UNIPROT", true);
assertEquals(2, xrefs.getHeight());
assertSame(pep1, xrefs.getSequenceAt(0));
assertSame(pep2, xrefs.getSequenceAt(1));
SequenceI[] seqs = new SequenceI[] { gene, braf001, braf002 };
AlignmentI al = new Alignment(seqs);
Alignment xrefs = new CrossRef(seqs, al)
- .findXrefSequences("UNIPROT");
+.findXrefSequences("UNIPROT",
+ true);
assertEquals(2, xrefs.getHeight());
assertSame(pep1, xrefs.getSequenceAt(0));
assertSame(pep2, xrefs.getSequenceAt(1));
*/
SequenceI[] seqs = new SequenceI[] { p0ce19, p0ce20 };
AlignmentI al = new Alignment(seqs);
- Alignment xrefs = new CrossRef(seqs, al)
- .findXrefSequences("EMBL");
+ Alignment xrefs = new CrossRef(seqs, al).findXrefSequences("EMBL",
+ false);
/*
* verify retrieved sequences
// try and find products
CrossRef crossRef = new CrossRef(al.getSequencesArray(),
al);
- List<String> types = crossRef.findXrefSourcesForSequences();
+ List<String> types = crossRef.findXrefSourcesForSequences(dna);
if (types != null)
{
System.out.println("Xref Types for: "
for (String source : types)
{
System.out.println("Type: " + source);
- SequenceI[] prod = crossRef.findXrefSequences(source)
+ SequenceI[] prod = crossRef.findXrefSequences(source, dna)
.getSequencesArray();
System.out.println("Found "
+ ((prod == null) ? "no" : "" + prod.length)
// have a bash at finding the products amongst all the retrieved
// sequences.
SequenceI[] seqs = al.getSequencesArray();
- Alignment prodal = new CrossRef(seqs, ds)
- .findXrefSequences(null);
+ Alignment prodal = new CrossRef(seqs, ds).findXrefSequences(null,
+ dna);
System.out.println("Found "
+ ((prodal == null) ? "no" : "" + prodal.getHeight())
+ " products");
assertEquals("Expected local reference map to be 3 nucleotides", dr[0]
.getMap().getWidth(), 3);
AlignmentI sprods = new CrossRef(alsq.getSequencesArray(), alsq)
- .findXrefSequences(dr[0].getSource());
+ .findXrefSequences(dr[0].getSource(), true);
assertNotNull(
"Couldn't recover cross reference sequence from dataset. Was it ever added ?",
sprods);