public static void doFor(File comparisonFile, String base) { System.out.println("profile ------------------------- " + comparisonFile); // Load similarities final Map<Tuple<File, File>, ColocCoefficients> comparison; comparison = CompareAll.loadCache(null, comparisonFile); // comparison=CompareAll.loadCache(datas, CompareAll.cachedValuesFileT); // Find out which files there are Set<File> datas = IntExpFileUtil.getAnnotated(); // new TreeSet<File>();//.getAnnotated(); /* for(Tuple<File,File> t:comparison.keySet()) IntExpFileUtil.getAnnotated() if(t.fst().exists()) datas.add(t.fst());*/ // Only keep those actually calculated Set<File> found = new TreeSet<File>(); for (Tuple<File, File> a : comparison.keySet()) found.add(a.fst()); datas.retainAll(found); System.out.println(datas); Map<File, String> nameMap = new HashMap<File, String>(); int countName = 0; StringBuffer sbSed = new StringBuffer(); for (File fa : datas) { // Similarity -> disimilarity, just a change of sign String tempName = ("n" + countName + "nnnnnnnnnn").substring(0, 10); nameMap.put(fa, tempName); countName++; String newName = IntExpFileUtil.getGeneName(fa) + " " + fa.getName(); sbSed.append(" | sed 's/" + tempName + "/" + newName + "/'"); } System.out.println("# recordings: " + datas.size()); HashSet<String> strainNames = new HashSet<String>(); for (File fa : datas) { String name = fa.getName(); name = name.substring(0, name.indexOf('_')); strainNames.add(name); } System.out.println("# strains: " + strainNames.size()); for (String type : new String[] {"l2", "pearson"}) { StringBuffer sb = new StringBuffer(); sb.append("" + datas.size() + "\n"); for (File fa : datas) { // Similarity -> disimilarity, just a change of sign String name = nameMap.get(fa); // (fa.getName()+" ").substring(0,10); sb.append(name); for (File fb : datas) { ColocCoefficients coef = comparison.get(Tuple.make(fa, fb)); if (coef == null) System.out.println("-----------------Null for " + fa + " " + fb); Double v = null; if (type.equals("pearson")) { v = 1.0 - Math.abs(coef.getPearson()); if (fa.equals(fb)) System.out.println("should be 0: " + v); // may need to force 0 if (v == null || Double.isInfinite(v) || Double.isNaN(v)) v = 0.0; } else if (type.equals("l2")) { v = coef.getL2(); if (v == null || Double.isInfinite(v) || Double.isNaN(v)) v = 0.5 * 0.5; // doubtful? but probably not further away if (fa.equals(fb)) v = 0.0; } sb.append(" " + v); } sb.append("\n"); } try { File basedir = new File(new File(CompareAll.outputBaseDir, "phylip"), base + "-" + type); basedir.mkdirs(); EvFileUtil.writeFile(new File(basedir, "infile"), sb.toString()); String fSed = "cat outfile" + sbSed + " > outfile2\n" + "cat outtree" + sbSed + " > outtree2\n"; EvFileUtil.writeFile(new File(basedir, "fix.sh"), fSed); } catch (IOException e) { e.printStackTrace(); } } }
public static EvStack apply(EvStack in, double sigmaX, double sigmaY, double sigmaZ) { int w = in.getWidth(); int h = in.getHeight(); int d = in.getDepth(); /* * System.out.println("incoming stack "+in); System.out.println("Generating kernel"); EvStack kernel=GenerateSpecialImage.genGaussian3D(sigmaX, sigmaY, sigmaZ, w, h, d); System.out.println(kernel); kernel.forceEvaluation(); System.gc(); System.out.println("Rotating"); kernel=EvOpRotateImage3D.apply(kernel, null,null, null); //old kernel is collected here System.out.println(kernel); kernel.forceEvaluation(); System.gc(); System.out.println("fft kernel"); EvStack[] ckernel=new EvOpFourierRealForwardFull3D().exec(kernel); ckernel[0].forceEvaluation(); ckernel[1].forceEvaluation(); System.out.println(ckernel[0]); System.out.println(ckernel[1]); System.gc(); System.out.println("fft im"); EvStack[] cin=new EvOpFourierRealForwardFull3D().exec(in); cin[0].forceEvaluation(); cin[1].forceEvaluation(); System.out.println(cin[0]); System.out.println(cin[1]); System.gc(); System.out.println("mul"); cin=new EvOpImageComplexMulImage().exec(cin[0],cin[1],ckernel[0],ckernel[1]); // EvStack[] mul=new EvOpImageComplexMulImage().exec(cin[0],cin[1],ckernel[0],ckernel[1]); cin[0].forceEvaluation(); cin[1].forceEvaluation(); System.out.println(cin[0]); System.out.println(cin[1]); System.gc(); return EvOpFourierComplexInverse3D.transform(cin[0], cin[1],true).fst(); */ System.out.println("Generating kernel"); EvStack kernel = GenerateSpecialImage.genGaussian3D(sigmaX, sigmaY, sigmaZ, w, h, d); System.gc(); System.out.println("Rotating"); kernel = EvOpWrapImage3D.apply(kernel, null, null, null); // old kernel is collected here System.gc(); System.out.println("fft kernel"); Tuple<EvStack, EvStack> ckernel = EvOpFourierRealForwardFull3D.transform(kernel); System.gc(); System.out.println("fft im"); Tuple<EvStack, EvStack> cin = EvOpFourierRealForwardFull3D.transform(in); System.gc(); /* System.out.println("mul"); EvStack[] mul=new EvOpImageComplexMulImage().exec(cin.fst(),cin.snd(),ckernel.fst(),ckernel.snd()); System.gc(); return EvOpFourierComplexInverse3D.transform(mul[0], mul[1],true).fst(); */ System.out.println("mul"); EvOpImageComplexMulImage.timesInPlaceDouble(cin.fst(), cin.snd(), ckernel.fst(), ckernel.snd()); System.gc(); return EvOpFourierComplexInverse3D.transform(cin.fst(), cin.snd(), true).fst(); }