001package org.biopax.paxtools.pattern.util; 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 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 private static Map<String, String> old2new; 021 022 public static void main(String[] args) 023 { 024 System.out.println(getSymbol("PKCA")); 025 } 026 027 public static String getSymbol(String idOrSymbol) 028 { 029 if (id2sym.containsKey(idOrSymbol)) return id2sym.get(idOrSymbol); 030 else if (sym2id.containsKey(idOrSymbol)) return idOrSymbol; 031 else if (old2new.containsKey(idOrSymbol)) return old2new.get(idOrSymbol); 032 else if (!idOrSymbol.toUpperCase().equals(idOrSymbol)) 033 return getSymbol(idOrSymbol.toUpperCase()); 034 else return null; 035 } 036 037 static 038 { 039 try 040 { 041 sym2id = new HashMap<String, String>(); 042 id2sym = new HashMap<String, String>(); 043 old2new = new HashMap<String, String>(); 044 BufferedReader reader = new BufferedReader(new InputStreamReader( 045 HGNC.class.getResourceAsStream("hgnc.txt"))); 046 047 reader.readLine(); //skip header 048 for (String line = reader.readLine(); line != null; line = reader.readLine()) 049 { 050 String[] token = line.split("\t"); 051 String sym = token[1]; 052 String id = token[0]; 053 sym2id.put(sym, id); 054 id2sym.put(id, sym); 055 056 if (token.length > 2) 057 { 058 String olds = token[2]; 059 for (String old : olds.split(",")) 060 { 061 old = old.trim(); 062 old2new.put(old, sym); 063 } 064 } 065 } 066 reader.close(); 067 } 068 catch (FileNotFoundException e) 069 { 070 e.printStackTrace(); 071 } 072 catch (IOException e) 073 { 074 e.printStackTrace(); 075 } 076 } 077}