Clover coverage report - baseCode - 0.2.5
Coverage timestamp: Tue Apr 12 2005 11:31:58 EDT
file stats: LOC: 182   Methods: 12
NCLOC: 89   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
GONames.java 0% 0% 0% 0%
coverage
 1   
 package baseCode.bio.geneset;
 2   
 
 3   
 import java.io.FileInputStream;
 4   
 import java.io.IOException;
 5   
 import java.io.InputStream;
 6   
 import java.util.HashSet;
 7   
 import java.util.Iterator;
 8   
 import java.util.Map;
 9   
 import java.util.Set;
 10   
 
 11   
 import org.xml.sax.SAXException;
 12   
 
 13   
 import baseCode.bio.GOEntry;
 14   
 import baseCode.dataStructure.graph.DirectedGraph;
 15   
 import baseCode.dataStructure.graph.DirectedGraphNode;
 16   
 import baseCode.xml.GOParser;
 17   
 
 18   
 /**
 19   
  * Rea data from GO XML file, store in easy-to-use data structure.
 20   
  * <p>
 21   
  * Copyright (c) 2004 Columbia University
 22   
  * 
 23   
  * @author Paul Pavlidis
 24   
  * @author Homin Lee
 25   
  * @version $Id: GONames.java,v 1.3 2004/12/28 22:07:27 pavlidis Exp $
 26   
  */
 27   
 public class GONames {
 28   
 
 29   
    private static Map goNameMap;
 30   
    private Set newGeneSets = new HashSet();
 31   
    private GOParser parser;
 32   
 
 33   
    /**
 34   
     * @param filename <code>String</code> The XML file containing class to name mappings. First column is the class
 35   
     *        id, second is a description that will be used int program output.
 36   
     * @throws IOException
 37   
     * @throws SAXException
 38   
     */
 39  0
    public GONames( String filename ) throws SAXException, IOException {
 40  0
       if ( filename == null || filename.length() == 0 ) {
 41  0
          throw new IllegalArgumentException(
 42   
                "Invalid filename " + filename + " or no filename was given" );
 43   
       }
 44   
 
 45  0
       InputStream i = new FileInputStream( filename );
 46  0
       parser = new GOParser( i );
 47  0
       goNameMap = parser.getGONameMap();
 48   
    }
 49   
 
 50   
    /**
 51   
     * @param inputStream
 52   
     * @throws IOException
 53   
     * @throws SAXException
 54   
     */
 55  0
    public GONames( InputStream inputStream ) throws IOException, SAXException {
 56  0
       if ( inputStream == null ) {
 57  0
          throw new IOException( "Input stream was null" );
 58   
       }
 59   
 
 60  0
       parser = new GOParser( inputStream );
 61  0
       goNameMap = parser.getGONameMap();
 62   
    }
 63   
 
 64   
    /**
 65   
     * Get the graph representation of the GO hierarchy. This can be used to support JTree representations.
 66   
     * 
 67   
     * @return
 68   
     */
 69  0
    public DirectedGraph getGraph() {
 70  0
       return parser.getGraph();
 71   
    }
 72   
 
 73   
    /**
 74   
     * @param id
 75   
     * @return a Set containing the ids of geneSets which are immediately below the selected one in the hierarchy.
 76   
     */
 77  0
    public Set getChildren( String id ) {
 78  0
       Set returnVal = new HashSet();
 79  0
       Set children = ( ( DirectedGraphNode ) getGraph().get( id ) )
 80   
             .getChildNodes();
 81  0
       for ( Iterator it = children.iterator(); it.hasNext(); ) {
 82  0
          DirectedGraphNode child = ( DirectedGraphNode ) it.next();
 83  0
          String childKey = ( ( GOEntry ) child.getItem() ).getId()
 84   
                .intern();
 85  0
          returnVal.add( childKey.intern() );
 86   
       }
 87  0
       return returnVal;
 88   
    }
 89   
 
 90   
    /**
 91   
     * @param id
 92   
     * @return a Set containing the ids of geneSets which are immediately above the selected one in the hierarchy.
 93   
     */
 94  0
    public Set getParents( String id ) {
 95  0
       Set returnVal = new HashSet();
 96  0
       Set parents = ( ( DirectedGraphNode ) getGraph().get( id ) )
 97   
             .getParentNodes();
 98  0
       for ( Iterator it = parents.iterator(); it.hasNext(); ) {
 99  0
          DirectedGraphNode parent = ( DirectedGraphNode ) it.next();
 100  0
          String parentKey = ( ( GOEntry ) parent.getItem() ).getId()
 101   
                .intern();
 102  0
          returnVal.add( parentKey.intern() );
 103   
       }
 104  0
       return returnVal;
 105   
    }
 106   
 
 107   
    /**
 108   
     * Get the Map representation of the GO id - name associations.
 109   
     * 
 110   
     * @return Map
 111   
     */
 112  0
    public Map getMap() {
 113  0
       return goNameMap;
 114   
    }
 115   
 
 116   
    /**
 117   
     * @param go_ID String
 118   
     * @return String
 119   
     */
 120  0
    public String getNameForId( String go_ID ) {
 121   
 
 122  0
       if ( !goNameMap.containsKey( go_ID ) ) {
 123  0
          return "<no description available>";
 124   
       }
 125   
 
 126  0
       return ( ( String ) ( goNameMap.get( go_ID ) ) ).intern();
 127   
    }
 128   
    
 129   
    
 130   
    /**
 131   
     * Get the aspect (molecular_function etc) for an id.
 132   
     * @param go_ID
 133   
     * @return
 134   
     */
 135  0
    public String getAspectForId( String go_ID ) {
 136  0
       if ( !goNameMap.containsKey( go_ID ) ) {
 137  0
          return "<no aspect available>";
 138   
       }
 139  0
       return ((GOEntry)getGraph().getNodeContents(go_ID)).getAspect();
 140   
    }
 141   
    
 142   
 
 143   
    /**
 144   
     * @param id String
 145   
     * @param name String
 146   
     * @todo this should modify the tree representation too.
 147   
     */
 148  0
    public void addClass( String id, String name ) {
 149  0
       goNameMap.put( id, name );
 150  0
       newGeneSets.add( id );
 151   
    }
 152   
 
 153   
    /**
 154   
     * @param id String
 155   
     * @param name String
 156   
     * @todo this should modify the tree representation too.
 157   
     */
 158  0
    public void modifyClass( String id, String name ) {
 159  0
       goNameMap.put( id, name );
 160  0
       newGeneSets.add( id );
 161   
    }
 162   
 
 163   
    /**
 164   
     * Check if a gene set is already defined.
 165   
     * 
 166   
     * @param id
 167   
     * @return
 168   
     */
 169  0
    public boolean newSet( String id ) {
 170  0
       return newGeneSets.contains( id );
 171   
    }
 172   
 
 173   
    /**
 174   
     * Return the Set of all new gene sets (ones which were added after loading the file)
 175   
     * 
 176   
     * @return
 177   
     */
 178  0
    public Set getNewGeneSets() {
 179  0
       return newGeneSets;
 180   
    }
 181   
 
 182   
 }