*/
package jalview.ws;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
import jalview.analysis.AlignSeq;
+import jalview.api.FeatureSettingsModelI;
import jalview.bin.Cache;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.Mapping;
import jalview.datamodel.SequenceI;
import jalview.gui.CutAndPasteTransfer;
-import jalview.gui.DasSourceBrowser;
import jalview.gui.Desktop;
import jalview.gui.FeatureSettings;
import jalview.gui.IProgressIndicator;
import jalview.gui.OOMWarning;
import jalview.util.DBRefUtils;
import jalview.util.MessageManager;
-import jalview.ws.dbsources.das.api.jalviewSourceI;
-import jalview.ws.dbsources.das.datamodel.DasSequenceSource;
import jalview.ws.seqfetcher.DbSourceProxy;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
import uk.ac.ebi.picr.model.UPEntry;
import uk.ac.ebi.www.picr.AccessionMappingService.AccessionMapperServiceLocator;
{
private static final String NEWLINE = System.lineSeparator();
+ public static final String TRIM_RETRIEVED_SEQUENCES = "TRIM_FETCHED_DATASET_SEQS";
+
public interface FetchFinishedListenerI
{
void finished();
CutAndPasteTransfer output = new CutAndPasteTransfer();
- boolean running = false;
-
/**
* picr client instance
*/
DbSourceProxy[] sources, FeatureSettings featureSettings,
boolean isNucleotide)
{
- listeners = new ArrayList<FetchFinishedListenerI>();
+ listeners = new ArrayList<>();
this.progressWindow = progressIndicatorFrame;
alseqs = new SequenceI[seqs.length];
SequenceI[] ds = new SequenceI[seqs.length];
}
this.dataset = ds;
// TODO Jalview 2.5 lots of this code should be in the gui package!
- sfetcher = jalview.gui.SequenceFetcher
- .getSequenceFetcherSingleton(progressIndicatorFrame);
+ sfetcher = jalview.gui.SequenceFetcher.getSequenceFetcherSingleton();
// set default behaviour for transferring excess sequence data to the
// dataset
- trimDsSeqs = Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true);
+ trimDsSeqs = Cache.getDefault(TRIM_RETRIEVED_SEQUENCES, true);
if (sources == null)
{
setDatabaseSources(featureSettings, isNucleotide);
{
// af.featureSettings_actionPerformed(null);
String[] defdb = null;
- List<DbSourceProxy> selsources = new ArrayList<DbSourceProxy>();
- Vector<jalviewSourceI> dasselsrc = (featureSettings != null)
- ? featureSettings.getSelectedSources()
- : new DasSourceBrowser().getSelectedSources();
-
- for (jalviewSourceI src : dasselsrc)
- {
- List<DbSourceProxy> sp = src.getSequenceSourceProxies();
- if (sp != null)
- {
- selsources.addAll(sp);
- if (sp.size() > 1)
- {
- Cache.log.debug("Added many Db Sources for :" + src.getTitle());
- }
- }
- }
+ List<DbSourceProxy> selsources = new ArrayList<>();
// select appropriate databases based on alignFrame context.
if (forNucleotide)
{
{
defdb = DBRefSource.PROTEINDBS;
}
- List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
+ List<DbSourceProxy> srces = new ArrayList<>();
for (String ddb : defdb)
{
List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
}
/**
- * retrieve all the das sequence sources and add them to the list of db
- * sources to retrieve from
- */
- public void appendAllDasSources()
- {
- if (dbSources == null)
- {
- dbSources = new DbSourceProxy[0];
- }
- // append additional sources
- DbSourceProxy[] otherdb = sfetcher
- .getDbSourceProxyInstances(DasSequenceSource.class);
- if (otherdb != null && otherdb.length > 0)
- {
- DbSourceProxy[] newsrc = new DbSourceProxy[dbSources.length
- + otherdb.length];
- System.arraycopy(dbSources, 0, newsrc, 0, dbSources.length);
- System.arraycopy(otherdb, 0, newsrc, dbSources.length,
- otherdb.length);
- dbSources = newsrc;
- }
- }
-
- /**
* start the fetcher thread
*
* @param waitTillFinished
*/
public void fetchDBRefs(boolean waitTillFinished)
{
- // TODO can we not simply write
- // if (waitTillFinished) { run(); } else { new Thread(this).start(); }
-
- Thread thread = new Thread(this);
- thread.start();
- running = true;
-
if (waitTillFinished)
{
- while (running)
- {
- try
- {
- Thread.sleep(500);
- } catch (Exception ex)
- {
- }
- }
+ run();
+ }
+ else
+ {
+ new Thread(this).start();
}
}
}
else if (seqs == null)
{
- seqs = new Vector<SequenceI>();
+ seqs = new Vector<>();
seqs.addElement(seq);
}
}
else
{
- seqs = new Vector<SequenceI>();
+ seqs = new Vector<>();
seqs.addElement(seq);
}
throw new Error(MessageManager
.getString("error.implementation_error_must_init_dbsources"));
}
- running = true;
long startTime = System.currentTimeMillis();
if (progressWindow != null)
{
e.printStackTrace();
}
- Vector<SequenceI> sdataset = new Vector<SequenceI>(
+ Vector<SequenceI> sdataset = new Vector<>(
Arrays.asList(dataset));
- List<String> warningMessages = new ArrayList<String>();
+ List<String> warningMessages = new ArrayList<>();
+
+ // clear any old feature display settings recorded from past sessions
+ featureDisplaySettings = null;
int db = 0;
while (sdataset.size() > 0 && db < dbSources.length)
SequenceI[] currSeqs = new SequenceI[sdataset.size()];
sdataset.copyInto(currSeqs);// seqs that are to be validated against
// dbSources[db]
- Vector<String> queries = new Vector<String>(); // generated queries curSeq
- seqRefs = new Hashtable<String, Vector<SequenceI>>();
+ Vector<String> queries = new Vector<>(); // generated queries curSeq
+ seqRefs = new Hashtable<>();
int seqIndex = 0;
}
if (retrieved != null)
{
- transferReferences(sdataset, dbsource.getDbSource(), retrieved,
+ transferReferences(sdataset, dbsource, retrieved,
trimDsSeqs, warningMessages);
}
}
&& (i < 50); seqIndex++, i++)
{
SequenceI sequence = dataset[seqIndex];
- DBRefEntry[] uprefs = DBRefUtils
+ List<DBRefEntry> uprefs = DBRefUtils
.selectRefs(sequence.getDBRefs(), new String[]
{ dbsource.getDbSource() }); // jalview.datamodel.DBRefSource.UNIPROT
// });
// check for existing dbrefs to use
- if (uprefs != null && uprefs.length > 0)
+ if (uprefs != null && uprefs.size() > 0)
{
- for (int j = 0; j < uprefs.length; j++)
+ for (int j = 0, n = uprefs.size(); j < n; j++)
{
- addSeqId(sequence, uprefs[j].getAccessionId());
+ DBRefEntry upref = uprefs.get(j);
+ addSeqId(sequence, upref.getAccessionId());
queries.addElement(
- uprefs[j].getAccessionId().toUpperCase());
+ upref.getAccessionId().toUpperCase());
}
}
else
{
listener.finished();
}
- running = false;
}
/**
* @param warningMessages
* a list of messages to add to
*/
- boolean transferReferences(Vector<SequenceI> sdataset, String dbSource,
+ boolean transferReferences(Vector<SequenceI> sdataset,
+ DbSourceProxy dbSourceProxy,
AlignmentI retrievedAl, boolean trimDatasetSeqs,
List<String> warningMessages)
{
return false;
}
+ String dbSource = dbSourceProxy.getDbName();
boolean modified = false;
SequenceI[] retrieved = recoverDbSequences(
retrievedAl.getSequencesArray());
{
// Work out which sequences this sequence matches,
// taking into account all accessionIds and names in the file
- Vector<SequenceI> sequenceMatches = new Vector<SequenceI>();
+ Vector<SequenceI> sequenceMatches = new Vector<>();
// look for corresponding accession ids
- DBRefEntry[] entryRefs = DBRefUtils
+ List<DBRefEntry> entryRefs = DBRefUtils
.selectRefs(retrievedSeq.getDBRefs(), new String[]
{ dbSource });
if (entryRefs == null)
+ dbSource + " on " + retrievedSeq.getName());
continue;
}
- for (int j = 0; j < entryRefs.length; j++)
+ for (int j = 0, n = entryRefs.size(); j < n; j++)
{
- String accessionId = entryRefs[j].getAccessionId();
+ DBRefEntry ref = entryRefs.get(j);
+ String accessionId = ref.getAccessionId();
// match up on accessionId
if (seqRefs.containsKey(accessionId.toUpperCase()))
{
// could be useful to extend this so we try to find any 'significant'
// information in common between two sequence objects.
/*
- * DBRefEntry[] entryRefs =
+ * List<DBRefEntry> entryRefs =
* jalview.util.DBRefUtils.selectRefs(entry.getDBRef(), new String[] {
* dbSource }); for (int j = 0; j < entry.getName().size(); j++) { String
* name = entry.getName().elementAt(j).toString(); if
* seqs.elementAt(jj); if (!sequenceMatches.contains(sequence)) {
* sequenceMatches.addElement(sequence); } } } }
*/
+ if (sequenceMatches.size() > 0)
+ {
+ addFeatureSettings(dbSourceProxy);
+ }
// sequenceMatches now contains the set of all sequences associated with
// the returned db record
final String retrievedSeqString = retrievedSeq.getSequenceAsString();
// TODO: test for legacy where uniprot or EMBL refs exist but no
// mappings are made (but content matches retrieved set)
boolean updateRefFrame = sequence.getDBRefs() == null
- || sequence.getDBRefs().length == 0;
+ || sequence.getDBRefs().size() == 0;
// TODO:
// verify sequence against the entry sequence
int startShift = absStart - sequenceStart + 1;
if (startShift != 0)
{
- modified |= sequence.getFeatures().shiftFeatures(startShift);
+ modified |= sequence.getFeatures().shiftFeatures(1,
+ startShift);
}
}
}
// and remove it from the rest
// TODO: decide if we should remove annotated sequence from set
sdataset.remove(sequence);
- // TODO: should we make a note of sequences that have received new DB
- // ids, so we can query all enabled DAS servers for them ?
}
}
return modified;
}
+ Map<String, FeatureSettingsModelI> featureDisplaySettings = null;
+
+ private void addFeatureSettings(DbSourceProxy dbSourceProxy)
+ {
+ FeatureSettingsModelI fsettings = dbSourceProxy
+ .getFeatureColourScheme();
+ if (fsettings != null)
+ {
+ if (featureDisplaySettings == null)
+ {
+ featureDisplaySettings = new HashMap<>();
+ }
+ featureDisplaySettings.put(dbSourceProxy.getDbName(), fsettings);
+ }
+ }
+
+ /**
+ *
+ * @return any feature settings associated with sources that have provided sequences
+ */
+ public List<FeatureSettingsModelI>getFeatureSettingsModels()
+ {
+ return featureDisplaySettings == null
+ ? Arrays.asList(new FeatureSettingsModelI[0])
+ : Arrays.asList(featureDisplaySettings.values()
+ .toArray(new FeatureSettingsModelI[1]));
+ }
/**
* Adds the message to the list unless it already contains it
*
*/
private SequenceI[] recoverDbSequences(SequenceI[] sequencesArray)
{
- Vector<SequenceI> nseq = new Vector<SequenceI>();
- for (int i = 0; sequencesArray != null
- && i < sequencesArray.length; i++)
+ int n;
+ if (sequencesArray == null || (n = sequencesArray.length) == 0)
+ return sequencesArray;
+ ArrayList<SequenceI> nseq = new ArrayList<>();
+ for (int i = 0;i < n; i++)
{
- nseq.addElement(sequencesArray[i]);
- DBRefEntry[] dbr = sequencesArray[i].getDBRefs();
+ nseq.add(sequencesArray[i]);
+ List<DBRefEntry> dbr = sequencesArray[i].getDBRefs();
Mapping map = null;
- for (int r = 0; (dbr != null) && r < dbr.length; r++)
+ if (dbr != null)
{
- if ((map = dbr[r].getMap()) != null)
+ for (int r = 0, rn = dbr.size(); r < rn; r++)
{
- if (map.getTo() != null && !nseq.contains(map.getTo()))
+ if ((map = dbr.get(r).getMap()) != null)
{
- nseq.addElement(map.getTo());
- }
+ if (map.getTo() != null && !nseq.contains(map.getTo()))
+ {
+ nseq.add(map.getTo());
+ }
+ }
}
}
}
+ // BH 2019.01.25 question here if this is the right logic. Return the original if nothing found?
if (nseq.size() > 0)
{
- sequencesArray = new SequenceI[nseq.size()];
- nseq.toArray(sequencesArray);
+ return nseq.toArray(new SequenceI[nseq.size()]);
}
return sequencesArray;
}