public double likelihood() { double c1 = 0.0; double c3 = -1.0 / (double) Math.sqrt(2.0 * variance); double sum = 0.0; double cpart = -0.5 * Math.log(Math.sqrt(2.0 * Math.PI * variance)); for (int i = 0; i < data.size(); i++) { for (int k = 0; k < channels.length; k++) { c1 += cpart; double pi = 0.0; for (Integer t : transcripts.keySet()) { if (transcripts.get(t).contains(i)) { double gammai = gammas[t][k]; double dit = delta(i, t); double pit = gammai * Math.exp(-lambda * dit); pi += pit; } } double zi = Math.log(pi); double err = data.values(i)[channels[k]] - zi; sum += (err * err); } } return c1 + c3 * sum; }
public double error() { double sum = 0.0; for (int i = 0; i < data.size(); i++) { for (int k = 0; k < channels.length; k++) { double pi = 0.0; for (Integer t : transcripts.keySet()) { if (transcripts.get(t).contains(i)) { double gammai = gammas[t][k]; double dit = delta(i, t); double pit = gammai * Math.exp(-lambda * dit); pi += pit; } } double zi = Math.log(pi); double err = Math.abs(data.values(i)[channels[k]] - zi); sum += err; } } return sum; }
public static ClusterData makeCd( final int lane, final int tile, final int xCoord, final int yCoord, final boolean pf, final byte[] bases, final byte[] qualities, final String matchedBarcode) { final ReadData rd = new ReadData(); rd.setBases(Arrays.copyOf(bases, bases.length)); rd.setQualities(Arrays.copyOf(qualities, bases.length)); rd.setReadType( ReadType.T); // This will be ignored, as the cluster will be chopped up by ReadStructure final ClusterData cd = new ClusterData(rd); cd.setLane(lane); cd.setTile(tile); cd.setX(xCoord); cd.setY(yCoord); cd.setPf(pf); cd.setMatchedBarcode(matchedBarcode); return cd; }
public DefaultGroupManager( String group, String cluster, Vertx vertx, ContextManager context, PlatformManager platform, ClusterListener listener, ClusterData data) { this.group = group; this.vertx = vertx; this.context = context; this.platform = platform; this.listener = listener; this.registry = vertx.sharedData().getSet(group); this.groups = data.getMultiMap(String.format("groups.%s", cluster)); this.deployments = data.getMultiMap(String.format("deployments.%s", cluster)); this.nodeSelectors = data.getMap(String.format("selectors.node.%s", group)); }
public ClusterLikelihoods( ClusterData d, Integer[] chs, int[] five, int[] three, double v, double l) { data = d; channels = chs.clone(); gammas = new double[five.length][channels.length]; for (int t = 0; t < gammas.length; t++) { for (int i = 0; i < gammas[t].length; i++) { gammas[t][i] = 1.0; } } transcripts = new TreeMap<Integer, Set<Integer>>(); fiveprime = five; threeprime = three; if (fiveprime.length != threeprime.length) { String msg = String.format("%d != %d", fiveprime.length, threeprime.length); throw new IllegalArgumentException(msg); } variance = v; lambda = l; for (int t = 0; t < fiveprime.length; t++) { transcripts.put(t, new TreeSet<Integer>()); } for (int i = 0; i < data.size(); i++) { int loc = data.location(i); for (int t = 0; t < fiveprime.length; t++) { if (fiveprime[t] <= loc && threeprime[t] >= loc) { transcripts.get(t).add(i); } } } }
public static ReadData[] copyReadData( final ReadStructure rs, final IlluminaDataType[] dts, final ClusterData toCopy) { boolean doBases = false; boolean doQuals = false; boolean doInts = false; boolean doNoise = false; for (final IlluminaDataType dt : dts) { switch (dt) { case BaseCalls: doBases = true; break; case QualityScores: doQuals = true; break; case RawIntensities: doInts = true; break; case Noise: doNoise = true; break; } } if (!doBases && !doQuals && !doInts && !doNoise) return null; final ReadData rdToCopy = toCopy.getRead(0); // Only gonna be one read in this final ReadData[] rds = new ReadData[rs.nonSkips.length()]; int index = 0; int baseIndex = 0; for (int i = 0; i < rs.descriptors.size(); i++) { final ReadDescriptor readDesc = rs.descriptors.get(i); if (readDesc.type != ReadType.S) { final ReadData curRead = new ReadData(readDesc.type); if (doBases) { final byte[] bases = Arrays.copyOfRange(rdToCopy.getBases(), baseIndex, baseIndex + readDesc.length); curRead.setBases(bases); } if (doQuals) { final byte[] quals = Arrays.copyOfRange(rdToCopy.getQualities(), baseIndex, baseIndex + readDesc.length); curRead.setQualities(quals); } if (doInts) { final FourChannelIntensityData fcid = copyIntensities(rdToCopy.getRawIntensities(), baseIndex, readDesc.length); curRead.setRawIntensities(fcid); } if (doNoise) { final FourChannelIntensityData fcid = copyIntensities(rdToCopy.getNoise(), baseIndex, readDesc.length); curRead.setNoise(fcid); } rds[index++] = curRead; } baseIndex += readDesc.length; } return rds; }
public static ClusterData selectiveCopyCd( final ClusterData toCopy, final String readStructure, final IlluminaDataType... dataTypes) { final ReadStructure rs = new ReadStructure(readStructure); final ReadData[] rd = copyReadData(rs, dataTypes, toCopy); final ClusterData cd = new ClusterData(rd); cd.setTile(toCopy.getTile()); cd.setLane(toCopy.getLane()); for (final IlluminaDataType idt : dataTypes) { switch (idt) { case Position: cd.setX(toCopy.getX()); cd.setY(toCopy.getY()); break; case PF: cd.setPf(toCopy.isPf()); break; case Barcodes: cd.setMatchedBarcode(toCopy.getMatchedBarcode()); break; default: break; } } return cd; }
public double delta(int i, int t) { int diff = threeprime[t] - data.location(i); return diff >= 0 ? (double) diff : 0.0; }