@Test public void testAppend () throws IOException { List<PairedHit> orighits = new ArrayList<PairedHit>(); List<PairedHit> newhits = new ArrayList<PairedHit>(); int len = 1000; for (int i = 0; i < len; i++) { orighits.add(new PairedHit(isLeft ? chrom : (int)(Math.random() * 1000), (int)(Math.random() * 100000000), i % 3 == 1, (short)(Math.random()*100+1), isLeft ? (int)(Math.random() * 1000) : chrom, (int)(Math.random() * 100000000), i % 3 == 1, (short)(Math.random()*100+1), (float)Math.random())); } for (int i = 0; i < len; i++) { newhits.add(new PairedHit(isLeft ? chrom : (int)(Math.random() * 1000), (int)(Math.random() * 100000000), i % 3 == 1, (short)(Math.random()*100+1), isLeft ? (int)(Math.random() * 1000) : chrom, (int)(Math.random() * 100000000), i % 3 == 1, (short)(Math.random()*100+1), (float)Math.random())); } Collections.sort(orighits, isLeft ? new PairedHitLeftComparator() : new PairedHitRightComparator()); Collections.sort(newhits, isLeft ? new PairedHitLeftComparator() : new PairedHitRightComparator()); PairedHits.writePairedHits(orighits, prefix, chrom, isLeft); hitsfile = new PairedHits(prefix,chrom,isLeft); hitsfile.appendPairedHits(newhits,prefix + "appended", chrom, isLeft); hitsfile = new PairedHits(prefix + "appended",chrom,isLeft); assertEquals(hitsfile.isLeft(), isLeft); ArrayList<PairedHit> allhits = new ArrayList<PairedHit>(); allhits.addAll(orighits); allhits.addAll(newhits); Collections.sort(allhits, isLeft ? new PairedHitLeftComparator() : new PairedHitRightComparator()); IntBP positions = hitsfile.getPositionsBuffer(); IntBP las = hitsfile.getLASBuffer(); FloatBP weights = hitsfile.getWeightsBuffer(); IntBP otherchrom = hitsfile.getChromsBuffer(); IntBP otherpos = hitsfile.getOtherPosBuffer(); for (int i = 0; i < allhits.size(); i++) { assertEquals(String.format("Hit %d, %s",i,allhits.get(i)), allhits.get(i).leftChrom, isLeft ? chrom : otherchrom.get(i)); assertEquals(String.format("Hit %d, %s",i,allhits.get(i)), allhits.get(i).leftPos, isLeft ? positions.get(i) : otherpos.get(i)); assertEquals(String.format("Hit %d, %s",i,allhits.get(i)), allhits.get(i).leftStrand, isLeft ? Hits.getStrandOne(las.get(i)) : Hits.getStrandTwo(las.get(i))); assertEquals(String.format("Hit %d, %s",i,allhits.get(i)), allhits.get(i).leftLength, isLeft ? Hits.getLengthOne(las.get(i)) : Hits.getLengthTwo(las.get(i))); assertEquals(String.format("Hit %d, %s",i,allhits.get(i)), allhits.get(i).rightChrom, !isLeft ? chrom : otherchrom.get(i)); assertEquals(String.format("Hit %d, %s",i,allhits.get(i)), allhits.get(i).rightPos, !isLeft ? positions.get(i) : otherpos.get(i)); assertEquals(String.format("Hit %d, %s",i,allhits.get(i)), allhits.get(i).rightStrand, !isLeft ? Hits.getStrandOne(las.get(i)) : Hits.getStrandTwo(las.get(i))); assertEquals(String.format("Hit %d, %s",i,allhits.get(i)), allhits.get(i).rightLength, !isLeft ? Hits.getLengthOne(las.get(i)) : Hits.getLengthTwo(las.get(i))); assertTrue(String.format("Hit %d, %s",i,allhits.get(i)), Math.abs(allhits.get(i).weight - weights.get(i)) < .00001); } }
private void append(List<PairedHit> hits, String prefix, int chrom, boolean isLeft) throws IOException { RandomAccessFile positionsRAF = new RandomAccessFile(getPositionsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile weightsRAF = new RandomAccessFile(getWeightsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile lasRAF = new RandomAccessFile(getLaSFname(prefix,chrom,isLeft),"rw"); RandomAccessFile chromsRAF = new RandomAccessFile(getChromsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile otherposRAF = new RandomAccessFile(getOtherPosFname(prefix,chrom,isLeft),"rw"); positionsRAF.seek(positionsRAF.length()); weightsRAF.seek(weightsRAF.length()); lasRAF.seek(lasRAF.length()); chromsRAF.seek(chromsRAF.length()); otherposRAF.seek(otherposRAF.length()); if (isLeft) { for (int i = 0; i < hits.size(); i++) { PairedHit h = hits.get(i); positionsRAF.writeInt(h.leftPos); weightsRAF.writeFloat(h.weight); lasRAF.writeInt(makeLAS(h.leftLength, h.leftStrand, h.rightLength, h.rightStrand)); chromsRAF.writeInt(h.rightChrom); otherposRAF.writeInt(h.rightPos); } } else { for (int i = 0; i < hits.size(); i++) { PairedHit h = hits.get(i); positionsRAF.writeInt(h.leftPos); weightsRAF.writeFloat(h.weight); lasRAF.writeInt(makeLAS(h.leftLength, h.leftStrand, h.rightLength, h.rightStrand)); chromsRAF.writeInt(h.rightChrom); otherposRAF.writeInt(h.rightPos); } } positionsRAF.close(); weightsRAF.close(); lasRAF.close(); chromsRAF.close(); otherposRAF.close(); }
PairedHits extends Hits { private void append(List<PairedHit> hits, String prefix, int chrom, boolean isLeft) throws IOException { RandomAccessFile positionsRAF = new RandomAccessFile(getPositionsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile weightsRAF = new RandomAccessFile(getWeightsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile lasRAF = new RandomAccessFile(getLaSFname(prefix,chrom,isLeft),"rw"); RandomAccessFile chromsRAF = new RandomAccessFile(getChromsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile otherposRAF = new RandomAccessFile(getOtherPosFname(prefix,chrom,isLeft),"rw"); positionsRAF.seek(positionsRAF.length()); weightsRAF.seek(weightsRAF.length()); lasRAF.seek(lasRAF.length()); chromsRAF.seek(chromsRAF.length()); otherposRAF.seek(otherposRAF.length()); if (isLeft) { for (int i = 0; i < hits.size(); i++) { PairedHit h = hits.get(i); positionsRAF.writeInt(h.leftPos); weightsRAF.writeFloat(h.weight); lasRAF.writeInt(makeLAS(h.leftLength, h.leftStrand, h.rightLength, h.rightStrand)); chromsRAF.writeInt(h.rightChrom); otherposRAF.writeInt(h.rightPos); } } else { for (int i = 0; i < hits.size(); i++) { PairedHit h = hits.get(i); positionsRAF.writeInt(h.leftPos); weightsRAF.writeFloat(h.weight); lasRAF.writeInt(makeLAS(h.leftLength, h.leftStrand, h.rightLength, h.rightStrand)); chromsRAF.writeInt(h.rightChrom); otherposRAF.writeInt(h.rightPos); } } positionsRAF.close(); weightsRAF.close(); lasRAF.close(); chromsRAF.close(); otherposRAF.close(); } }
PairedHits extends Hits { private void append(List<PairedHit> hits, String prefix, int chrom, boolean isLeft) throws IOException { RandomAccessFile positionsRAF = new RandomAccessFile(getPositionsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile weightsRAF = new RandomAccessFile(getWeightsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile lasRAF = new RandomAccessFile(getLaSFname(prefix,chrom,isLeft),"rw"); RandomAccessFile chromsRAF = new RandomAccessFile(getChromsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile otherposRAF = new RandomAccessFile(getOtherPosFname(prefix,chrom,isLeft),"rw"); positionsRAF.seek(positionsRAF.length()); weightsRAF.seek(weightsRAF.length()); lasRAF.seek(lasRAF.length()); chromsRAF.seek(chromsRAF.length()); otherposRAF.seek(otherposRAF.length()); if (isLeft) { for (int i = 0; i < hits.size(); i++) { PairedHit h = hits.get(i); positionsRAF.writeInt(h.leftPos); weightsRAF.writeFloat(h.weight); lasRAF.writeInt(makeLAS(h.leftLength, h.leftStrand, h.rightLength, h.rightStrand)); chromsRAF.writeInt(h.rightChrom); otherposRAF.writeInt(h.rightPos); } } else { for (int i = 0; i < hits.size(); i++) { PairedHit h = hits.get(i); positionsRAF.writeInt(h.leftPos); weightsRAF.writeFloat(h.weight); lasRAF.writeInt(makeLAS(h.leftLength, h.leftStrand, h.rightLength, h.rightStrand)); chromsRAF.writeInt(h.rightChrom); otherposRAF.writeInt(h.rightPos); } } positionsRAF.close(); weightsRAF.close(); lasRAF.close(); chromsRAF.close(); otherposRAF.close(); } PairedHits(String prefix, int chrom, boolean isLeft); }
PairedHits extends Hits { private void append(List<PairedHit> hits, String prefix, int chrom, boolean isLeft) throws IOException { RandomAccessFile positionsRAF = new RandomAccessFile(getPositionsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile weightsRAF = new RandomAccessFile(getWeightsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile lasRAF = new RandomAccessFile(getLaSFname(prefix,chrom,isLeft),"rw"); RandomAccessFile chromsRAF = new RandomAccessFile(getChromsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile otherposRAF = new RandomAccessFile(getOtherPosFname(prefix,chrom,isLeft),"rw"); positionsRAF.seek(positionsRAF.length()); weightsRAF.seek(weightsRAF.length()); lasRAF.seek(lasRAF.length()); chromsRAF.seek(chromsRAF.length()); otherposRAF.seek(otherposRAF.length()); if (isLeft) { for (int i = 0; i < hits.size(); i++) { PairedHit h = hits.get(i); positionsRAF.writeInt(h.leftPos); weightsRAF.writeFloat(h.weight); lasRAF.writeInt(makeLAS(h.leftLength, h.leftStrand, h.rightLength, h.rightStrand)); chromsRAF.writeInt(h.rightChrom); otherposRAF.writeInt(h.rightPos); } } else { for (int i = 0; i < hits.size(); i++) { PairedHit h = hits.get(i); positionsRAF.writeInt(h.leftPos); weightsRAF.writeFloat(h.weight); lasRAF.writeInt(makeLAS(h.leftLength, h.leftStrand, h.rightLength, h.rightStrand)); chromsRAF.writeInt(h.rightChrom); otherposRAF.writeInt(h.rightPos); } } positionsRAF.close(); weightsRAF.close(); lasRAF.close(); chromsRAF.close(); otherposRAF.close(); } PairedHits(String prefix, int chrom, boolean isLeft); boolean isLeft(); IntBP getChromsBuffer(); IntBP getOtherPosBuffer(); IntBP getOtherChromsBetween(int firstindex,
                                       int lastindex,
                                       int start,
                                       int stop,
                                       Float minweight,
                                       Boolean isPlus); IntBP getOtherPositionsBetween(int firstindex,
                                          int lastindex,
                                          int start,
                                          int stop,
                                          Float minweight,
                                          Boolean isPlus); static void writePairedHits(List<PairedHit> hits,
                                       String prefix, 
                                       int chrom,
                                       boolean isLeft); void appendPairedHits(List<PairedHit> hits,
                                 String prefix, 
                                 int chrom,
                                 boolean isLeft); }
PairedHits extends Hits { private void append(List<PairedHit> hits, String prefix, int chrom, boolean isLeft) throws IOException { RandomAccessFile positionsRAF = new RandomAccessFile(getPositionsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile weightsRAF = new RandomAccessFile(getWeightsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile lasRAF = new RandomAccessFile(getLaSFname(prefix,chrom,isLeft),"rw"); RandomAccessFile chromsRAF = new RandomAccessFile(getChromsFname(prefix,chrom,isLeft),"rw"); RandomAccessFile otherposRAF = new RandomAccessFile(getOtherPosFname(prefix,chrom,isLeft),"rw"); positionsRAF.seek(positionsRAF.length()); weightsRAF.seek(weightsRAF.length()); lasRAF.seek(lasRAF.length()); chromsRAF.seek(chromsRAF.length()); otherposRAF.seek(otherposRAF.length()); if (isLeft) { for (int i = 0; i < hits.size(); i++) { PairedHit h = hits.get(i); positionsRAF.writeInt(h.leftPos); weightsRAF.writeFloat(h.weight); lasRAF.writeInt(makeLAS(h.leftLength, h.leftStrand, h.rightLength, h.rightStrand)); chromsRAF.writeInt(h.rightChrom); otherposRAF.writeInt(h.rightPos); } } else { for (int i = 0; i < hits.size(); i++) { PairedHit h = hits.get(i); positionsRAF.writeInt(h.leftPos); weightsRAF.writeFloat(h.weight); lasRAF.writeInt(makeLAS(h.leftLength, h.leftStrand, h.rightLength, h.rightStrand)); chromsRAF.writeInt(h.rightChrom); otherposRAF.writeInt(h.rightPos); } } positionsRAF.close(); weightsRAF.close(); lasRAF.close(); chromsRAF.close(); otherposRAF.close(); } PairedHits(String prefix, int chrom, boolean isLeft); boolean isLeft(); IntBP getChromsBuffer(); IntBP getOtherPosBuffer(); IntBP getOtherChromsBetween(int firstindex,
                                       int lastindex,
                                       int start,
                                       int stop,
                                       Float minweight,
                                       Boolean isPlus); IntBP getOtherPositionsBetween(int firstindex,
                                          int lastindex,
                                          int start,
                                          int stop,
                                          Float minweight,
                                          Boolean isPlus); static void writePairedHits(List<PairedHit> hits,
                                       String prefix, 
                                       int chrom,
                                       boolean isLeft); void appendPairedHits(List<PairedHit> hits,
                                 String prefix, 
                                 int chrom,
                                 boolean isLeft);  }