| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | package org.pathvisio.plugins.statistics; |
|---|
| 18 | |
|---|
| 19 | import java.io.File; |
|---|
| 20 | import java.io.FileNotFoundException; |
|---|
| 21 | import java.io.FileOutputStream; |
|---|
| 22 | import java.io.PrintStream; |
|---|
| 23 | import java.util.ArrayList; |
|---|
| 24 | import java.util.HashMap; |
|---|
| 25 | import java.util.List; |
|---|
| 26 | import java.util.Map; |
|---|
| 27 | import java.util.regex.Matcher; |
|---|
| 28 | import java.util.regex.Pattern; |
|---|
| 29 | |
|---|
| 30 | import org.bridgedb.IDMapperException; |
|---|
| 31 | import org.bridgedb.Xref; |
|---|
| 32 | import org.bridgedb.rdb.DataDerby; |
|---|
| 33 | import org.bridgedb.rdb.SimpleGdb; |
|---|
| 34 | import org.bridgedb.rdb.SimpleGdbFactory; |
|---|
| 35 | import org.pathvisio.data.XrefWithSymbol; |
|---|
| 36 | import org.pathvisio.debug.Logger; |
|---|
| 37 | import org.pathvisio.gex.GexManager; |
|---|
| 38 | import org.pathvisio.gex.ReporterData; |
|---|
| 39 | import org.pathvisio.gex.SimpleGex; |
|---|
| 40 | import org.pathvisio.preferences.PreferenceManager; |
|---|
| 41 | import org.pathvisio.util.FileUtils; |
|---|
| 42 | import org.pathvisio.util.PathwayParser; |
|---|
| 43 | import org.pathvisio.util.PathwayParser.ParseException; |
|---|
| 44 | import org.pathvisio.util.Utils; |
|---|
| 45 | import org.xml.sax.SAXException; |
|---|
| 46 | import org.xml.sax.XMLReader; |
|---|
| 47 | import org.xml.sax.helpers.XMLReaderFactory; |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | public class IsDataInPathways |
|---|
| 56 | { |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | static File fGex = new File ("/media/KINGSTON/muscle_t12_vs_t0_PathVisio.pgex"); |
|---|
| 63 | static File fGdb = new File ("/home/martijn/PathVisio-Data/gene databases/Mm_Derby_20080102.pgdb"); |
|---|
| 64 | static File pwDir = new File ("/home/martijn/wikipathways/Mus_musculus"); |
|---|
| 65 | |
|---|
| 66 | static File outFile = new File ("/home/martijn/Desktop/isdatainpahtways.txt"); |
|---|
| 67 | |
|---|
| 68 | public static void main(String[] args) throws IDMapperException, ParseException, FileNotFoundException |
|---|
| 69 | { |
|---|
| 70 | PreferenceManager.init(); |
|---|
| 71 | GexManager gexManager = new GexManager(); |
|---|
| 72 | gexManager.setCurrentGex("" + fGex, false); |
|---|
| 73 | |
|---|
| 74 | XMLReader xmlReader; |
|---|
| 75 | |
|---|
| 76 | try |
|---|
| 77 | { |
|---|
| 78 | xmlReader = XMLReaderFactory.createXMLReader(); |
|---|
| 79 | } |
|---|
| 80 | catch (SAXException e) |
|---|
| 81 | { |
|---|
| 82 | Logger.log.error("Problem while searching pathways", e); |
|---|
| 83 | return; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | SimpleGex gex = gexManager.getCurrentGex(); |
|---|
| 88 | |
|---|
| 89 | Map<Xref, Xref> dataRefs = new HashMap<Xref, Xref>(); |
|---|
| 90 | Map<Xref, List<String>> counts = new HashMap<Xref, List<String>>(); |
|---|
| 91 | |
|---|
| 92 | SimpleGdb gdb = SimpleGdbFactory.createInstance("" + fGdb, new DataDerby(), 0); |
|---|
| 93 | |
|---|
| 94 | for (int i = 0; i < gex.getNrRow(); ++i) |
|---|
| 95 | { |
|---|
| 96 | ReporterData data = gex.getRow(i); |
|---|
| 97 | Xref src = data.getXref(); |
|---|
| 98 | counts.put (src, new ArrayList<String>()); |
|---|
| 99 | for (Xref dest : gdb.mapID(data.getXref())) |
|---|
| 100 | { |
|---|
| 101 | dataRefs.put (dest, src); |
|---|
| 102 | } |
|---|
| 103 | dataRefs.put (src, src); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | for (File f : FileUtils.getFiles(pwDir, "gpml", false)) |
|---|
| 107 | { |
|---|
| 108 | PathwayParser pp = new PathwayParser (f, xmlReader); |
|---|
| 109 | |
|---|
| 110 | for (XrefWithSymbol ref : pp.getGenes()) |
|---|
| 111 | { |
|---|
| 112 | Xref ref2 = new Xref (ref.getId(), ref.getDataSource()); |
|---|
| 113 | if (dataRefs.containsKey(ref2)) |
|---|
| 114 | { |
|---|
| 115 | counts.get(dataRefs.get(ref2)).add(pp.getName()); |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | PrintStream out = new PrintStream(new FileOutputStream(outFile)); |
|---|
| 121 | for (int i = 0; i < gex.getNrRow(); ++i) |
|---|
| 122 | { |
|---|
| 123 | ReporterData data = gex.getRow(i); |
|---|
| 124 | Xref ref = data.getXref(); |
|---|
| 125 | String bpText = Utils.oneOf (gdb.getAttributes(ref, "Backpage")); |
|---|
| 126 | String desc = ""; |
|---|
| 127 | if (bpText != null) |
|---|
| 128 | { |
|---|
| 129 | Pattern pat = Pattern.compile("<TH>Description:<TH>(.*)<TR>"); |
|---|
| 130 | Matcher mat = pat.matcher (bpText); |
|---|
| 131 | if (mat.find()) |
|---|
| 132 | { |
|---|
| 133 | desc = mat.group(1); |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | List<String> pwyNames = counts.get(ref); |
|---|
| 137 | out.print (i + "\t" + |
|---|
| 138 | ref.getId() + "\t" + |
|---|
| 139 | ref.getDataSource().getSystemCode() + "\t" + |
|---|
| 140 | desc + "\t" + |
|---|
| 141 | pwyNames.size() + "\t"); |
|---|
| 142 | |
|---|
| 143 | boolean first = true; |
|---|
| 144 | for (String name : pwyNames) |
|---|
| 145 | { |
|---|
| 146 | if (!first) |
|---|
| 147 | { |
|---|
| 148 | out.print (" \\\\\\ "); |
|---|
| 149 | } |
|---|
| 150 | first = false; |
|---|
| 151 | out.print (name); |
|---|
| 152 | } |
|---|
| 153 | out.println(); |
|---|
| 154 | } |
|---|
| 155 | out.close(); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | } |
|---|