/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.ws;
import jalview.bin.Instance;
import jalview.datamodel.DBRefSource;
import jalview.ext.ensembl.EnsemblGene;
import jalview.ws.dbsources.Uniprot;
import jalview.ws.seqfetcher.ASequenceFetcher;
import jalview.ws.seqfetcher.DbSourceProxy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Thread safe construction of database proxies. This implements the run-time
* discovery of sequence database clients.
*
* TODO: extend to a configurable database plugin mechanism where classes are
* instantiated by reflection and queried for their DbRefSource and version
* association.
*/
public class SequenceFetcher extends ASequenceFetcher
{
/**
* Returns a new SequenceFetcher singleton, or a mock object if one has been
* set. Used by CrossRef and java.gui.SequenceFetcher.
*
* @return
*/
public static SequenceFetcher getInstance()
{
Instance j = Instance.getInstance();
return (j.sequenceFetcher == null
? j.sequenceFetcher = new SequenceFetcher()
: j.sequenceFetcher);
}
/**
*
* This public constructor is only is for use by testng to anonymously
* subclass SequenceFetcher.
*
*
*/
public SequenceFetcher()
{
addAllDatabases();
}
/**
* Set the instance object to use (intended for unit testing with mock
* objects).
*
* Be sure to reset to null in the tearDown method of any tests!
*
* @param sf
*/
public static void setSequenceFetcher(SequenceFetcher sf)
{
Instance.getInstance().sequenceFetcher = sf;
}
public void addAllDatabases()
{
addDBRefSourceImpl(EnsemblGene.class); // includes EnsemblGenomes.class
addDBRefSourceImpl(Uniprot.class); // includes UniprotName.class
// addDBRefSourceImpl(EmblSource.class);
// addDBRefSourceImpl(EmblCdsSource.class);
// addDBRefSourceImpl(Pdb.class);
// addDBRefSourceImpl(PfamFull.class);
// addDBRefSourceImpl(PfamSeed.class);
// addDBRefSourceImpl(RfamSeed.class);
addDBRefSourceImpl(DBRefSource.EMBL,
"jalview.ws.dbsources.EmblSource");
addDBRefSourceImpl(DBRefSource.EMBLCDS,
"jalview.ws.dbsources.EmblCdsSource");
addDBRefSourceImpl(DBRefSource.PDB, "jalview.ws.dbsources.Pdb");
addDBRefSourceImpl(DBRefSource.PFAM_FULL,
"jalview.ws.dbsources.PfamFull");
addDBRefSourceImpl(DBRefSource.PFAM_SEED,
"jalview.ws.dbsources.PfamSeed");
addDBRefSourceImpl(DBRefSource.RFAM_SEED,
"jalview.ws.dbsources.RfamSeed");
}
/**
* return an ordered list of database sources excluding alignment only
* databases
*/
public String[] getNonAlignmentSources()
{
String[] srcs = this.getSupportedDb();
List src = new ArrayList<>();
outer: for (int i = 0; i < srcs.length; i++)
{
for (DbSourceProxy dbs : getSourceProxy(srcs[i]))
{
// Skip the alignment databases for the moment - they're not useful for
// verifying a single sequence against its reference source
if (dbs.isAlignmentSource())
{
continue outer;
}
}
src.add(srcs[i]);
}
Collections.sort(src, String.CASE_INSENSITIVE_ORDER);
return src.toArray(new String[src.size()]);
}
}