All Downloads are FREE. Search and download functionalities are using the official Maven repository.

umcg.genetica.io.gmt.GMTFile Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package umcg.genetica.io.gmt;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import umcg.genetica.io.text.TextFile;

/**
 *
 * @author harmjan
 *
 * $LastChangedDate: 2012-08-24 11:50:07 +0200 (Fri, 24 Aug 2012) $ 
 * $LastChangedRevision: 43 $
 */
public class GMTFile {

    List pathways = new ArrayList();
    Map> genesInPathways = new HashMap>();

    public GMTFile(String file) throws IOException {
        if (file == null) {
            throw new IllegalArgumentException("Error loading GMT file: no file specified.");
        } else {
            read(file);
        }
    }

    private void read(String gmtfile) throws IOException {
        System.out.println("Reading GMT file: " + gmtfile);
        TextFile tfpathway = new TextFile(gmtfile, TextFile.R);
        String[] pwelems;
        while ((pwelems = tfpathway.readLineElems(TextFile.tab)) != null) {
            if (pwelems.length > 2) {
                pathways.add(pwelems[0]);
//            System.out.println("Loading pathway: " + pwelems[0]);
                HashSet genes = new HashSet();
                for (int i = 2; i < pwelems.length; i++) {
                    genes.add(pwelems[i]);
                }
                genesInPathways.put(pwelems[0], genes);
            }

        }
        tfpathway.close();
        System.out.println(pathways.size() + " pathways loaded.");
    }

    public List getPathways() {
        return pathways;
    }

    public Set getGenesForPathway(String pathway) {
        return genesInPathways.get(pathway);
    }
    
    public Map> getPathwayToGenes() {
        return genesInPathways;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy