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)