import jalview.ws.seqfetcher.ASequenceFetcher;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
xrfs = t;
try
{
- retrieved = sftch.getSequences(xrfs, !dna);
+ retrieved = sftch.getSequences(Arrays.asList(xrfs), !dna);
// problem here is we don't know which of xrfs resulted in which
// retrieved element
} catch (Exception e)
// look for direct or indirect references in common
DBRefEntry[] poss = nxt.getDBRefs();
- DBRefEntry[] cands = null;
+ List<DBRefEntry> cands = null;
/*
* TODO does this make any sense?
* if 'direct', search the dbrefs for xrf
poss = DBRefUtils.selectDbRefs(!dna, poss);
cands = DBRefUtils.searchRefs(poss, xrf);
}
- if (cands != null)
+ if (!cands.isEmpty())
{
if (!rseqs.contains(nxt))
{
found = true;
rseqs.add(nxt);
- boolean foundmap = cf != null;
- // don't search if we aren't given a codon map object
- for (int r = 0; foundmap && r < cands.length; r++)
+ if (cf != null)
{
- if (cands[r].hasMap())
+ // don't search if we aren't given a codon map object
+ for (DBRefEntry candidate : cands)
{
- Mapping mapping = cands[r].getMap();
- MapList map = mapping.getMap();
- if (mapping.getTo() != null
- && map.getFromRatio() != map.getToRatio())
+ Mapping mapping = candidate.getMap();
+ if (mapping != null)
{
- // get sense of map correct for adding to product
- // alignment.
- if (dna)
+ MapList map = mapping.getMap();
+ if (mapping.getTo() != null
+ && map.getFromRatio() != map.getToRatio())
{
- // map is from dna seq to a protein product
- cf.addMap(sequenceI, nxt, map);
- }
- else
- {
- // map should be from protein seq to its coding dna
- cf.addMap(nxt, sequenceI, map.getInverse());
+ // get sense of map correct for adding to product
+ // alignment.
+ if (dna)
+ {
+ // map is from dna seq to a protein product
+ cf.addMap(sequenceI, nxt, map);
+ }
+ else
+ {
+ // map should be from protein seq to its coding dna
+ cf.addMap(nxt, sequenceI, map.getInverse());
+ }
}
}
}
List<SequenceI> foundSeqs = new ArrayList<SequenceI>();
AlignedCodonFrame mappings = new AlignedCodonFrame();
+ List<DBRefEntry> sourceRefs = new ArrayList<DBRefEntry>();
+
for (SequenceI seq : seqs)
{
if (dna != Comparison.isNucleotide(seq))
/*
* get this sequence's dbrefs to source database (if any)
*/
- List<DBRefEntry> sourceRefs = DBRefUtils.searchRefsForSource(
+ List<DBRefEntry> seqSourceRefs = DBRefUtils.searchRefsForSource(
seq.getDBRefs(), source);
/*
* first extract any mapped sequences from sourceRefs
*/
- findMappedDbrefs(seq, sourceRefs, foundSeqs, mappings);
+ findMappedDbrefs(seq, seqSourceRefs, foundSeqs, mappings);
/*
* for remaining sourceRefs, try to match a
* complementary sequence in the dataset
*/
- findIndirectCrossReferences(seq, source, sourceRefs, dataset,
+ findIndirectCrossReferences(seq, source, seqSourceRefs, dataset,
foundSeqs, mappings);
-
- /*
- * fetch any remaining sourceRefs from the source database
- */
- fetchCrossReferences(seq, sourceRefs, foundSeqs, mappings, dna,
- dataset);
}
+ /*
+ * fetch any remaining sourceRefs from the source database
+ */
+ fetchCrossReferences(sourceRefs, foundSeqs, mappings, dna, dataset);
+
if (foundSeqs.isEmpty())
{
return null;
import jalview.analysis.AlignmentSorter;
import jalview.analysis.AlignmentUtils;
import jalview.analysis.CrossRef;
+import jalview.analysis.CrossRefs;
import jalview.analysis.Dna;
import jalview.analysis.ParseProperties;
import jalview.analysis.SequenceIdMatcher;
{
AlignmentI alignment = AlignFrame.this.getViewport()
.getAlignment();
- AlignmentI xrefs = CrossRef.findXrefSequences(sel, dna, source,
+ AlignmentI xrefs = CrossRefs.findXrefSequences(sel, dna, source,
alignment);
if (xrefs != null)
{
Cache.log.info(
"Error retrieving " + accession
+ " from " + proxy.getDbName(), e);
- } finally
- {
- return success;
}
+ return success;
}
/**
for (String q : queries)
{
- DBRefEntry[] found = null;
DBRefEntry dbr = new DBRefEntry();
dbr.setSource(proxy.getDbSource());
dbr.setVersion(null);
{
if (rs[r] != null)
{
- found = DBRefUtils.searchRefs(rs[r].getDBRefs(), accId);
- if (found != null && found.length > 0)
+ List<DBRefEntry> found = DBRefUtils.searchRefs(rs[r].getDBRefs(),
+ accId);
+ if (!found.isEmpty())
{
rfound = true;
break;
}
/**
+ * Overloaded method signature to test whether a single sequence is nucleotide
+ * (that is, more than 85% CGTA)
+ *
+ * @param seq
+ * @return
+ */
+ public static final boolean isNucleotide(SequenceI seq)
+ {
+ return isNucleotide(new SequenceI[] { seq });
+ }
+
+ /**
* Answers true if more than 85% of the sequence residues (ignoring gaps) are
* A, G, C, T or U, else false. This is just a heuristic guess and may give a
* wrong answer (as AGCT are also amino acid codes).
}
/**
- * Returns an array of those references that match the given entry, or null if
- * no matches. Currently uses a comparator which matches if
+ * Returns a (possibly empty) list of those references that match the given
+ * entry. Currently uses a comparator which matches if
* <ul>
* <li>database sources are the same</li>
* <li>accession ids are the same</li>
* pattern to match
* @return
*/
- public static DBRefEntry[] searchRefs(DBRefEntry[] ref, DBRefEntry entry)
+ public static List<DBRefEntry> searchRefs(DBRefEntry[] ref,
+ DBRefEntry entry)
{
return searchRefs(ref, entry,
matchDbAndIdAndEitherMapOrEquivalentMapList);
}
/**
- * Returns an array of those references that match the given accession id
+ * Returns a list of those references that match the given accession id
* <ul>
* <li>database sources are the same</li>
* <li>accession ids are the same</li>
* <li>both have no mapping, or the mappings are the same</li>
* </ul>
*
- * @param ref
+ * @param refs
* Set of references to search
- * @param entry
- * pattern to match
+ * @param accId
+ * accession id to match
* @return
*/
- public static DBRefEntry[] searchRefs(DBRefEntry[] ref, String accId)
+ public static List<DBRefEntry> searchRefs(DBRefEntry[] refs, String accId)
{
- return searchRefs(ref, new DBRefEntry("", "", accId), matchId);
+ return searchRefs(refs, new DBRefEntry("", "", accId), matchId);
}
/**
- * Returns an array of those references that match the given entry, according
- * to the given comparator. Returns null if no matches.
+ * Returns a (possibly empty) list of those references that match the given
+ * entry, according to the given comparator.
*
* @param refs
* an array of database references to search
* @param comparator
* @return
*/
- static DBRefEntry[] searchRefs(DBRefEntry[] refs, DBRefEntry entry,
+ static List<DBRefEntry> searchRefs(DBRefEntry[] refs, DBRefEntry entry,
DbRefComp comparator)
{
+ List<DBRefEntry> rfs = new ArrayList<DBRefEntry>();
if (refs == null || entry == null)
{
- return null;
+ return rfs;
}
- List<DBRefEntry> rfs = new ArrayList<DBRefEntry>();
for (int i = 0; i < refs.length; i++)
{
if (comparator.matches(entry, refs[i]))
rfs.add(refs[i]);
}
}
- return rfs.size() == 0 ? null : rfs.toArray(new DBRefEntry[rfs.size()]);
+ return rfs;
}
interface DbRefComp
// (not dna, not protein seq)
}
+ /**
+ * Returns the (possibly empty) list of those supplied dbrefs which have the
+ * specified source databse
+ *
+ * @param dbRefs
+ * @param source
+ * @return
+ */
+ public static List<DBRefEntry> searchRefsForSource(DBRefEntry[] dbRefs,
+ String source)
+ {
+ List<DBRefEntry> matches = new ArrayList<DBRefEntry>();
+ if (dbRefs != null && source != null)
+ {
+ for (DBRefEntry dbref : dbRefs)
+ {
+ if (source.equals(dbref.getSource()))
+ {
+ matches.add(dbref);
+ }
+ }
+ }
+ return matches;
+ }
+
}
* if true, only fetch from nucleotide data sources, else peptide
* @return
*/
- public SequenceI[] getSequences(DBRefEntry[] refs, boolean dna)
+ public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
{
Vector<SequenceI> rseqs = new Vector<SequenceI>();
Hashtable<String, List<String>> queries = new Hashtable<String, List<String>>();
- for (int r = 0; r < refs.length; r++)
+ for (DBRefEntry ref : refs)
{
- if (!queries.containsKey(refs[r].getSource()))
+ if (!queries.containsKey(ref.getSource()))
{
- queries.put(refs[r].getSource(), new ArrayList<String>());
+ queries.put(ref.getSource(), new ArrayList<String>());
}
- List<String> qset = queries.get(refs[r].getSource());
- if (!qset.contains(refs[r].getAccessionId()))
+ List<String> qset = queries.get(ref.getSource());
+ if (!qset.contains(ref.getAccessionId()))
{
- qset.add(refs[r].getAccessionId());
+ qset.add(ref.getAccessionId());
}
}
Enumeration<String> e = queries.keys();
for (int is = 0; is < seqs.length; is++)
{
rseqs.addElement(seqs[is]);
- DBRefEntry[] frefs = DBRefUtils.searchRefs(seqs[is]
+ List<DBRefEntry> frefs = DBRefUtils.searchRefs(seqs[is]
.getDBRefs(), new DBRefEntry(db, null, null));
- if (frefs != null)
+ for (DBRefEntry dbr : frefs)
{
- for (DBRefEntry dbr : frefs)
- {
- queriesFound.add(dbr.getAccessionId());
- queriesMade.remove(dbr.getAccessionId());
- }
+ queriesFound.add(dbr.getAccessionId());
+ queriesMade.remove(dbr.getAccessionId());
}
seqs[is] = null;
}
}
@Override
- public SequenceI[] getSequences(DBRefEntry[] refs, boolean dna)
+ public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
{
return new SequenceI[] { pep1, pep2 };
}
emblSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
/*
- * find EMBL xrefs for peptide sequence - it has no direct
- * dbrefs, but the 'corresponding' nucleotide sequence does, so is returned
- */
- /*
* Find EMBL xrefs for peptide
* - it has no EMBL dbref of its own
* - but nucleotide with matching peptide dbref does, so is returned
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
+import java.util.List;
+
import org.testng.annotations.Test;
public class DBRefUtilsTest
ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1,
1 }, 1, 1)));
- DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1,
+ List<DBRefEntry> matches = DBRefUtils.searchRefs(new DBRefEntry[] {
+ ref1,
ref2, ref3, ref4, ref5 }, target);
- assertEquals(3, matches.length);
- assertSame(ref1, matches[0]);
- assertSame(ref2, matches[1]);
- assertSame(ref5, matches[2]);
+ assertEquals(3, matches.size());
+ assertSame(ref1, matches.get(0));
+ assertSame(ref2, matches.get(1));
+ assertSame(ref5, matches.get(2));
}
/**
new int[] { 1, 1 }, 2, 2));
ref3.setMap(map3);
- DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1,
+ List<DBRefEntry> matches = DBRefUtils.searchRefs(new DBRefEntry[] {
+ ref1,
ref2, ref3 }, target);
- assertEquals(2, matches.length);
- assertSame(ref1, matches[0]);
- assertSame(ref2, matches[1]);
+ assertEquals(2, matches.size());
+ assertSame(ref1, matches.get(0));
+ assertSame(ref2, matches.get(1));
}
/**
DBRefEntry[] dbrefs = new DBRefEntry[] { ref1,
ref2, ref3, ref4, ref5 };
- DBRefEntry[] matches = DBRefUtils.searchRefs(dbrefs, "A1234");
- assertEquals(3, matches.length);
- assertSame(ref1, matches[0]);
- assertSame(ref2, matches[1]);
- assertSame(ref5, matches[2]);
+ List<DBRefEntry> matches = DBRefUtils.searchRefs(dbrefs, "A1234");
+ assertEquals(3, matches.size());
+ assertSame(ref1, matches.get(0));
+ assertSame(ref2, matches.get(1));
+ assertSame(ref5, matches.get(2));
}
/**
ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1,
1 }, 1, 1)));
- DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1,
+ List<DBRefEntry> matches = DBRefUtils.searchRefs(new DBRefEntry[] {
+ ref1,
ref2, ref3, ref4, ref5 }, target);
- assertEquals(4, matches.length);
- assertSame(ref1, matches[0]);
- assertSame(ref2, matches[1]);
- assertSame(ref3, matches[2]);
- assertSame(ref5, matches[3]);
+ assertEquals(4, matches.size());
+ assertSame(ref1, matches.get(0));
+ assertSame(ref2, matches.get(1));
+ assertSame(ref3, matches.get(2));
+ assertSame(ref5, matches.get(3));
}
}