public void parseInputFile(File inputFile) throws IOException { geneFeatures.clear(); otherRecords.clear(); try { GFFEntrySet gffEntries = GFFTools.readGFF(inputFile); Iterator itr = gffEntries.lineIterator(); int count = 0; int intronFeatures = 0; LinkedList<GFFRecord> cdsRecs = new LinkedList<GFFRecord>(); while (itr.hasNext()) { Object val = itr.next(); if (val instanceof GFFRecord) { GFFRecord rec = (GFFRecord) val; count += 1; if (rec.getFeature().endsWith("gene")) { GeneFeatures gf = new GeneFeatures(rec); geneFeatures.put(gf.id, gf); } else if (rec.getFeature().equals("CDS")) { cdsRecs.addLast(rec); } else { otherRecords.add(rec); } } } for (GFFRecord rec : cdsRecs) { Map<String, List<String>> attrs = decodeAttrMap(rec); if (geneFeatures.containsKey(attrs.get("Parent").get(0))) { geneFeatures.get(attrs.get("Parent").get(0)).addCDS(rec, attrs); } else { System.err.println("Unknown CDS Parent: " + attrs.get("Parent").get(0)); } } for (String k : geneFeatures.keySet()) { GeneFeatures gf = geneFeatures.get(k); if (gf.cds != null && gf.cds.size() > 1) { intronFeatures++; } } System.err.println("# GFF Records: " + count); System.err.println("# Gene Feature Sets: " + geneFeatures.size()); System.err.println("\t# Intron-Features: " + intronFeatures); } catch (ParserException e) { e.printStackTrace(); } catch (BioException e) { e.printStackTrace(); } }
public Collection<Experiment> findExpts(CellLine cells, ExptCondition cond) throws SQLException { LinkedList<Integer> dbids = new LinkedList<Integer>(); String tables = "experiment e"; if (genome != null) { tables += ", probe_platform_to_genome p2g"; } String query = "select e.id from " + tables; Vector<String> conds = new Vector<String>(); if (genome != null) { int gid = genome.getDBID(); conds.add("e.platform=p2g.platform and p2g.genome=" + gid); } if (cells != null) { conds.add("e.cells=" + cells.getDBID()); } if (cond != null) { conds.add("e.condition=" + cond.getDBID()); } for (int i = 0; i < conds.size(); i++) { if (i == 0) { query += " where "; } else { query += " and "; } query += conds.get(i); } System.out.println("Final Query: \"" + query + "\""); java.sql.Connection cxn = loader.getConnection(); Statement s = cxn.createStatement(); ResultSet rs = s.executeQuery(query); while (rs.next()) { int dbid = rs.getInt(1); dbids.addLast(dbid); } rs.close(); s.close(); Collection<Experiment> expts = loader.loadExperiments(dbids); return expts; }
public void addCDS(GFFRecord rec, Map<String, List<String>> attrs) { if (!rec.getFeature().equals("CDS")) { throw new IllegalArgumentException(); } if (attrs == null) { attrs = decodeAttrMap(rec); } if (!attrs.containsKey("Parent")) { throw new IllegalArgumentException(); } if (!attrs.get("Parent").contains(id)) { throw new IllegalArgumentException(); } cds.addLast(rec); }
public static Pair<String, List<String>> decodeKeyValues(String str) { int index = str.indexOf("="); if (index == -1) { return null; } String k = str.substring(0, index); LinkedList<String> vlist = new LinkedList<String>(); try { String vstr = URLDecoder.decode(str.substring(index + 1, str.length()), "UTF-8"); String[] array = vstr.split(","); for (int i = 0; i < array.length; i++) { vlist.addLast(array[i]); } return new Pair<String, List<String>>(k, vlist); } catch (UnsupportedEncodingException e) { System.err.println("BAD STRING " + str); e.printStackTrace(); return null; } catch (Exception e) { System.err.println("BAD STRING " + str); return null; } }
static synchronized void pushConnectionBackToPool(ConnectionWrapper con) { boolean exist = m_usedUsedConnection.remove(con); if (exist) { m_notUsedConnection.addLast(con); } }