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;
009import java.util.Set;
010
011/**
012 * This class provides a mapping between HGNC IDs and approved gene symbols.
013 *
014 * @author Ozgun Babur
015 */
016public class HGNC
017{
018        private static Map<String, String> sym2id;
019        private static Map<String, String> id2sym;
020
021        public static void main(String[] args)
022        {
023                System.out.println(getID("BAX"));
024        }
025
026        /**
027         * Provides HGNC ID of the given approved gene symbol.
028         * @param symbol HGNC Symbol (aka gene name/symbol)
029         * @return HGNC ID
030         */
031        public static String getID(String symbol)
032        {
033                return sym2id.get(symbol);
034        }
035
036        public static String getSymbol(String hgncID)
037        {
038                return id2sym.get(hgncID);
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        public static Set<String> getSymbols()
052        {
053                return sym2id.keySet();
054        }
055
056        static
057        {
058                try
059                {
060                        sym2id = new HashMap<String, String>();
061                        BufferedReader reader = new BufferedReader(new InputStreamReader(
062                                HGNC.class.getResourceAsStream("HGNC.txt")));
063                        for (String line = reader.readLine(); line != null; line = reader.readLine())
064                        {
065                                String[] token = line.split("\t");
066                                String sym = token[1];
067                                String id = token[0];
068                                sym2id.put(sym, id);
069                        }
070                        reader.close();
071
072                        id2sym = new HashMap<String, String>();
073                        for (String key : sym2id.keySet())
074                        {
075                                id2sym.put(sym2id.get(key), key);
076                        }
077
078                }
079                catch (FileNotFoundException e)
080                {
081                        e.printStackTrace();
082                }
083                catch (IOException e)
084                {
085                        e.printStackTrace();
086                }
087        }
088}