org.bridgedb.DataSource - java examples

Here are the examples of the java api org.bridgedb.DataSource taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

135 Examples 7

19 View Complete Implementation : SQLIdMapper.java
Copyright Apache License 2.0
Author : bridgedb
protected final String[] toCodes(DataSource[] tgtDataSources) {
    if (tgtDataSources == null || tgtDataSources.length == 0) {
        return new String[0];
    }
    String[] results = new String[tgtDataSources.length];
    for (int i = 0; i < tgtDataSources.length; i++) {
        results[i] = tgtDataSources[i].getSystemCode();
    }
    return results;
}

19 View Complete Implementation : Lens.java
Copyright Apache License 2.0
Author : bridgedb
public final void addAllowedMiddleSource(String allowedMiddleSource) {
    DataSource dataSource = DataSource.getExistingByFullName(allowedMiddleSource);
    addAllowedMiddleSource(dataSource);
}

19 View Complete Implementation : Attributes.java
Copyright Apache License 2.0
Author : bridgedb
protected void doInit() throws ResourceException {
    super.doInit();
    try {
        // Required parameters
        String id = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_ID));
        String dsName = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_SYSTEM));
        DataSource dataSource = parseDataSource(dsName);
        if (dataSource == null) {
            throw new IllegalArgumentException("Unknown datasource: " + dsName);
        }
        xref = new Xref(id, dataSource);
        attrType = (String) getRequest().getAttributes().get(IDMapperService.PAR_TARGET_ATTR_NAME);
    } catch (Exception e) {
        throw new ResourceException(e);
    }
}

19 View Complete Implementation : XrefExists.java
Copyright Apache License 2.0
Author : bridgedb
protected void doInit() throws ResourceException {
    super.doInit();
    try {
        String id = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_ID));
        String dsName = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_SYSTEM));
        DataSource dataSource = parseDataSource(dsName);
        if (dataSource == null) {
            throw new IllegalArgumentException("Unknown datasource: " + dsName);
        }
        xref = new Xref(id, dataSource);
    } catch (Exception e) {
        throw new ResourceException(e);
    }
}

19 View Complete Implementation : DataNodeListExporter.java
Copyright Apache License 2.0
Author : PathVisio
public void setResultDataSource(DataSource value) {
    resultDs = value;
}

19 View Complete Implementation : Batch.java
Copyright Apache License 2.0
Author : bridgedb
/**
 * @author nuno
 */
public clreplaced Batch extends IDMapperResource {

    private DataSource sourceDs;

    private DataSource targetDs;

    /* (non-Javadoc)
	 * @see src.org.bridgedb.server.IDMapperResource#doInit()
	 */
    protected void doInit() throws ResourceException {
        super.doInit();
        try {
            System.out.println("Batch Xrefs.doInit start");
            // Required parameters
            String dsName = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_SYSTEM));
            sourceDs = parseDataSource(dsName);
            String targetDsName = (String) getRequest().getAttributes().get(IDMapperService.PAR_TARGET_SYSTEM);
            targetDs = parseDataSource(targetDsName);
            if (targetDsName != null) {
                targetDs = parseDataSource(urlDecode(targetDsName));
            }
        } catch (Exception e) {
            throw new ResourceException(e);
        }
    }

    /**
     * @param enreplacedy
     * @return
     */
    @Post
    public String accept(Representation enreplacedy) {
        String result = null;
        if (sourceDs != null) {
            result = oneDataSource(enreplacedy);
        } else {
            result = multiDataSource(enreplacedy);
        }
        return result;
    }

    /**
     * @param enreplacedy
     * @return
     */
    public String multiDataSource(Representation enreplacedy) {
        System.out.println("Batch Multi Xrefs.getXrefs() start");
        try {
            // The result set
            String[] splitXrefs = enreplacedy.getText().split("\n");
            IDMapper mapper = getIDMappers();
            StringBuilder result = new StringBuilder();
            for (String line : splitXrefs) {
                String[] lineSplit = line.split("\t");
                String id = lineSplit[0].trim();
                DataSource ds = parseDataSource(lineSplit[1]);
                Xref source = new Xref(lineSplit[0].trim(), ds);
                Set<Xref> xrefs;
                if (targetDs == null)
                    xrefs = mapper.mapID(source);
                else
                    xrefs = mapper.mapID(source, targetDs);
                if (xrefs.isEmpty()) {
                    result.append(id.trim());
                    result.append("\t");
                    result.append(ds.getFullName());
                    result.append("\t");
                    result.append("N/A");
                    result.append("\n");
                } else {
                    result.append(id.trim());
                    result.append("\t");
                    result.append(ds.getFullName());
                    result.append("\t");
                    Iterator<Xref> iter = xrefs.iterator();
                    result.append(iter.next());
                    while (iter.hasNext()) {
                        result.append("," + iter.next());
                    }
                    result.append("\n");
                }
            }
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
            setStatus(Status.SERVER_ERROR_INTERNAL);
            return e.getMessage();
        }
    }

    /**
     * @param enreplacedy
     * @return
     */
    public String oneDataSource(Representation enreplacedy) {
        System.out.println("Batch Xrefs.getXrefs() start");
        try {
            // The result set
            String[] splitXrefs = enreplacedy.getText().split("\n");
            IDMapper mapper = getIDMappers();
            StringBuilder result = new StringBuilder();
            for (String id : splitXrefs) {
                Xref xref = new Xref(id.trim(), sourceDs);
                Set<Xref> xrefs;
                if (targetDs == null)
                    xrefs = mapper.mapID(xref);
                else
                    xrefs = mapper.mapID(xref, targetDs);
                if (xrefs.isEmpty()) {
                    result.append(id.trim());
                    result.append("\t");
                    result.append(sourceDs.getFullName());
                    result.append("\t");
                    result.append("N/A");
                    result.append("\n");
                } else {
                    result.append(id.trim());
                    result.append("\t");
                    result.append(sourceDs.getFullName());
                    result.append("\t");
                    Iterator<Xref> iter = xrefs.iterator();
                    result.append(iter.next());
                    while (iter.hasNext()) {
                        result.append("," + iter.next());
                    }
                    result.append("\n");
                }
            }
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
            setStatus(Status.SERVER_ERROR_INTERNAL);
            return e.getMessage();
        }
    }

    /* (non-Javadoc)
	 * @see src.org.bridgedb.server.IDMapperResource#parseDataSource(String)
	 */
    protected DataSource parseDataSource(String dsName) {
        if (dsName == null)
            return null;
        DataSource ds = null;
        // Try parsing by full name
        if (DataSource.getFullNames().contains(dsName)) {
            ds = DataSource.getExistingByFullName(dsName);
        } else {
            // If not possible, use system code
            ds = DataSource.getExistingBySystemCode(dsName);
        }
        return ds;
    }
}

19 View Complete Implementation : Lens.java
Copyright Apache License 2.0
Author : bridgedb
protected final void addAllowedMiddleSources(Collection<DataSource> dataSources) {
    for (DataSource dataSource : dataSources) {
        addAllowedMiddleSource(dataSource);
    }
}

19 View Complete Implementation : BridgeDBRdfHandler.java
Copyright Apache License 2.0
Author : bridgedb
private DataSource getDataSource(RepositoryConnection repositoryConnection, Resource dataSourceResource) throws BridgeDBException, RepositoryException {
    DataSource result = dataSourceRegister.get(dataSourceResource);
    if (result == null) {
        result = readDataSource(repositoryConnection, dataSourceResource);
        dataSourceRegister.put(dataSourceResource, result);
    }
    return result;
}

19 View Complete Implementation : XrefBean.java
Copyright Apache License 2.0
Author : bridgedb
public Xref asXref() {
    DataSource ds = DataSourceBean.asDataSource(dataSource);
    return new Xref(id, ds);
}

19 View Complete Implementation : TransitiveGraph.java
Copyright Apache License 2.0
Author : bridgedb
/**
 * Update the target and source maps with the given set of new, valid paths.
 */
private void indexPaths(Set<Path> set) {
    for (Path p : set) {
        DataSource source = p.getSource();
        DataSource target = p.getTarget();
        InternalUtils.multiMapPut(sourceMap, source, p);
        InternalUtils.multiMapPut(targetMap, target, p);
    }
}

19 View Complete Implementation : BridgeDBRdfHandler.java
Copyright Apache License 2.0
Author : bridgedb
protected static Resource asCodeMapperResource(DataSource dataSource) {
    if (dataSource.getFullName() == null) {
        return new URIImpl(BridgeDBConstants.CODE_MAPPER1 + "_bysysCode_" + scrub(dataSource.getSystemCode()));
    } else {
        return new URIImpl(BridgeDBConstants.CODE_MAPPER1 + "_" + scrub(dataSource.getFullName()));
    }
}

19 View Complete Implementation : ImportInformation.java
Copyright Apache License 2.0
Author : PathVisio
/**
 * Sets the data source to use for all imported identifiers.
 * Only meaningful if getSyscodeColumn returns false.
 */
public void setDataSource(DataSource value) {
    ds = value;
}

19 View Complete Implementation : BridgeDBRdfHandler.java
Copyright Apache License 2.0
Author : bridgedb
protected static Resource asResource(DataSource dataSource) {
    if (dataSource.getFullName() == null) {
        return new URIImpl(BridgeDBConstants.DATA_SOURCE1 + "_bysysCode_" + scrub(dataSource.getSystemCode()));
    } else {
        return new URIImpl(BridgeDBConstants.DATA_SOURCE1 + "_" + scrub(dataSource.getFullName()));
    }
}

19 View Complete Implementation : IsMappingSupported.java
Copyright Apache License 2.0
Author : bridgedb
public clreplaced IsMappingSupported extends IDMapperResource {

    DataSource srcDs;

    DataSource destDs;

    protected void doInit() throws ResourceException {
        super.doInit();
        try {
            // Required parameters
            String dsName = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_SOURCE_SYSTEM));
            srcDs = parseDataSource(dsName);
            if (srcDs == null) {
                throw new IllegalArgumentException("Unknown datasource: " + dsName);
            }
            dsName = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_DEST_SYSTEM));
            destDs = parseDataSource(dsName);
            if (destDs == null) {
                throw new IllegalArgumentException("Unknown datasource: " + dsName);
            }
        } catch (Exception e) {
            throw new ResourceException(e);
        }
    }

    @Get
    public String isMappingSupported() {
        try {
            IDMapper m = getIDMappers();
            boolean supported = m.getCapabilities().isMappingSupported(srcDs, destDs);
            return "" + supported;
        } catch (Exception e) {
            e.printStackTrace();
            setStatus(Status.SERVER_ERROR_INTERNAL);
            return e.getMessage();
        }
    }
}

18 View Complete Implementation : EUGeneExporter.java
Copyright Apache License 2.0
Author : PathVisio
/**
 * Exports to pathway format understood by the EuGene
 * pathway statistics program.
 * This format is basically a list of genes in a flat text file
 * preceded by 3 header lines.
 *
 * EuGene supports several id systems but has its own naming
 * for them, this exporter also handles the translation.
 */
public clreplaced EUGeneExporter implements PathwayExporter {

    public String[] getExtensions() {
        return new String[] { "pwf" };
    }

    public String getName() {
        return "Eu.Gene pathway";
    }

    public void doExport(File file, Pathway pathway) throws ConverterException {
        EUGenePathway eugPathway = new EUGenePathway(pathway);
        try {
            eugPathway.writeToEUGene(file);
        } catch (Exception e) {
            throw new ConverterException(e);
        }
    }

    private static clreplaced EUGenePathway {

        Logger log = Logger.log;

        Pathway pathway;

        // The annotation system
        DataSource system;

        List<Xref> refs;

        public EUGenePathway(Pathway p) {
            pathway = p;
            read();
        }

        void writeToEUGene(File file) throws FileNotFoundException {
            String euGeneSystem = null;
            StringBuilder geneString = new StringBuilder();
            StringBuilder missedGenes = new StringBuilder();
            euGeneSystem = getEUGeneSystem();
            for (Xref ref : refs) {
                DataSource ds = ref.getDataSource();
                String id = ref.getId();
                if (ds == system) {
                    // Check if gene is of most occuring system
                    geneString.append(id + "\n");
                } else {
                    missedGenes.append(id + "|" + ds.getSystemCode() + "; ");
                    log.error("id '" + id + "' differs from pathway annotation system");
                }
            }
            // Write the file
            PrintStream out = null;
            out = new PrintStream(file);
            // Print the data
            out.println("//PATHWAY_NAME = " + pathway.getMappInfo().getMapInfoName());
            out.println("//PATHWAY_SOURCE = GenMAPP");
            out.println("//PATHWAY_MARKER = " + euGeneSystem);
            if (missedGenes.length() > 0)
                out.println("//LOST_DURING_CONVERSION: " + missedGenes);
            out.print(geneString);
            out.close();
        }

        void read() {
            refs = new ArrayList<Xref>();
            Map<DataSource, Integer> codeCount = new HashMap<DataSource, Integer>();
            for (PathwayElement elm : pathway.getDataObjects()) {
                if (elm.getObjectType() != ObjectType.DATANODE) {
                    // Skip non-datanodes
                    continue;
                }
                Xref ref = elm.getXref();
                DataSource ds = ref.getDataSource();
                if (ref == null || ref.getId().equals("") || ref.getDataSource() == null) {
                    // Skip datanodes with incomplete annotation
                    continue;
                }
                refs.add(ref);
                // Increase code count for this code
                if (codeCount.containsKey(ref.getDataSource()))
                    codeCount.put(ds, codeCount.get(ds) + 1);
                else
                    codeCount.put(ds, 1);
            }
            // Get most occuring systemcode
            DataSource maxCode = null;
            for (DataSource ds : codeCount.keySet()) {
                if (maxCode == null || codeCount.get(ds) > codeCount.get(maxCode)) {
                    maxCode = ds;
                }
            }
            system = maxCode;
            if (system == null) {
                // May occur when no identifiers available
                system = BioDataSource.ENSEMBL;
            }
            if (codeCount.keySet().size() > 1) {
                log.warn("\tThis pathway contains genes with different SystemCodes; '" + maxCode + "' has the highest occurence and is therefore chosen as PATHWAY_MARKER" + " for the EUGene file\n\t Other SystemCodes found and their occurences: " + codeCount);
            }
        }

        String getEUGeneSystem() {
            if (systemMappings.containsKey(system)) {
                return systemMappings.get(system);
            } else {
                return system.getFullName();
            }
        }
    }

    private static Map<DataSource, String> systemMappings;

    private static final String[] EU_GENE_SYSTEMS = new String[] { "ENSEMBL_GENE_ID", "UNIPROT", "ENTREZ", "UNIGENE", "AFFYMETRIX", "AGILENT", "HGNC", "PDB_ID", "SGD_ID" };

    private static final DataSource[] GENMAPP_SYSTEMS = new DataSource[] { BioDataSource.ENSEMBL, BioDataSource.UNIPROT, BioDataSource.ENTREZ_GENE, BioDataSource.UNIGENE, BioDataSource.AFFY, BioDataSource.AGILENT, BioDataSource.HUGO, BioDataSource.PDB, BioDataSource.SGD };

    static {
        systemMappings = new HashMap<DataSource, String>();
        for (int i = 0; i < EU_GENE_SYSTEMS.length; i++) {
            systemMappings.put(GENMAPP_SYSTEMS[i], EU_GENE_SYSTEMS[i]);
        }
    }

    @Override
    public List<String> getWarnings() {
        return Collections.emptyList();
    }

    @Override
    public void doExport(File file, Pathway pathway, int zoom) throws ConverterException {
    // TODO Auto-generated method stub
    }
}

18 View Complete Implementation : BioDataSource.java
Copyright Apache License 2.0
Author : bridgedb
/**
 * @deprecated use resources.org.bridgedb.bio.datasources.txt instead
 *
 * Definition of many common biological DataSources.
 * Meta data about these Data Sources, such as URL templates,
 * are read from a bundled text file. Call the init() method
 * at the start of your program to initialize all meta data.
 */
public clreplaced BioDataSource {

    public static final DataSource TAIR = DataSource.register("A", "TAIR").asDataSource();

    public static final DataSource AGILENT = DataSource.register("Ag", "Agilent").asDataSource();

    public static final DataSource BIOGRID = DataSource.register("Bg", "BioGrid").asDataSource();

    public static final DataSource BIOCYC = DataSource.register("Bc", "BioCyc").asDataSource();

    public static final DataSource CCDS = DataSource.register("Cc", "CCDS").asDataSource();

    public static final DataSource CAS = DataSource.register("Ca", "CAS").asDataSource();

    public static final DataSource CHEBI = DataSource.register("Ce", "ChEBI").asDataSource();

    public static final DataSource HMDB = DataSource.register("Ch", "HMDB").asDataSource();

    public static final DataSource KEGG_COMPOUND = DataSource.register("Ck", "KEGG Compound").asDataSource();

    /**
     * @deprecated use one of the organism-specific system codes instead
     */
    // Oct 29 2013 Christian: Had to add this back in for Examples/ChebiPubchemExample.java to work!
    public static final DataSource PUBCHEM = DataSource.register("Cp", "PubChem").asDataSource();

    public static final DataSource PUBCHEM_SUBSTANCE = DataSource.register("Cps", "PubChem-substance").asDataSource();

    public static final DataSource PUBCHEM_COMPOUND = DataSource.register("Cpc", "PubChem-compound").asDataSource();

    public static final DataSource CHEMSPIDER = DataSource.register("Cs", "Chemspider").asDataSource();

    public static final DataSource SGD = DataSource.register("D", "SGD").asDataSource();

    public static final DataSource ENZYME_CODE = DataSource.register("E", "Enzyme Nomenclature").asDataSource();

    public static final DataSource ECOLI = DataSource.register("Ec", "EcoGene").asDataSource();

    public static final DataSource EMBL = DataSource.register("Em", "EMBL").asDataSource();

    public static final DataSource ENSEMBL = DataSource.register("En", "Ensembl").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_MOSQUITO = DataSource.register("EnAg", "Ensembl Mosquito").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource GRAMENE_ARABIDOPSIS = DataSource.register("EnAt", "Gramene Arabidopsis").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_BSUBTILIS = DataSource.register("EnBs", "Ensembl B. subtilis").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_COW = DataSource.register("EnBt", "Ensembl Cow").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_CELEGANS = DataSource.register("EnCe", "Ensembl C. elegans").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_DOG = DataSource.register("EnCf", "Ensembl Dog").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_FRUITFLY = DataSource.register("EnDm", "Ensembl Fruitfly").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_ZEBRAFISH = DataSource.register("EnDr", "Ensembl Zebrafish").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_ECOLI = DataSource.register("EnEc", "Ensembl E. coli").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_CHICKEN = DataSource.register("EnGg", "Ensembl Chicken").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_HUMAN = DataSource.register("EnHs", "Ensembl Human").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_MOUSE = DataSource.register("EnMm", "Ensembl Mouse").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_MTUBERCULOSIS = DataSource.register("EnMx", "Ensembl M. tuberculosis").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource GRAMENE_RICE = DataSource.register("EnOj", "Gramene Rice").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_CHIMP = DataSource.register("EnPt", "Ensembl Chimp").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_HORSE = DataSource.register("EnQc", "Ensembl Horse").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_RAT = DataSource.register("EnRn", "Ensembl Rat").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_SCEREVISIAE = DataSource.register("EnSc", "Ensembl Yeast").asDataSource();

    /**
     * @deprecated use ENSEMBL instead
     */
    public static final DataSource ENSEMBL_XENOPUS = DataSource.register("EnXt", "Ensembl Xenopus").asDataSource();

    public static final DataSource FLYBASE = DataSource.register("F", "FlyBase").asDataSource();

    public static final DataSource GENBANK = DataSource.register("G", "GenBank").asDataSource();

    public static final DataSource CODELINK = DataSource.register("Ge", "CodeLink").asDataSource();

    public static final DataSource GRAMENE_GENES_DB = DataSource.register("Gg", "Gramene Genes DB").asDataSource();

    public static final DataSource GRAMENE_LITERATURE = DataSource.register("Gl", "Gramene Literature").asDataSource();

    public static final DataSource GRAMENE_PATHWAY = DataSource.register("Gp", "Gramene Pathway").asDataSource();

    public static final DataSource GENE_WIKI = DataSource.register("Gw", "Gene Wiki").asDataSource();

    public static final DataSource HUGO = DataSource.register("H", "HGNC").asDataSource();

    public static final DataSource HSGENE = DataSource.register("Hs", "HsGene").asDataSource();

    public static final DataSource INTERPRO = DataSource.register("I", "InterPro").asDataSource();

    public static final DataSource ILLUMINA = DataSource.register("Il", "Illumina").asDataSource();

    public static final DataSource IPI = DataSource.register("Ip", "IPI").asDataSource();

    public static final DataSource IRGSP_GENE = DataSource.register("Ir", "IRGSP Gene").asDataSource();

    public static final DataSource KEGG_GENES = DataSource.register("Kg", "KEGG Genes").asDataSource();

    public static final DataSource ENTREZ_GENE = DataSource.register("L", "Entrez Gene").asDataSource();

    public static final DataSource MGI = DataSource.register("M", "MGI").asDataSource();

    public static final DataSource MIRBASE = DataSource.register("Mb", "miRBase Sequence").asDataSource();

    public static final DataSource MIRBASE_MATURE = DataSource.register("Mbm", "miRBase mature sequence").asDataSource();

    public static final DataSource MAIZE_GDB = DataSource.register("Mg", "MaizeGDB").asDataSource();

    public static final DataSource NASC_GENE = DataSource.register("N", "NASC Gene").asDataSource();

    public static final DataSource NUGOWIKI = DataSource.register("Nw", "NuGO wiki").asDataSource();

    public static final DataSource OTHER = DataSource.register("O", "Other").asDataSource();

    public static final DataSource ORYZA_BASE = DataSource.register("Ob", "Oryzabase").asDataSource();

    public static final DataSource OMIM = DataSource.register("Om", "OMIM").asDataSource();

    public static final DataSource RICE_ENSEMBL_GENE = DataSource.register("Os", "Rice Ensembl Gene").asDataSource();

    public static final DataSource PDB = DataSource.register("Pd", "PDB").asDataSource();

    public static final DataSource PFAM = DataSource.register("Pf", "Pfam").asDataSource();

    public static final DataSource PLANTGDB = DataSource.register("Pl", "PlantGDB").asDataSource();

    public static final DataSource REFSEQ = DataSource.register("Q", "RefSeq").asDataSource();

    public static final DataSource RGD = DataSource.register("R", "RGD").asDataSource();

    public static final DataSource REACTOME = DataSource.register("Re", "Reactome").asDataSource();

    public static final DataSource KEGG_REACTION = DataSource.register("Rk", "KEGG Reaction").asDataSource();

    public static final DataSource RFAM = DataSource.register("Rf", "Rfam").asDataSource();

    /**
     * NB the UNIPROT datasource is for Uniprot accession numbers like P12345
     */
    public static final DataSource UNIPROT = DataSource.register("S", "Uniprot-TrEMBL").asDataSource();

    /**
     * THE UNIPROT_SWISSPROT datasource is for id's like P53_HUMAN
     */
    public static final DataSource UNIPROT_SWISSPROT = DataSource.register("Sp", "Uniprot-SwissProt").asDataSource();

    public static final DataSource SNP = DataSource.register("Sn", "dbSNP").asDataSource();

    public static final DataSource GENE_ONTOLOGY = DataSource.register("T", "GeneOntology").asDataSource();

    public static final DataSource TAXONOMY_NCBI = DataSource.register("Tn", "NCBI Taxonomy Database").asDataSource();

    public static final DataSource TIGR = DataSource.register("Ti", "TIGR").asDataSource();

    public static final DataSource TUBERCULIST = DataSource.register("Tb", "TubercuList").asDataSource();

    public static final DataSource UNIGENE = DataSource.register("U", "UniGene").asDataSource();

    public static final DataSource UCSC = DataSource.register("Uc", "UCSC Genome Browser").asDataSource();

    public static final DataSource WORMBASE = DataSource.register("W", "WormBase").asDataSource();

    public static final DataSource WIKIGENE = DataSource.register("Wg", "WikiGenes").asDataSource();

    public static final DataSource WIKIPEDIA = DataSource.register("Wi", "Wikipedia").asDataSource();

    public static final DataSource WIKIPATHWAYS = DataSource.register("Wp", "WikiPathways").asDataSource();

    public static final DataSource WHEAT_GENE_NAMES = DataSource.register("Wn", "Wheat gene names").asDataSource();

    public static final DataSource WHEAT_GENE_REFERENCES = DataSource.register("Wr", "Wheat gene refs").asDataSource();

    public static final DataSource AFFY = DataSource.register("X", "Affy").asDataSource();

    public static final DataSource ZFIN = DataSource.register("Z", "ZFIN").asDataSource();

    public static final DataSource RHEA = DataSource.register("Rh", "Rhea").asDataSource();

    public static final DataSource MACIE = DataSource.register("Ma", "MACiE").asDataSource();

    public static final DataSource UNIPATHWAY = DataSource.register("Up", "Unipathway").asDataSource();

    /* 
	 * Make patterns of regular expressions for matching 
	 * the gene identifiers with specific gene databases.
	 * (see, 
	 * http://www.childrens-mercy.org/stats/model/arrayDataManagement.htm ) 
	 */
    private static final Map<Organism, DataSource> ensemblBySpecies = new HashMap<Organism, DataSource>();

    /**
     *  @deprecated use datasources.txt instead
     */
    static {
        // sgd
        DataSourcePatterns.registerPattern(BioDataSource.TAXONOMY_NCBI, Pattern.compile("\\d+"));
        // sgd
        DataSourcePatterns.registerPattern(BioDataSource.SGD, Pattern.compile("S\\d{9}"));
        // flybase
        DataSourcePatterns.registerPattern(BioDataSource.FLYBASE, Pattern.compile("(C[RG]\\d{4,5}|FBgn\\d{7})"));
        // genbank (http://www.ncbi.nlm.nih.gov/Sequin/acc.html)
        DataSourcePatterns.registerPattern(BioDataSource.GENBANK, Pattern.compile("(\\w\\d{5})|(\\w{2}\\d{6})|(\\w{3}\\d{5})"));
        // interpro
        DataSourcePatterns.registerPattern(BioDataSource.INTERPRO, Pattern.compile("IPR\\d{6}"));
        // entrez gene
        DataSourcePatterns.registerPattern(BioDataSource.ENTREZ_GENE, Pattern.compile("\\d+"));
        // gene wiki (using entrez gene ids)
        DataSourcePatterns.registerPattern(BioDataSource.GENE_WIKI, Pattern.compile("\\d+"));
        // MGI
        DataSourcePatterns.registerPattern(BioDataSource.MGI, Pattern.compile("MGI:\\d+"));
        DataSourcePatterns.registerPattern(BioDataSource.RFAM, Pattern.compile("RF\\d+"));
        DataSourcePatterns.registerPattern(BioDataSource.IPI, Pattern.compile("IPI\\d+"));
        DataSourcePatterns.registerPattern(BioDataSource.UCSC, Pattern.compile("uc\\d{3}[a-z]{3}\\.\\d"));
        DataSourcePatterns.registerPattern(BioDataSource.ILLUMINA, Pattern.compile("ILMN_\\d+"));
        DataSourcePatterns.registerPattern(BioDataSource.MIRBASE, Pattern.compile("MI\\d+"));
        // refseq
        DataSourcePatterns.registerPattern(BioDataSource.REFSEQ, Pattern.compile("\\w{2}_\\d+"));
        // RGD
        DataSourcePatterns.registerPattern(BioDataSource.RGD, Pattern.compile("RGD:\\d+"));
        // UniProtKB/TrEMBL
        DataSourcePatterns.registerPattern(BioDataSource.UNIPROT, Pattern.compile("([A-N,R-][0-9][A-Z][A-Z,0-9][A-Z,0-9][0-9])|([O,P,Q][0-9][A-Z,0-9][A-Z,0-9][A-Z,0-9][0-9])"));
        // UniProtKB/Swiss-Prot
        DataSourcePatterns.registerPattern(BioDataSource.UNIPROT_SWISSPROT, Pattern.compile("[A-Z0-9]+_[A-Z]+"));
        // gene ontology
        DataSourcePatterns.registerPattern(BioDataSource.GENE_ONTOLOGY, Pattern.compile("GO:\\d+"));
        // unigene
        DataSourcePatterns.registerPattern(BioDataSource.UNIGENE, Pattern.compile("[A-Z][a-z][a-z]?\\.\\d+"));
        // Wormbase
        DataSourcePatterns.registerPattern(BioDataSource.WORMBASE, Pattern.compile("WBGene\\d{8}"));
        // affymetrix
        DataSourcePatterns.registerPattern(BioDataSource.AFFY, Pattern.compile(".+_at"));
        // Ensemble
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_HUMAN, Pattern.compile("ENSG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_MOUSE, Pattern.compile("ENSMUSG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_RAT, Pattern.compile("ENSRNOG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_MOSQUITO, Pattern.compile("AGAP\\d{6}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_BSUBTILIS, Pattern.compile("EBBACG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_ECOLI, Pattern.compile("EBESCG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_CHICKEN, Pattern.compile("ENSGALG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_HORSE, Pattern.compile("ENSECAG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_XENOPUS, Pattern.compile("ENSXETG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_CHIMP, Pattern.compile("ENSPTRG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_COW, Pattern.compile("ENSBTAG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_DOG, Pattern.compile("ENSCAFG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_ZEBRAFISH, Pattern.compile("ENSDARG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_MTUBERCULOSIS, Pattern.compile("EBMYCG\\d{11}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_FRUITFLY, Pattern.compile("FBgn\\d{7}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENSEMBL_SCEREVISIAE, Pattern.compile("Y[A-Z][RL]\\d{3}[WC](?:\\-[A-Z])?"));
        DataSourcePatterns.registerPattern(BioDataSource.TAIR, Pattern.compile("AT[\\dCM]G\\d{5}"));
        DataSourcePatterns.registerPattern(BioDataSource.GRAMENE_ARABIDOPSIS, Pattern.compile("AT[\\dCM]G\\d{5}\\-TAIR\\-G"));
        DataSourcePatterns.registerPattern(BioDataSource.IRGSP_GENE, Pattern.compile("Os\\d{2}g\\d+"));
        DataSourcePatterns.registerPattern(BioDataSource.GRAMENE_GENES_DB, Pattern.compile("GR:\\d+"));
        DataSourcePatterns.registerPattern(BioDataSource.BIOGRID, Pattern.compile("\\d+"));
        DataSourcePatterns.registerPattern(BioDataSource.NASC_GENE, Pattern.compile("AT[\\dCM]G\\d{5}\\-TAIR\\-G"));
        DataSourcePatterns.registerPattern(BioDataSource.PLANTGDB, Pattern.compile("PUT-[\\w\\d-]+"));
        // EMBL
        DataSourcePatterns.registerPattern(BioDataSource.EMBL, Pattern.compile("\\w{2}\\d{6}"));
        // HUGO
        DataSourcePatterns.registerPattern(BioDataSource.HUGO, Pattern.compile("[A-Z][A-Z,0-9]+"));
        // OMIM (http://www.ncbi.nlm.nih.gov/Omim/omimfaq.html#numbering_system)
        DataSourcePatterns.registerPattern(BioDataSource.OMIM, Pattern.compile("\\d{6}(\\.\\d{4})?"));
        // PDB ( http://www.rcsb.org/robohelp_f/#search_database/query_results.htm )
        DataSourcePatterns.registerPattern(BioDataSource.PDB, Pattern.compile("\\d[A-Z\\d]{3}"));
        // Pfam (http://pfam.sanger.ac.uk/help)
        DataSourcePatterns.registerPattern(BioDataSource.PFAM, Pattern.compile("(PF\\d{5})|(PB\\d{6})"));
        // Zfin (http://zfin.org/zf_info/dbase/PAPERS/ZFIN_DataModel/sectioniv_1.html)
        DataSourcePatterns.registerPattern(BioDataSource.ZFIN, Pattern.compile("ZDB.+"));
        DataSourcePatterns.registerPattern(BioDataSource.AGILENT, Pattern.compile("A_\\d+_.+"));
        DataSourcePatterns.registerPattern(BioDataSource.HMDB, Pattern.compile("HMDB\\d{5}"));
        DataSourcePatterns.registerPattern(BioDataSource.CAS, Pattern.compile("\\d+-\\d{2}-\\d{1}"));
        DataSourcePatterns.registerPattern(BioDataSource.ENZYME_CODE, Pattern.compile("(\\d+\\.){3}\\d+"));
        DataSourcePatterns.registerPattern(BioDataSource.CHEBI, Pattern.compile("CHEBI\\:\\d+"));
        DataSourcePatterns.registerPattern(BioDataSource.KEGG_COMPOUND, Pattern.compile("C\\d+"));
        DataSourcePatterns.registerPattern(BioDataSource.KEGG_GENES, Pattern.compile("[a-z]{3}:.+"));
        DataSourcePatterns.registerPattern(BioDataSource.BIOCYC, Pattern.compile("^\\w+\\:[A-Za-z0-9-]+$"));
        DataSourcePatterns.registerPattern(BioDataSource.TUBERCULIST, Pattern.compile("Rv\\d{4}(A|B|c|\\.\\d)?"));
        DataSourcePatterns.registerPattern(BioDataSource.RHEA, Pattern.compile("^\\d{5}$"));
        DataSourcePatterns.registerPattern(BioDataSource.MACIE, Pattern.compile("^M\\d{4}$"));
        DataSourcePatterns.registerPattern(BioDataSource.UNIPATHWAY, Pattern.compile("^UPA\\d{5}$"));
        ensemblBySpecies.put(Organism.BacillusSubtilis, ENSEMBL_BSUBTILIS);
        ensemblBySpecies.put(Organism.CaenorhabditisElegans, ENSEMBL_CELEGANS);
        ensemblBySpecies.put(Organism.GallusGallus, ENSEMBL_CHICKEN);
        ensemblBySpecies.put(Organism.PanTroglodytes, ENSEMBL_CHIMP);
        ensemblBySpecies.put(Organism.BosTaurus, ENSEMBL_COW);
        ensemblBySpecies.put(Organism.CanisFamiliaris, ENSEMBL_DOG);
        ensemblBySpecies.put(Organism.EscherichiaColi, ENSEMBL_ECOLI);
        ensemblBySpecies.put(Organism.DrosophilaMelanogaster, ENSEMBL_FRUITFLY);
        ensemblBySpecies.put(Organism.EquusCaballus, ENSEMBL_HORSE);
        ensemblBySpecies.put(Organism.replacedSapiens, ENSEMBL_HUMAN);
        ensemblBySpecies.put(Organism.AnophelesGambiae, ENSEMBL_MOSQUITO);
        ensemblBySpecies.put(Organism.MusMusculus, ENSEMBL_MOUSE);
        ensemblBySpecies.put(Organism.RattusNorvegicus, ENSEMBL_RAT);
        ensemblBySpecies.put(Organism.SaccharomycesCerevisiae, ENSEMBL_SCEREVISIAE);
        ensemblBySpecies.put(Organism.XenopusTropicalis, ENSEMBL_XENOPUS);
        ensemblBySpecies.put(Organism.DanioRerio, ENSEMBL_ZEBRAFISH);
        ensemblBySpecies.put(Organism.MycobacteriumTuberculosis, ENSEMBL_MTUBERCULOSIS);
        // Reactions
        DataSourcePatterns.registerPattern(BioDataSource.KEGG_REACTION, Pattern.compile("^R\\d+$"));
        DataSourcePatterns.registerPattern(BioDataSource.REACTOME, Pattern.compile("^REACT_\\d+(\\.\\d+)?$"));
    }

    /**
     * @return the species-specific Ensembl DataSource corresponding to a given organism, or null if there isn't one known.
     * @param org an organism
     * @deprecated
     */
    public static DataSource getSpeciesSpecificEnsembl(Organism org) {
        return ensemblBySpecies.get(org);
    }

    /**
     * Call this to initialize the BioDataSource.XXX constants.
     * 	You should call this before using any of these constants,
     * 	or they may be undefined.
     */
    public static void init() {
        InputStream is = BioDataSource.clreplaced.getClreplacedLoader().getResourcereplacedtream("org/bridgedb/bio/datasources.txt");
        try {
            DataSourceTxt.loadInputStream(is);
            InternalUtils.readXmlConfig(new InputSource(BioDataSource.clreplaced.getClreplacedLoader().getResourcereplacedtream("org/bridgedb/bio/datasources.xml")));
        } catch (IOException ex) {
            throw new Error(ex);
        } catch (ParserConfigurationException e) {
            throw new Error(e);
        } catch (SAXException e) {
            throw new Error(e);
        }
    }
}

18 View Complete Implementation : DataSourceHandler.java
Copyright Apache License 2.0
Author : PathVisio
private String value2label(DataSource value) {
    if (value == null)
        return null;
    String result = value.getFullName();
    if (result == null)
        result = value.getSystemCode();
    return result;
}

18 View Complete Implementation : DataSourceComparator.java
Copyright Apache License 2.0
Author : bridgedb
@Override
public int compare(DataSource dataSource1, DataSource dataSource2) {
    int result = softCompare(dataSource1.getFullName(), dataSource2.getFullName());
    if (result != 0) {
        return result;
    }
    result = softCompare(dataSource1.getSystemCode(), dataSource2.getSystemCode());
    if (result != 0) {
        return result;
    }
    return dataSource1.hashCode() - dataSource2.hashCode();
}

18 View Complete Implementation : IDMapperRdb.java
Copyright Apache License 2.0
Author : bridgedb
/**
 * {@inheritDoc}
 */
public Map<Xref, Set<Xref>> mapID(Collection<Xref> srcXrefs, DataSource... tgtDataSources) throws IDMapperException {
    return InternalUtils.mapMultiFromSingle(this, srcXrefs, tgtDataSources);
}

18 View Complete Implementation : BridgeDBRdfHandler.java
Copyright Apache License 2.0
Author : bridgedb
public static void writeRdfToFile(File file, SortedSet<DataSource> dataSources) throws BridgeDBException {
    Reporter.println("Writing DataSource RDF to " + file.getAbsolutePath());
    Repository repository = null;
    RepositoryConnection repositoryConnection = null;
    try {
        repository = new SailRepository(new MemoryStore());
        repository.initialize();
        repositoryConnection = repository.getConnection();
        for (DataSource dataSource : dataSources) {
            writeDataSource(repositoryConnection, dataSource);
        }
        OrganismRdf.addAll(repositoryConnection);
        UriPattern.addAll(repositoryConnection);
        writeRDF(repositoryConnection, file);
    } catch (Exception ex) {
        throw new BridgeDBException("Error writing RDF to file:" + ex.getMessage(), ex);
    } finally {
        shutDown(repository, repositoryConnection);
    }
}

18 View Complete Implementation : IdentifersOrgReader.java
Copyright Apache License 2.0
Author : bridgedb
private void compareDataSource(RepositoryConnection repositoryConnection, Resource catalogRecord, DataSource dataSource) throws Exception {
    String sysCode = getSingletonString(repositoryConnection, catalogRecord, IdenitifiersOrgConstants.NAMESPACE_URI);
    String fullName = getSingletonString(repositoryConnection, catalogRecord, DCatConstants.replacedLE_URI);
    if (!dataSource.getFullName().equals(fullName)) {
        System.err.println("FullName mismatch for " + dataSource.getSystemCode() + " BridgeDb has " + dataSource.getFullName() + " while miriam uses " + fullName);
    }
    if (dataSource.getAlternative() != null && !dataSource.getAlternative().equals(fullName)) {
        System.err.println("Alternative mismatch for " + dataSource.getSystemCode() + " BridgeDb has " + dataSource.getAlternative() + " while miriam uses " + fullName);
    }
}

18 View Complete Implementation : BackPageText.java
Copyright Apache License 2.0
Author : bridgedb
protected void doInit() throws ResourceException {
    super.doInit();
    try {
        System.out.println("Xrefs.doInit start");
        // Required parameters
        String id = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_ID));
        String dsName = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_SYSTEM));
        DataSource dataSource = parseDataSource(dsName);
        if (dataSource == null) {
            throw new IllegalArgumentException("Unknown datasource: " + dsName);
        }
        xref = new Xref(id, dataSource);
        // Optional parameters
        String targetDsName = (String) getRequest().getAttributes().get(IDMapperService.PAR_TARGET_SYSTEM);
        targetDs = parseDataSource(targetDsName);
    } catch (Exception e) {
        throw new ResourceException(e);
    }
}

18 View Complete Implementation : BackPageText.java
Copyright Apache License 2.0
Author : bridgedb
/**
 * Resource that handles the xref queries
 */
public clreplaced BackPageText extends IDMapperResource {

    Xref xref;

    DataSource targetDs;

    protected void doInit() throws ResourceException {
        super.doInit();
        try {
            System.out.println("Xrefs.doInit start");
            // Required parameters
            String id = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_ID));
            String dsName = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_SYSTEM));
            DataSource dataSource = parseDataSource(dsName);
            if (dataSource == null) {
                throw new IllegalArgumentException("Unknown datasource: " + dsName);
            }
            xref = new Xref(id, dataSource);
            // Optional parameters
            String targetDsName = (String) getRequest().getAttributes().get(IDMapperService.PAR_TARGET_SYSTEM);
            targetDs = parseDataSource(targetDsName);
        } catch (Exception e) {
            throw new ResourceException(e);
        }
    }

    @Get
    public String getBackPageText() {
        System.out.println("Xrefs.getBackPageText() start");
        try {
            IDMapperStack mapper = getIDMappers();
            // The result set
            Set<String> bpInfoSym = mapper.getAttributes(xref, "Symbol");
            Set<String> bpInfoDes = mapper.getAttributes(xref, "Description");
            Set<String> bpInfoTyp = mapper.getAttributes(xref, "Type");
            Set<String> bpInfoChr = mapper.getAttributes(xref, "Chromosome");
            Set<String> bpInfoSyn = mapper.getAttributes(xref, "Synonyms");
            StringBuilder result = new StringBuilder();
            result.append("<html><body><table>");
            for (String x : bpInfoSym) {
                result.append("<tr><td>Symbol</td><td>" + x + "</td></tr>");
            }
            for (String x : bpInfoDes) {
                result.append("<tr><td>Description</td><td>" + x + "</td></tr>");
            }
            for (String x : bpInfoTyp) {
                result.append("<tr><td>Type</td><td>" + x + "</td></tr>");
            }
            for (String x : bpInfoChr) {
                result.append("<tr><td>Chromosome</td><td>" + x + "</td></tr>");
            }
            for (String x : bpInfoSyn) {
                result.append("<tr><td>Synonyms</td><td>" + x + "</td></tr>");
            }
            result.append("</table></body></html>");
            return (result.toString());
        } catch (Exception e) {
            e.printStackTrace();
            setStatus(Status.SERVER_ERROR_INTERNAL);
            return e.getMessage();
        }
    }
}

18 View Complete Implementation : Batch.java
Copyright Apache License 2.0
Author : bridgedb
/* (non-Javadoc)
	 * @see src.org.bridgedb.server.IDMapperResource#parseDataSource(String)
	 */
protected DataSource parseDataSource(String dsName) {
    if (dsName == null)
        return null;
    DataSource ds = null;
    // Try parsing by full name
    if (DataSource.getFullNames().contains(dsName)) {
        ds = DataSource.getExistingByFullName(dsName);
    } else {
        // If not possible, use system code
        ds = DataSource.getExistingBySystemCode(dsName);
    }
    return ds;
}

18 View Complete Implementation : IDMapperResource.java
Copyright Apache License 2.0
Author : bridgedb
protected DataSource parseDataSource(String dsName) {
    if (dsName == null)
        return null;
    DataSource ds = null;
    // Try parsing by full name
    if (DataSource.getFullNames().contains(dsName)) {
        ds = DataSource.getByFullName(dsName);
    } else {
        // If not possible, use system code
        ds = DataSource.getBySystemCode(dsName);
    }
    return ds;
}

18 View Complete Implementation : Xrefs.java
Copyright Apache License 2.0
Author : bridgedb
protected void doInit() throws ResourceException {
    super.doInit();
    try {
        System.out.println("Xrefs.doInit start");
        // Required parameters
        String id = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_ID));
        String dsName = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_SYSTEM));
        DataSource dataSource = parseDataSource(dsName);
        if (dataSource == null) {
            throw new IllegalArgumentException("Unknown datasource: " + dsName);
        }
        xref = new Xref(id, dataSource);
        // Optional parameters
        String targetDsName = (String) getRequest().getAttributes().get(IDMapperService.PAR_TARGET_SYSTEM);
        if (targetDsName != null) {
            targetDs = parseDataSource(urlDecode(targetDsName));
        }
    } catch (Exception e) {
        throw new ResourceException(e);
    }
}

18 View Complete Implementation : Xrefs.java
Copyright Apache License 2.0
Author : bridgedb
/**
 * Resource that handles the xref queries
 */
public clreplaced Xrefs extends IDMapperResource {

    Xref xref;

    DataSource targetDs;

    protected void doInit() throws ResourceException {
        super.doInit();
        try {
            System.out.println("Xrefs.doInit start");
            // Required parameters
            String id = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_ID));
            String dsName = urlDecode((String) getRequest().getAttributes().get(IDMapperService.PAR_SYSTEM));
            DataSource dataSource = parseDataSource(dsName);
            if (dataSource == null) {
                throw new IllegalArgumentException("Unknown datasource: " + dsName);
            }
            xref = new Xref(id, dataSource);
            // Optional parameters
            String targetDsName = (String) getRequest().getAttributes().get(IDMapperService.PAR_TARGET_SYSTEM);
            if (targetDsName != null) {
                targetDs = parseDataSource(urlDecode(targetDsName));
            }
        } catch (Exception e) {
            throw new ResourceException(e);
        }
    }

    @Get
    public String getXrefs() {
        System.out.println("Xrefs.getXrefs() start");
        try {
            // The result set
            IDMapper mapper = getIDMappers();
            Set<Xref> xrefs;
            if (targetDs == null)
                xrefs = mapper.mapID(xref);
            else
                xrefs = mapper.mapID(xref, targetDs);
            StringBuilder result = new StringBuilder();
            for (Xref x : xrefs) {
                result.append(x.getId());
                result.append("\t");
                result.append(x.getDataSource().getFullName());
                result.append("\n");
            }
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
            setStatus(Status.SERVER_ERROR_INTERNAL);
            return e.getMessage();
        }
    }
}

18 View Complete Implementation : DataNodeListExporter.java
Copyright Apache License 2.0
Author : PathVisio
/**
 * Exporter that writes a pathway as a list
 * of DataNodes, using their database references
 * @author thomas
 */
public clreplaced DataNodeListExporter implements PathwayExporter {

    /**
     * Use this String as argument in {@link #setResultCode(String)}
     * to indicate that the exporter has to keep the original database
     * code as used in the pathway
     */
    // Use the id/code as in database
    public static final String DB_ORIGINAL = "original";

    private DataSource resultDs = DataSource.getBySystemCode(DB_ORIGINAL);

    private String multiRefSep = ", ";

    /**
     * Set the separator used to separate multiple
     * references for a single DataNode on the pathway.
     * Default is ", ".
     * @param sep
     */
    public void setMultiRefSep(String sep) {
        multiRefSep = sep;
    }

    /**
     * Get the separator used to separate multiple
     * references for a single DataNode on the pathway.
     * Default is ", ".
     */
    public String getMultiRefSep() {
        return multiRefSep;
    }

    /**
     * Set the database code to which every datanode
     * reference will be mapped to in the output file.
     * @see #DB_ORIGINAL
     * @param code
     * @deprecated use setResultDataSource();
     */
    public void setResultCode(String code) {
        resultDs = DataSource.getBySystemCode(code);
    }

    public void setResultDataSource(DataSource value) {
        resultDs = value;
    }

    /**
     * Get the database code to which every datanode
     * reference will be mapped to in the output file.
     * @deprecated use getResultDataSouce()
     */
    public String getResultCode() {
        return resultDs.getSystemCode();
    }

    public DataSource getResultDataSource() {
        return resultDs;
    }

    public void doExport(File file, Pathway pathway) throws ConverterException {
        if (!DB_ORIGINAL.equals(getResultCode())) {
            // Check gene database connection
            if (gdbManager == null || !gdbManager.isConnected()) {
                throw new ConverterException("No gene database loaded");
            }
        }
        PrintStream out = null;
        try {
            out = new PrintStream(new BufferedOutputStream(new FileOutputStream(file)));
        } catch (FileNotFoundException e) {
            throw new ConverterException(e);
        }
        printHeaders(out);
        for (PathwayElement elm : pathway.getDataObjects()) {
            if (elm.getObjectType() == ObjectType.DATANODE) {
                String line = "";
                String id = elm.getElementID();
                DataSource ds = elm.getDataSource();
                if (!checkString(id) || ds == null) {
                    // Skip empty id/codes
                    continue;
                }
                // Use the original id, if code is already the one asked for
                if (DB_ORIGINAL.equals(getResultCode()) || ds.equals(resultDs)) {
                    line = id + "\t" + ds.getFullName();
                } else {
                    // Lookup the cross-references for the wanted database code
                    try {
                        Set<Xref> refs = gdbManager.getCurrentGdb().mapID(elm.getXref(), resultDs);
                        for (Xref ref : refs) {
                            line += ref.getId() + multiRefSep;
                        }
                        if (line.length() > multiRefSep.length()) {
                            // Remove the last ', '
                            line = line.substring(0, line.length() - multiRefSep.length());
                            line += "\t" + resultDs.getFullName();
                        }
                    } catch (IDMapperException ex) {
                        throw new ConverterException(ex);
                    }
                }
                out.println(line);
            }
        }
        out.close();
    }

    /**
     * Print the file headers.
     * @param out The output stream to print to
     */
    protected void printHeaders(PrintStream out) {
        // print headers
        out.println("Identifier\tDatabase");
    }

    private boolean checkString(String string) {
        return string != null && string.length() > 0;
    }

    public String[] getExtensions() {
        return new String[] { "txt" };
    }

    public String getName() {
        return "DataNode list";
    }

    private GdbManager gdbManager = null;

    /**
     * Create an exporter that uses the given GdbManager
     * to lookup cross references for each datanode
     */
    public DataNodeListExporter(GdbManager gdbManager) {
        this.gdbManager = gdbManager;
    }

    public DataNodeListExporter() {
    }

    @Override
    public List<String> getWarnings() {
        return Collections.emptyList();
    }

    @Override
    public void doExport(File file, Pathway pathway, int zoom) throws ConverterException {
    // TODO Auto-generated method stub
    }
}

18 View Complete Implementation : TransitiveGraph.java
Copyright Apache License 2.0
Author : bridgedb
public boolean isTransitiveMappingSupported(DataSource src, DataSource tgt) throws IDMapperException {
    if (!(sourceMap.containsKey(src) && targetMap.containsKey(tgt)))
        return false;
    for (Path path : sourceMap.get(src)) {
        if (path.getTarget() == tgt)
            return true;
    }
    return false;
}

18 View Complete Implementation : PathwayParser.java
Copyright Apache License 2.0
Author : PathVisio
/**
 * This sax handler can be used to quickly parse pathway information from
 * a gpml file
 */
public clreplaced PathwayParser extends DefaultHandler {

    /**
     * exception occuring during parsing of pathway, most likely because
     * the input file is not properly formatted
     */
    public static clreplaced ParseException extends Exception {

        public ParseException(Exception e) {
            super(e);
        }
    }

    String name;

    private List<XrefWithSymbol> genes;

    public PathwayParser() {
        name = "";
        genes = new ArrayList<XrefWithSymbol>();
    }

    public PathwayParser(File f, XMLReader xmlReader) throws ParseException {
        this();
        xmlReader.setContentHandler(this);
        xmlReader.setEnreplacedyResolver(this);
        try {
            xmlReader.parse(new InputSource(new FileReader(f)));
        } catch (IOException e) {
            throw new ParseException(e);
        } catch (SAXException e) {
            throw new ParseException(e);
        // ignore pathways that generate an exception (return empty list)
        }
    }

    public List<XrefWithSymbol> getGenes() {
        return genes;
    }

    public String getName() {
        return name;
    }

    DataSource currentDs = null;

    String currentSymbol = null;

    String currentId = null;

    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        if (localName.equals("DataNode")) {
            currentId = null;
            currentDs = null;
            currentSymbol = attributes.getValue("TextLabel");
        } else if (localName.equals("Pathway")) {
            name = attributes.getValue("Name");
        } else if (localName.equals("Xref")) {
            String sysName = attributes.getValue("Database");
            replacedert (sysName != null);
            currentDs = DataSource.getByFullName(sysName);
            currentId = attributes.getValue("ID");
            replacedert (currentId != null);
            XrefWithSymbol currentGene = new XrefWithSymbol(currentId, currentDs, currentSymbol);
            if (// Don't add duplicate genes
            !genes.contains(currentGene))
                genes.add(currentGene);
            currentGene = null;
        }
    }

    public void error(SAXParseException e) {
        Logger.log.error("Error while parsing xml doreplacedent", e);
    }

    public void fatalError(SAXParseException e) throws SAXParseException {
        Logger.log.error("Fatal error while parsing xml doreplacedent", e);
        throw new SAXParseException("Fatal error, parsing of this doreplacedent aborted", null);
    }

    public void warning(SAXParseException e) {
        Logger.log.error("Warning while parsing xml doreplacedent", e);
    }
}

18 View Complete Implementation : SQLIdMapper.java
Copyright Apache License 2.0
Author : bridgedb
protected final String toCode(DataSource tgtDataSource) {
    if (tgtDataSource == null) {
        return null;
    }
    return tgtDataSource.getSystemCode();
}

18 View Complete Implementation : SQLListener.java
Copyright Apache License 2.0
Author : bridgedb
@Override
public int registerMappingSet(DataSource source, DataSource target, boolean symetric) throws BridgeDBException {
    int forwardId = registerMappingSet(source, target);
    if (symetric) {
        int symetricId = registerMappingSet(target, source);
    }
    return forwardId;
}

18 View Complete Implementation : SQLListener.java
Copyright Apache License 2.0
Author : bridgedb
protected final String getDataSourceKey(DataSource dataSource) {
    if (dataSource.getSystemCode() == null) {
        return FULL_NAME_PREFIX + dataSource.getFullName();
    } else {
        return dataSource.getSystemCode();
    }
}

18 View Complete Implementation : Utils.java
Copyright Apache License 2.0
Author : bridgedb
public static Xref translateDs(Xref in, DataSource base) {
    return new Xref(in.getId(), base);
}

18 View Complete Implementation : DataSourceMapBean.java
Copyright Apache License 2.0
Author : bridgedb
public static DataSourceMapBean asBean(DataSource source, Set<DataSource> tgtDataSource) {
    DataSourceMapBean bean = new DataSourceMapBean();
    bean.source = new DataSourceBean(source);
    bean.target = new ArrayList<DataSourceBean>();
    for (DataSource tgt : tgtDataSource) {
        bean.target.add(new DataSourceBean(tgt));
    }
    return bean;
}

17 View Complete Implementation : TransitiveGraph.java
Copyright Apache License 2.0
Author : bridgedb
/**
 * This is for testing. May be removed in the future.
 */
public void printMap(Map<DataSource, Set<Path>> map) {
    for (DataSource ds : map.keySet()) {
        Set<Path> collection = map.get(ds);
        System.out.println("DataSource: " + ds);
        System.out.println(" - " + collection + "\n");
    }
    System.out.println();
}

17 View Complete Implementation : EnsemblCompatibilityMapper.java
Copyright Apache License 2.0
Author : bridgedb
@Override
public Map<Xref, Set<Xref>> mapID(Collection<Xref> srcXrefs, DataSource... tgtDataSources) throws IDMapperException {
    return InternalUtils.mapMultiFromSingle(this, srcXrefs, tgtDataSources);
}

17 View Complete Implementation : IdentifersOrgReader.java
Copyright Apache License 2.0
Author : bridgedb
private void loadExtraDataSourceInfo(RepositoryConnection repositoryConnection, Resource catalogRecord, DataSource dataSource) throws RepositoryException, BridgeDBException {
    if (dataSource.getExample().getId() == null) {
        String id = getPossibleSingletonString(repositoryConnection, catalogRecord, VoidConstants.EXAMPLE_RESOURCE);
        DataSource.register(dataSource.getSystemCode(), dataSource.getFullName()).idExample(id);
    }
}

17 View Complete Implementation : IdentifersOrgReader.java
Copyright Apache License 2.0
Author : bridgedb
private void loadData(RepositoryConnection repositoryConnection) throws Exception {
    int count = 0;
    RepositoryResult<Statement> statements = repositoryConnection.getStatements(null, VoidConstants.URI_SPACE_URI, null, true);
    while (statements.hasNext()) {
        Statement statement = statements.next();
        DataSource dataSource = DataSource.getByIdentiferOrgBase(statement.getObject().stringValue());
        Resource catalogRecord = statement.getSubject();
        if (dataSource == null) {
            dataSource = readDataSource(repositoryConnection, catalogRecord, statement.getObject().stringValue());
        } else {
            compareDataSource(repositoryConnection, catalogRecord, dataSource);
        }
        loadExtraDataSourceInfo(repositoryConnection, catalogRecord, dataSource);
        Pattern regex = loadRegex(repositoryConnection, catalogRecord, dataSource);
        loadUriPatterns(repositoryConnection, catalogRecord, dataSource, regex);
        count++;
    }
}

17 View Complete Implementation : DataSourceComparatorTest.java
Copyright Apache License 2.0
Author : bridgedb
/**
 * Test of getResourceId method, of clreplaced DataSourceUris.
 */
@Test
public void testGetResourceId() {
    Reporter.println("getResourceId");
    DataSource dataSource = DataSource.getByFullName("DataSourceUrisTest_testGetResourceId");
    Resource expResult = new URIImpl("http://vocabularies.bridgedb.org/ops#DataSource_DataSourceUrisTest_testGetResourceId");
    Resource result = BridgeDBRdfHandler.asResource(dataSource);
    replacedertEquals(expResult, result);
}

17 View Complete Implementation : SQLIdMapper.java
Copyright Apache License 2.0
Author : bridgedb
// *** IDMapper Methods
@Override
public Map<Xref, Set<Xref>> mapID(Collection<Xref> srcXrefs, DataSource... tgtDataSources) throws IDMapperException {
    return InternalUtils.mapMultiFromSingle(this, srcXrefs, tgtDataSources);
}

17 View Complete Implementation : PatternChecker.java
Copyright Apache License 2.0
Author : bridgedb
/**
 * when the script is run on mutliple databases in one go, finalReport will give a summary
 * across databases
 */
private void finalReport() {
    System.out.println("=========== FINAL REPORT OF ID PATTERNS =============");
    for (DataSource ds : allTotals.elementSet()) {
        int miss = allMisses.count(ds);
        int total = allTotals.count(ds);
        System.out.println(ds + "\t" + miss + "\t" + total + "\t" + miss * 100 / total + "%");
    }
}

17 View Complete Implementation : Lens.java
Copyright Apache License 2.0
Author : bridgedb
public final void addAllowedMiddleSource(DataSource dataSource) {
    allowedMiddleSources.add(dataSource);
    allowedMiddleSysCodes.add(dataSource.getSystemCode());
}

17 View Complete Implementation : SyscodeBasedCodeMapper.java
Copyright Apache License 2.0
Author : bridgedb
@Override
public Xref toXref(IdSysCodePair pair) throws BridgeDBException {
    DataSource dataSource = DataSource.getExistingBySystemCode(pair.getSysCode());
    String id = pair.getId();
    return new Xref(id, dataSource);
}

17 View Complete Implementation : BridgeRest.java
Copyright Apache License 2.0
Author : bridgedb
/**
 * parse a single line of input.
 * @param reader reader to read line from
 * @return Xref or null if end of stream was reached
 * @throws IOException if there was an error while reading (not EOF!)
 */
private Xref parseLine(BufferedReader reader) throws IOException {
    StringBuilder builder = new StringBuilder();
    String id = null;
    int c;
    while (true) {
        // read char by char and use switch statement
        // for efficiency
        c = reader.read();
        switch(c) {
            case -1:
                // end of the stream
                return null;
            case '\n':
                DataSource ds = DataSource.getByFullName(builder.toString());
                return new Xref(id, ds);
            case '\t':
                id = builder.toString();
                builder = new StringBuilder();
                break;
            default:
                builder.append((char) c);
        }
    }
}

17 View Complete Implementation : CapabilitiesBean.java
Copyright Apache License 2.0
Author : bridgedb
@Override
public boolean isMappingSupported(DataSource src, DataSource tgt) throws BridgeDBException {
    for (DataSourceMapBean bean : supportedMapping) {
        if (DataSourceMapBean.AsDataSource(bean) == src) {
            Set<DataSource> targets = DataSourceMapBean.getMappedSet(bean);
            return targets.contains(tgt);
        }
    }
    return false;
}

17 View Complete Implementation : WSCoreService.java
Copyright Apache License 2.0
Author : bridgedb
private MappingSupportedBean isMappingSupportedInner(String sourceCode, String targetCode) throws BridgeDBException {
    if (sourceCode == null) {
        throw new BridgeDBException(WsConstants.SOURCE_DATASOURCE_SYSTEM_CODE + " parameter can not be null");
    }
    if (targetCode == null) {
        throw new BridgeDBException(WsConstants.TARGET_DATASOURCE_SYSTEM_CODE + " parameter can not be null");
    }
    DataSource src = DataSource.getExistingBySystemCode(sourceCode);
    DataSource tgt = DataSource.getExistingBySystemCode(targetCode);
    try {
        return new MappingSupportedBean(src, tgt, idMapper.getCapabilities().isMappingSupported(src, tgt));
    } catch (IDMapperException e) {
        throw BridgeDBException.convertToBridgeDB(e);
    }
}

17 View Complete Implementation : ImportInformation.java
Copyright Apache License 2.0
Author : PathVisio
/**
 * This clreplaced contains the information needed to start importing a delimited
 * text file to an expression dataset. This information can be gathered using
 * the {@link GexImportWizard} or can be filled automatically
 */
public clreplaced ImportInformation {

    /**
     * Points to the text file containing the expression data
     */
    private File txtFile;

    /**
     * Sets the text file containing the expression data
     * @param aTxtFile {@link File} to set
     */
    public void setTxtFile(File aTxtFile) throws IOException {
        if (!aTxtFile.equals(txtFile)) {
            txtFile = aTxtFile;
            readSample();
            interpretSample();
        }
    }

    /**
     * Get the private {@link File} txtFile
     * @return {@link File} object pointing to the text file that contains the
     * expression data
     */
    public File getTxtFile() {
        return txtFile;
    }

    private String dbName;

    /**
     * The database name in which the expression data is saved
     */
    public void setGexName(String value) {
        dbName = value;
    }

    /**
     * The database name in which the expression data is saved
     */
    public String getGexName() {
        return dbName;
    }

    private double maximum;

    private double minimum;

    /**
     * get/set maximum double value in this dataset
     */
    public double getMaximum() {
        return maximum;
    }

    public void setMaximum(double setpoint) {
        maximum = setpoint;
    }

    /**
     * get/set minimum double value in this dataset
     */
    public double getMinimum() {
        return minimum;
    }

    public void setMinimum(double setpoint) {
        minimum = setpoint;
    }

    private List<String> errorList = new ArrayList<String>();

    /**
     * Returns a list of errors made during importing data, the same list as saved
     * in the error file (.ex.txt)
     */
    public List<String> getErrorList() {
        return errorList;
    }

    /**
     * A error has been reported during importing data. The message is added to
     * the list of errors.
     */
    public void addError(String message) {
        errorList.add(message);
    }

    private int firstDataRow = 1;

    /**
     * linenumber (first line is 0) of the line where the data begins
     */
    public int getFirstDataRow() {
        return firstDataRow;
    }

    /**
     * linenumber (first line is 0) of the line where the data begins
     */
    public void setFirstDataRow(int value) {
        replacedert (value >= 0);
        firstDataRow = value;
        if (firstHeaderRow > firstDataRow) {
            firstHeaderRow = firstDataRow;
        }
    }

    private int firstHeaderRow;

    /**
     * linenumber (first line is 0) of the line where the header begins.
     */
    public int getFirstHeaderRow() {
        return firstHeaderRow;
    }

    /**
     * linenumber (first line is 0) of the line where the header begins.
     * firstHeaderRow must be <= firstDataRow, so it will be set to the next line if that happens.
     */
    public void setFirstHeaderRow(int value) {
        replacedert (value >= 0);
        firstHeaderRow = value;
        if (firstHeaderRow > firstDataRow) {
            firstDataRow = firstHeaderRow + 1;
        }
    }

    public boolean isHeaderRow(int row) {
        return row >= firstHeaderRow && row < firstDataRow;
    }

    public boolean isDataRow(int row) {
        return row >= firstDataRow;
    }

    /**
     * linenumber (first line is 0) of the line containing the column headers
     */
    int headerRow = 0;

    /**
     * Column number (first column is 0) of the column containing the gene identifier
     */
    private int idColumn = 0;

    public int getIdColumn() {
        return idColumn;
    }

    public void setIdColumn(int value) {
        idColumn = value;
    }

    private int syscodeColumn = 1;

    /**
     * Column number (first column is 0) of the column containing the system code
     */
    public int getSyscodeColumn() {
        return syscodeColumn;
    }

    /**
     * Column number (first column is 0) of the column containing the system code
     */
    public void setSysodeColumn(int value) {
        syscodeColumn = value;
    }

    /**
     * Various possible column types
     */
    public enum ColumnType {

        COL_SYSCODE, COL_ID, COL_STRING, COL_NUMBER
    }

    public ColumnType getColumnType(int col) {
        if (col == idColumn)
            return ColumnType.COL_ID;
        if (isSyscodeFixed ? false : col == syscodeColumn)
            return ColumnType.COL_SYSCODE;
        return isStringCol(col) ? ColumnType.COL_STRING : ColumnType.COL_NUMBER;
    }

    /**
     * Boolean which can be set to false if there is no column for the system code is available
     * in the dataset.
     */
    private boolean isSyscodeFixed = false;

    /**
     * String containing the system code that has been set by the user in gexImportWizard
     * (if no system code column is available).
     */
    DataSource ds = null;

    /**
     * Delimiter used to seperate columns in the text file containing expression data
     */
    private String delimiter = "\t";

    /**
     * Column numbers (first column is 0) of the columns of which the data should not be treated
     * as numberic
     */
    private Set<Integer> stringCols = new HashSet<Integer>();

    /**
     * Set if the given column is of type String or not
     */
    public void setStringColumn(int col, boolean value) {
        if (value)
            stringCols.add(col);
        else
            stringCols.remove(col);
    }

    /**
     * Checks if the column for the given column index is marked as 'string column' and
     * should not be treated as numeric
     * @param colIndex	the index of the column to check (start with 0)
     * @return true if the column is marked as 'string column', false if not
     */
    public boolean isStringCol(int colIndex) {
        return stringCols.contains(colIndex);
    }

    /**
     * Creates an excel "Column name" for a given 0-based column index.
     * 0 -> A, 25-> Z
     * 26 -> AA
     * 26 + 26^2 -> AAA
     * etc.
     */
    static String colIndexToExcel(int i) {
        replacedert (i >= 0);
        String result = "";
        while (i >= 0) {
            result = (char) ('A' + i % 26) + result;
            i /= 26;
            i--;
        }
        return result;
    }

    /**
     * Reads the column names from the text file containing the expression data at the
     * header row specified by the user. Multiple header rows can also be read. When no header
     * row is present, a header row is created manually.
     *
     * The column names are guaranteed to be unique, non-empty, and
     * there will be at least as many columns as sampleMaxNumCols.
     *
     * @return the column names
     */
    public String[] getColNames() {
        String[] result = null;
        result = new String[sampleMaxNumCols];
        // initialize columns to empty strings
        for (int i = 0; i < sampleMaxNumCols; i++) result[i] = "";
        // concatenate header rows
        if (!getNoHeader()) {
            int i = 0;
            // Read headerlines till the first data row
            boolean first = true;
            while (i < firstDataRow) {
                for (int j = 0; j < cells[i].length; j++) {
                    // All header rows are added
                    if (i >= headerRow) {
                        if (!first)
                            result[j] += " ";
                        result[j] = result[j] += cells[i][j].trim();
                    }
                }
                first = false;
                i++;
            }
        }
        // check that column names are unique
        Set<String> unique = new HashSet<String>();
        // set remaining emtpy column names to default string
        for (int j = 0; j < result.length; ++j) {
            String col = result[j];
            if (col.equals("") || unique.contains(col)) {
                // generate default column name
                result[j] = "Column " + colIndexToExcel(j);
            }
            unique.add(result[j]);
        }
        return result;
    }

    /**
     * indicates whether a header is present or not
     * @return value of noHeader (true or false)
     */
    public boolean getNoHeader() {
        return firstDataRow - firstHeaderRow <= 0;
    }

    /**
     * Returns the boolean value set by the user which indicates whether
     * the system code is fixed, or specified in another column
     */
    public boolean isSyscodeFixed() {
        return isSyscodeFixed;
    }

    /**
     * Sets the boolean value to determine if the system code
     * is fixed, or specified in separate column
     */
    public void setSyscodeFixed(boolean target) {
        isSyscodeFixed = target;
    }

    /**
     * Sets the data source to use for all imported identifiers.
     * Only meaningful if getSyscodeColumn returns false.
     */
    public void setDataSource(DataSource value) {
        ds = value;
    }

    /**
     * Gets the data source to use for all imported identifiers.
     * Only meaningful if getSyscodeColumn retunrs false.
     */
    public DataSource getDataSource() {
        return ds;
    }

    /**
     * Returns the string that is used as the delimiter for reading the input data.
     *  This string is used to separate columns in the input data.
     *  The returned string can be any length, but during normal use it is typically 1 or 2 characters
     *  long.
     */
    public String getDelimiter() {
        return delimiter;
    }

    /**
     * Set the delimiter string. This string is used to separate columns in the input data.
     * The delimiter string can be set to any length, but during normal use it is typically
     * 1 or 2 characters long
     */
    public void setDelimiter(String target) {
        delimiter = target;
        interpretSample();
    }

    private static final int NUM_SAMPLE_LINES = 50;

    private List<String> lines = null;

    private String[][] cells = null;

    private int sampleMaxNumCols = 0;

    public int getSampleMaxNumCols() {
        return sampleMaxNumCols;
    }

    public int getSampleNumRows() {
        return lines == null ? 0 : lines.size();
    }

    public String getSampleData(int row, int col) {
        if (cells != null && cells[row] != null && cells[row].length > col) {
            return cells[row][col];
        } else {
            return "";
        }
    }

    private boolean digitIsDot = true;

    public boolean digitIsDot() {
        return digitIsDot;
    }

    public void setDigitIsDot(boolean value) {
        digitIsDot = value;
    }

    /**
     * derive datasource from sample data
     */
    public void guessSettings() {
        isSyscodeFixed = !guessHreplacedyscodeColumn;
        if (guessDataSource != null)
            setDataSource(guessDataSource);
        if (guessHreplacedyscodeColumn && guessSyscodeColumn >= 0) {
            setSysodeColumn(guessSyscodeColumn);
        }
        if (guessIdColumn >= 0)
            setIdColumn(guessIdColumn);
        digitIsDot = guessDigitIsDot;
        Logger.log.info("Guessing sysCode: " + guessHreplacedyscodeColumn + " " + guessSyscodeColumn + " id: " + guessIdColumn + " " + guessDataSource + " digitIsDot? " + guessDigitIsDot);
    }

    private boolean guessHreplacedyscodeColumn = true;

    private int guessSyscodeColumn = -1;

    private int guessIdColumn = -1;

    private boolean guessDigitIsDot;

    private DataSource guessDataSource = null;

    /**
     * Helper clreplaced to keep track of how often patterns occur, and in which column
     */
    private static clreplaced PatternCounter {

        private final Pattern p;

        private Map<Integer, Integer> counts = new HashMap<Integer, Integer>();

        private int total = 0;

        PatternCounter(Pattern p) {
            this.p = p;
        }

        void countCell(String cell, int column) {
            Matcher m = p.matcher(cell);
            // check if it matches
            if (m.matches()) {
                // increase total and per-column counts
                int prev = counts.containsKey(column) ? counts.get(column) : 0;
                counts.put(column, ++prev);
                total++;
            }
        }

        int getTotal() {
            return total;
        }

        int getColumnCount(int col) {
            return (counts.containsKey(col) ? counts.get(col) : 0);
        }
    }

    /**
     * fraction of cells that have to match a pattern for it to be a good guess
     */
    private static final double GOOD_GUESS_FRACTION = 0.9;

    /*
	 * read a sample from the selected text file
	 */
    private void readSample() throws IOException {
        BufferedReader in = new BufferedReader(new FileReader(txtFile));
        lines = new ArrayList<String>();
        String line;
        while ((line = in.readLine()) != null && lines.size() < NUM_SAMPLE_LINES) {
            lines.add(line);
        }
        in.close();
    }

    /* guess some parameters */
    private void interpretSample() {
        // "Guess" the system code based on the first 50 lines.
        // Make regular expressions patterns for the gene ID's.
        Map<DataSource, Pattern> patterns = DataSourcePatterns.getPatterns();
        // Make regular expressions pattern for the system code.
        final PatternCounter syscodeCounter = new PatternCounter(Pattern.compile("[A-Z][a-z]?"));
        final PatternCounter dotCounter = new PatternCounter(Pattern.compile("-?[0-9]*\\.[0-9]+"));
        final PatternCounter commaCounter = new PatternCounter(Pattern.compile("-?[0-9]*,[0-9]+"));
        // Make count variables.
        Map<DataSource, PatternCounter> counters = new HashMap<DataSource, PatternCounter>();
        for (DataSource ds : patterns.keySet()) {
            counters.put(ds, new PatternCounter(patterns.get(ds)));
        }
        sampleMaxNumCols = 0;
        int row = 0;
        cells = new String[NUM_SAMPLE_LINES][];
        for (String line : lines) {
            cells[row] = line.split(delimiter);
            int numCols = cells[row].length;
            if (numCols > sampleMaxNumCols) {
                sampleMaxNumCols = numCols;
            }
            for (int col = 0; col < cells[row].length; ++col) {
                // Count all the times that an element matches a gene identifier.
                syscodeCounter.countCell(cells[row][col], col);
                commaCounter.countCell(cells[row][col], col);
                dotCounter.countCell(cells[row][col], col);
                for (DataSource ds : patterns.keySet()) {
                    counters.get(ds).countCell(cells[row][col], col);
                }
            }
            row++;
        }
        /*Calculate percentage of rows where a system code is found and
		 * compare with a given percentage*/
        {
            double max = 0;
            int maxCol = -1;
            for (int col = 0; col < sampleMaxNumCols; ++col) {
                double syscodepercentage = (double) syscodeCounter.getColumnCount(col) / (double) row;
                if (syscodepercentage > max) {
                    max = syscodepercentage;
                    maxCol = col;
                }
            }
            /*Set the selection to the codeRadio button if a system code is found
			 * in more than rows than the given percentage, otherwise set the
			 * selection to the syscodeRadio button*/
            if (max >= GOOD_GUESS_FRACTION) {
                guessHreplacedyscodeColumn = true;
                guessSyscodeColumn = maxCol;
            } else {
                guessHreplacedyscodeColumn = false;
                guessSyscodeColumn = -1;
            }
        }
        double commaTotal = commaCounter.getTotal();
        double dotTotal = dotCounter.getTotal();
        // if more than 90% of number-like patterns use a dot, then the digit symbol is a dot.
        guessDigitIsDot = ((dotTotal / (commaTotal + dotTotal)) > GOOD_GUESS_FRACTION);
        // Update digitIsDot in case of csv file and dot digit.
        digitIsDot = guessDigitIsDot;
        Logger.log.info("readsample - I read " + dotTotal + " dots and " + commaTotal + " comma's. I'm guessing " + (guessDigitIsDot ? "dot" : "comma"));
        // Look for maximum.
        double max = 0;
        double second = 0;
        DataSource maxds = null;
        int maxCol = -1;
        for (int col = 0; col < sampleMaxNumCols; ++col) {
            for (DataSource ds : patterns.keySet()) {
                // Determine the maximum of the percentages (most hits).
                // Sometimes, normal data can match a gene identifier, in which case percentages[i]>1.
                // Ignores these gene identifiers.
                double percentage = (double) counters.get(ds).getColumnCount(col) / (double) row;
                if (percentage > max && percentage <= 1) {
                    // remember the second highest percentage too
                    second = max;
                    max = percentage;
                    maxds = ds;
                    maxCol = col;
                }
            }
        }
        // Select the right entry in the drop down menu and change the system code in importInformation
        guessDataSource = maxds;
        // only set guessIdColumn if the guess is a clear outlier,
        // if it's hardly above noise, just set it to 0.
        if (max > 2 * second)
            guessIdColumn = maxCol;
        else
            guessIdColumn = 0;
    }

    int dataRowsImported = 0;

    int rowsMapped = 0;

    public int getDataRowsImported() {
        return dataRowsImported;
    }

    public int getRowsMapped() {
        return rowsMapped;
    }
}

17 View Complete Implementation : DataSourceModel.java
Copyright Apache License 2.0
Author : PathVisio
/**
 * Stick this into a ComboBox to let the user
 * select a {@link DataSource}.
 *
 * By default this is based on all registered {@link DataSource}'s,
 * but optionally the model can be filtered to show only primary
 * data sources, only metabolites or only a certain organism.
 *
 * NB: if you want to use a JComboBox with a filtered list
 * (to narrow down the number of choices for the user)
 * but you still want to allow
 * programmatic selection of any DataSource, you need to
 * either make the {@link JComboBox} editable, or use a
 * {@link PermissiveComboBox}. An ordinary non-editable JComboBox
 * does not allow setting an item that is not in it's listModel.
 */
public clreplaced DataSourceModel implements ComboBoxModel {

    List<ListDataListener> listeners = new ArrayList<ListDataListener>();

    private List<DataSource> items = new ArrayList<DataSource>();

    DataSource selectedItem;

    public Object getSelectedItem() {
        return selectedItem;
    }

    /**
     * same as getSelectedItem, but type safe.
     */
    public DataSource getSelectedDataSource() {
        return selectedItem;
    }

    private void fireEvent(ListDataEvent e) {
        // fire change event
        for (ListDataListener listener : listeners) {
            listener.contentsChanged(e);
        }
    }

    /**
     * @param value may be null, but should be of type DataSource, otherwise you get a ClreplacedCastException
     */
    public void setSelectedItem(Object value) {
        selectedItem = (DataSource) value;
        fireEvent(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, 0));
    }

    public void addListDataListener(ListDataListener arg0) {
        listeners.add(arg0);
    }

    public Object getElementAt(int arg0) {
        return items.get(arg0);
    }

    public int getSize() {
        return items.size();
    }

    public void removeListDataListener(ListDataListener arg0) {
        listeners.remove(arg0);
    }

    public DataSourceModel() {
        super();
        inireplacedems();
    }

    /**
     * refresh combobox in response to e.g. changes in the list
     * of available data sources
     */
    private void inireplacedems() {
        items = new ArrayList<DataSource>();
        items.addAll(DataSourceHandler.getFilteredSetAlt(primary, type, organism, interaction));
        items.remove(DataSource.getExistingBySystemCode("EnBs"));
        items.remove(DataSource.getExistingBySystemCode("EnCe"));
        items.remove(DataSource.getExistingBySystemCode("EnGg"));
        items.remove(DataSource.getExistingBySystemCode("EnPt"));
        items.remove(DataSource.getExistingBySystemCode("EnBt"));
        items.remove(DataSource.getExistingBySystemCode("EnCf"));
        items.remove(DataSource.getExistingBySystemCode("EnEc"));
        items.remove(DataSource.getExistingBySystemCode("EnDm"));
        items.remove(DataSource.getExistingBySystemCode("EnQc"));
        items.remove(DataSource.getExistingBySystemCode("EnHs"));
        items.remove(DataSource.getExistingBySystemCode("EnMx"));
        items.remove(DataSource.getExistingBySystemCode("EnAg"));
        items.remove(DataSource.getExistingBySystemCode("EnMm"));
        items.remove(DataSource.getExistingBySystemCode("EnSs"));
        items.remove(DataSource.getExistingBySystemCode("EP"));
        items.remove(DataSource.getExistingBySystemCode("EnRn"));
        items.remove(DataSource.getExistingBySystemCode("EnXt"));
        items.remove(DataSource.getExistingBySystemCode("EnSc"));
        items.remove(DataSource.getExistingBySystemCode("EnDr"));
        Collections.sort(items, new Comparator<DataSource>() {

            public int compare(DataSource arg0, DataSource arg1) {
                String f0 = arg0.getFullName();
                String f1 = arg1.getFullName();
                if (f0 != null) {
                    return f1 == null ? -1 : f0.compareTo(f1);
                } else {
                    return f1 == null ? 0 : 1;
                }
            }
        });
        ListDataEvent e = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, items.size());
        fireEvent(e);
    }

    private Organism organism = null;

    private String[] type = null;

    private Boolean primary = null;

    private Boolean interaction = false;

    public void setSpeciesFilter(Organism aOrganism) {
        organism = aOrganism;
        inireplacedems();
    }

    public void setMetaboliteFilter(Boolean aMetabolite) {
        type = new String[] { "metabolite" };
        inireplacedems();
    }

    public void setPrimaryFilter(Boolean aPrimary) {
        primary = aPrimary;
        inireplacedems();
    }

    public void setInteractionFilter(Boolean aInteraction) {
        interaction = aInteraction;
        inireplacedems();
    }

    public void setTypeFilter(String[] aType) {
        type = aType;
        inireplacedems();
    }
}

16 View Complete Implementation : Utils.java
Copyright Apache License 2.0
Author : bridgedb
public static Set<Xref> translateDs(Set<Xref> in, DataSource base) {
    Set<Xref> result = new HashSet<Xref>();
    for (Xref ref : in) {
        result.add(translateDs(ref, base));
    }
    return result;
}