001package org.biopax.paxtools.io.sbgn.idmapping;
002
003import java.io.BufferedReader;
004import java.io.FileNotFoundException;
005import java.io.IOException;
006import java.io.InputStreamReader;
007import java.util.HashMap;
008import java.util.Map;
009
010/**
011 * This class provides a mapping Entrez Gene IDs and gene symbols.
012 *
013 * @author Ozgun Babur
014 */
015public class EntrezGene
016{
017        private static Map<String, String> sym2id;
018        private static Map<String, String> id2sym;
019
020        public static void main(String[] args)
021        {
022                System.out.println("getSymbol(\"367\") = " + getSymbol("367"));
023                System.out.println("getID(\"AR\") = " + getID("AR"));
024        }
025
026        /**
027         * Provides Entrez Gene ID of the given gene symbol.
028         * @param symbol gene symbol
029         * @return EG ID
030         */
031        public static String getID(String symbol)
032        {
033                return sym2id.get(symbol);
034        }
035
036        public static String getSymbol(String id)
037        {
038                return id2sym.get(id);
039        }
040
041        public static boolean containsID(String id)
042        {
043                return id2sym.containsKey(id);
044        }
045
046        public static boolean containsSymbol(String symbol)
047        {
048                return sym2id.containsKey(symbol);
049        }
050
051        static
052        {
053                try
054                {
055                        sym2id = new HashMap<String, String>();
056                        BufferedReader reader = new BufferedReader(new InputStreamReader(
057                                HGNC.class.getResourceAsStream("EntrezGene.txt")));
058                        for (String line = reader.readLine(); line != null; line = reader.readLine())
059                        {
060                                String[] token = line.split("\t");
061
062                                if (token.length < 2) continue;
063
064                                String sym = token[0];
065                                String id = token[1];
066                                if (sym.length() > 0 && id.length() > 0) sym2id.put(sym, id);
067                        }
068                        reader.close();
069
070                        id2sym = new HashMap<String, String>();
071                        for (String key : sym2id.keySet())
072                        {
073                                id2sym.put(sym2id.get(key), key);
074                        }
075
076                }
077                catch (FileNotFoundException e)
078                {
079                        e.printStackTrace();
080                }
081                catch (IOException e)
082                {
083                        e.printStackTrace();
084                }
085        }
086}