List of usage examples for org.apache.commons.math3.util Pair getValue
public V getValue()
From source file:ldbc.snb.datagen.generator.distribution.utils.Bucket.java
public static ArrayList<Bucket> bucketizeHistogram(ArrayList<Pair<Integer, Integer>> histogram, int num_buckets) { ArrayList<Bucket> buckets = new ArrayList<Bucket>(); int population = 0; int num_edges = 0; for (Pair<Integer, Integer> i : histogram) { population += i.getValue(); num_edges += i.getValue() * i.getKey(); }/*from ww w . j av a 2 s. c o m*/ num_edges /= 2; int avgDegreeAt1B = 200; int avgDegree = num_edges / population; double aCoeff = Math.log(avgDegreeAt1B) / Math.log(1000000000); double bCoeff = (aCoeff - (Math.log(avgDegree) / Math.log(population))) / Math.log10(population); int target_mean = (int) Math.round( Math.pow(DatagenParams.numPersons, (aCoeff - bCoeff * Math.log10(DatagenParams.numPersons)))); System.out.println("Distribution mean degree: " + avgDegree + " Distribution target mean " + target_mean); int bucket_size = (int) (Math.ceil(population / (double) (num_buckets))); int current_histogram_index = 0; int current_histogram_left = histogram.get(current_histogram_index).getValue(); for (int i = 0; i < num_buckets && (current_histogram_index < histogram.size()); ++i) { int current_bucket_count = 0; int min = population; int max = 0; while (current_bucket_count < bucket_size && current_histogram_index < histogram.size()) { int degree = histogram.get(current_histogram_index).getKey(); min = degree < min ? degree : min; max = degree > max ? degree : max; if ((bucket_size - current_bucket_count) > current_histogram_left) { current_bucket_count += current_histogram_left; current_histogram_index++; if (current_histogram_index < histogram.size()) { current_histogram_left = histogram.get(current_histogram_index).getValue(); } } else { current_histogram_left -= (bucket_size - current_bucket_count); current_bucket_count = bucket_size; } } min = (int) (min * target_mean / (double) avgDegree); max = (int) (max * target_mean / (double) avgDegree); buckets.add(new Bucket(min, max)); } return buckets; }
From source file:com.insightml.utils.Collections.java
public static <V> LinkedList<V> values(final List<? extends Pair<?, V>> run) { final LinkedList<V> values = new LinkedList<>(); for (final Pair<?, V> entry : run) { if (entry.getValue() != null) { values.add(entry.getValue()); }/*from ww w. jav a2 s . c o m*/ } return values; }
From source file:database.HashTablesTools.java
public static boolean addAFile(String pathToFile, String fourLetterCode, Connection connexion, String tableName, String tableFailureName, AlgoParameters algoParameters) throws IOException, NoSuchAlgorithmException { String hash = HashTablesTools.getMD5hash(pathToFile); // TODO add check to failure db boolean alreadyParsed = false; try {//from ww w.j av a2 s . c o m alreadyParsed = fileAlreadyParsedDetectedByHash(connexion, tableName, tableFailureName, hash); } catch (SQLException e) { return false; } if (alreadyParsed == true) { //System.out.println("Already parsed in DB, nothing to do"); return false; } Pair<String, MyStructureIfc> pairPathMyStructure = IOTools.getMyStructureIfc(algoParameters, pathToFile); if (pairPathMyStructure == null || pairPathMyStructure.getValue() == null) { insertIntoFailureTable(connexion, tableFailureName, hash, fourLetterCode); return false; } MyChainIfc[] chainsForShapeBuilding = pairPathMyStructure.getValue().getAllChainsRelevantForShapeBuilding(); int countEntries = 0; Chains: for (MyChainIfc chain : chainsForShapeBuilding) { MyMonomerType monomerType = MyMonomerType.getEnumType(chain.getMyMonomers()[0].getType()); char[] chainType = " ".toCharArray(); if (monomerType.equals(MyMonomerType.AMINOACID)) { chainType = "AA".toCharArray(); } if (monomerType.equals(MyMonomerType.NUCLEOTIDE)) { chainType = "NU".toCharArray(); } if (monomerType.equals(MyMonomerType.HETATM)) { continue Chains; } char[] chainName = chain.getChainId(); String sequence = SequenceTools.generateSequence(chain); if (sequence.length() > HashTablesTools.maxCharInVarchar) { String truncatedSequence = sequence.substring(0, HashTablesTools.maxCharInVarchar); sequence = truncatedSequence; } countEntries += enterInPDBfilesHashDB(connexion, hash, fourLetterCode, tableName, chainType, chainName, sequence); } if (countEntries == 0) { insertIntoFailureTable(connexion, tableFailureName, hash, fourLetterCode); } return true; }
From source file:io.IOTools.java
public static Pair<String, MyStructureIfc> getMyStructureIfc(AlgoParameters algoParameters, String pathToFile) { BiojavaReader reader = new BiojavaReader(algoParameters); Pair<String, Structure> pairPathStructure = null; try {//from www.j ava2 s . c o m pairPathStructure = reader.read(pathToFile, algoParameters.getPATH_TO_CHEMCOMP_FOLDER()); } catch (IOException | ExceptionInIOPackage e) { return null; } AdapterBioJavaStructure adapterBioJavaStructure = new AdapterBioJavaStructure(algoParameters); MyStructureIfc mystructure = null; String pdbFileHash = null; try { pdbFileHash = HashTablesTools.getMD5hash(pathToFile); } catch (NoSuchAlgorithmException | IOException e) { e.printStackTrace(); } try { mystructure = adapterBioJavaStructure.getMyStructureAndSkipHydrogens(pairPathStructure.getValue(), pdbFileHash); } catch (ExceptionInMyStructurePackage | ReadingStructurefileException | ExceptionInConvertFormat e) { return null; } Pair<String, MyStructureIfc> pairPathMyStructure = new Pair(pairPathStructure.getKey(), mystructure); return pairPathMyStructure; }
From source file:io.IOTools.java
/** * @param algoParameters/* ww w .j a v a 2 s .c o m*/ * @param fourLetterCode that must be lower case * @return Can return null */ public static Pair<String, MyStructureIfc> getMyStructureIfc(AlgoParameters algoParameters, char[] fourLetterCode) { BiojavaReader reader = new BiojavaReader(algoParameters); Pair<String, Structure> pairPathStructure = null; try { // TODO change to char[] pairPathStructure = reader.readFromPDBFolder(String.valueOf(fourLetterCode), algoParameters.getPATH_TO_REMEDIATED_PDB_MMCIF_FOLDER(), algoParameters.getPATH_TO_CHEMCOMP_FOLDER()); } catch (IOException | ExceptionInIOPackage e) { return null; } String pdbFileHash = null; try { pdbFileHash = HashTablesTools.getMD5hash(pairPathStructure.getKey()); } catch (NoSuchAlgorithmException | IOException e) { e.printStackTrace(); } AdapterBioJavaStructure adapterBioJavaStructure = new AdapterBioJavaStructure(algoParameters); MyStructureIfc mystructure = null; try { mystructure = adapterBioJavaStructure.getMyStructureAndSkipHydrogens(pairPathStructure.getValue(), pdbFileHash); } catch (ExceptionInMyStructurePackage | ReadingStructurefileException | ExceptionInConvertFormat e) { return null; } Pair<String, MyStructureIfc> pairPathMyStructure = new Pair(pairPathStructure.getKey(), mystructure); return pairPathMyStructure; }
From source file:genericBuffer.MyStructureBuffer.java
public synchronized MyStructureIfc getStructure(char[] fourLettercode) { String fourLettercodeString = String.valueOf(fourLettercode); for (Pair<String, MyStructureIfc> storeElement : queue) { if (storeElement.getFirst().equals(fourLettercodeString)) { return storeElement.getValue(); }/*from ww w.java2 s. c o m*/ } return null; }
From source file:io.warp10.script.functions.OPTDTW.java
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { Object o = stack.pop();/*from w ww . j ava 2 s.c o m*/ if (!(o instanceof Number)) { throw new WarpScriptException( getName() + " expects a count of best restults to return on top of the stack."); } int count = ((Number) o).intValue(); o = stack.pop(); if (!(o instanceof List)) { throw new WarpScriptException(getName() + " expects a numeric list to use as query below the count."); } double[] query = new double[((List) o).size()]; int i = 0; for (Object oo : (List) o) { query[i++] = ((Number) oo).doubleValue(); } // Z-Normalize query double[] musigma = DoubleUtils.musigma(query, true); for (i = 0; i < query.length; i++) { query[i] = (query[i] - musigma[0]) / musigma[1]; } o = stack.pop(); if (!(o instanceof List)) { throw new WarpScriptException(getName() + " expects a numeric list as the sequence in which to find best matches below the 'query' list."); } double[] sequence = new double[((List) o).size()]; i = 0; for (Object oo : (List) o) { sequence[i++] = ((Number) oo).doubleValue(); } if (sequence.length <= query.length) { throw new WarpScriptException( getName() + " expects the query list to be shorter than the sequence list."); } double mindist = 0.0; PriorityQueue<Pair<Integer, Double>> distances = new PriorityQueue<Pair<Integer, Double>>( new Comparator<Pair<Integer, Double>>() { @Override public int compare(Pair<Integer, Double> o1, Pair<Integer, Double> o2) { return o1.getValue().compareTo(o2.getValue()); } }); double[] subsequence = new double[query.length]; for (i = 0; i <= sequence.length - query.length; i++) { System.arraycopy(sequence, i, subsequence, 0, query.length); // Z-Normalize the subsequence musigma = DoubleUtils.musigma(subsequence, true); for (int j = 0; j < subsequence.length; j++) { subsequence[j] = (subsequence[j] - musigma[0]) / musigma[1]; } double dist = dtw.compute(query, 0, query.length, subsequence, 0, query.length, mindist); if (dist < 0) { continue; } distances.add(new Pair<Integer, Double>(i, dist)); // // If the priority queue is of 'count' size, retrieve the largest distance and // use it as the threshold for the DTW computation // if (count > 0 && distances.size() >= count) { Object adist[] = distances.toArray(); mindist = ((Pair<Integer, Double>) adist[count - 1]).getValue(); } } List<List<Object>> results = new ArrayList<List<Object>>(); while (!distances.isEmpty()) { Pair<Integer, Double> entry = distances.poll(); List<Object> result = new ArrayList<Object>(); result.add(entry.getKey()); result.add(entry.getValue()); results.add(result); if (count > 0 && count == results.size()) { break; } } stack.push(results); return stack; }
From source file:myjmol.ScriptCommandOnUltiJmolTest.java
@Test public void computeHydrogensEnergyAfterHydrogenMinimization() throws IOException, ParsingConfigFileException { AlgoParameters algoParameters = Tools.generateModifiedAlgoParametersForTestWithTestFoldersWithUltiJmol(); int initialCount = algoParameters.ultiJMolBuffer.getSize(); // Prepare input as environment of MSQ in 1di9 String fourLetterCode = "1di9"; Pair<String, MyStructureIfc> pathAndMyStructure = IOTools.getMyStructureIfc(algoParameters, fourLetterCode.toCharArray()); MyMonomerIfc msqLigand = pathAndMyStructure.getValue().getHeteroChain("A".toCharArray()) .getMyMonomerFromResidueId(500); MyChainIfc[] neighbors = msqLigand.getNeighboringAminoMyMonomerByRepresentativeAtomDistance(); Cloner cloner2 = new Cloner(neighbors, algoParameters); MyStructureIfc target = cloner2.getClone(); Protonate protonate = new Protonate(target, algoParameters); try {//from ww w . j a v a2 s. com protonate.compute(); } catch (ExceptionInScoringUsingBioJavaJMolGUI | ShapeBuildingException exceptionInScoringUsingBioJavaJMolGUI) { assertTrue(false); } MyStructureIfc protonatedTarget = protonate.getProtonatedMyStructure(); protonatedTarget.setFourLetterCode("1di9".toCharArray()); String moleculeV3000 = protonatedTarget.toV3000(); try { Thread.sleep(1000L); } catch (InterruptedException e) { e.printStackTrace(); } String script = MyJmolScripts.getScriptMinimizationOnlyHydrogens(); ScriptCommandOnUltiJmol scriptCommandOnUltiJmol = new ScriptCommandOnUltiJmol(script, moleculeV3000, algoParameters, null); try { scriptCommandOnUltiJmol.execute(); } catch (ExceptionInScoringUsingBioJavaJMolGUI exceptionInScoringUsingBioJavaJMolGUI) { assertTrue(false); // Should not happen. Only if energy during minimization failed to be obtained } Map<Results, Object> results = scriptCommandOnUltiJmol.getResults(); boolean convergenceReached = (boolean) results.get(Results.CONVERGENCE_REACHED); Float finalEnergy = (Float) results.get(Results.FINAL_ENERGY); assertTrue(convergenceReached); // not reproducible System.out.println("finalEnergy = " + finalEnergy); // also possible finalEnergy = 5460.785 //assertEquals(finalEnergy, 597.0f, 50.0f); int finalCount = algoParameters.ultiJMolBuffer.getSize(); assertTrue(finalCount == initialCount); try { for (int i = 0; i < initialCount; i++) { algoParameters.ultiJMolBuffer.get().frame.dispose(); } } catch (InterruptedException e) { e.printStackTrace(); } assertTrue(algoParameters.ultiJMolBuffer.getSize() == 0); }
From source file:mystructure.ClonerTest.java
@Test public void testClonerWithMyMonomerAndConvertionToV3000() throws ParsingConfigFileException, IOException, ReadingStructurefileException, ExceptionInMyStructurePackage { AlgoParameters algoParameters = Tools.generateModifiedAlgoParametersForTestWithTestFoldersWithUltiJmol(); String fourLetterCode = "1di9"; Pair<String, MyStructureIfc> pathAndMyStructure = IOTools.getMyStructureIfc(algoParameters, fourLetterCode.toCharArray()); int initialCount = algoParameters.ultiJMolBuffer.getSize(); MyMonomerIfc msqLigand = pathAndMyStructure.getValue().getHeteroChain("A".toCharArray()) .getMyMonomerFromResidueId(500); Cloner cloner = new Cloner(msqLigand, algoParameters); MyStructureIfc myStructureFromAMyMonomer = cloner.getClone(); String myStructureV3000 = myStructureFromAMyMonomer.toV3000(); // write to a temp text file String pathToTempFolder = folder.getRoot().getAbsolutePath(); String pathTOWriteV3000Molfile = pathToTempFolder + "//v3000test.mol"; WriteTextFile.writeTextFile(myStructureV3000, pathTOWriteV3000Molfile); // read it with cdk and check atom and bond count IAtomContainer mol = CdkTools.readV3000molFile(pathTOWriteV3000Molfile); int atomCount = MyStructureTools.getAtomCount(myStructureFromAMyMonomer); int bondCount = TestTools.getBondCount(myStructureFromAMyMonomer); assertTrue(mol.getAtomCount() == atomCount); assertTrue(mol.getBondCount() * 2 == bondCount); int finalCount = algoParameters.ultiJMolBuffer.getSize(); assertTrue(finalCount == initialCount); try {/* w ww . jav a2 s . c o m*/ for (int i = 0; i < initialCount; i++) { algoParameters.ultiJMolBuffer.get().frame.dispose(); } } catch (InterruptedException e) { e.printStackTrace(); } assertTrue(algoParameters.ultiJMolBuffer.getSize() == 0); }
From source file:database.SequenceToolsTest.java
@Test public void testGenerateSequenceFromMyStructureWithThreeUMPcovalentToNucleosides() throws ParsingConfigFileException, IOException { AlgoParameters algoParameters = Tools.generateModifiedAlgoParametersForTestWithTestFolders(); String fourLetterCode = "229d"; Pair<String, MyStructureIfc> pathAndMyStructure = IOTools.getMyStructureIfc(algoParameters, fourLetterCode.toCharArray()); String sequence = SequenceTools.generateSequence(pathAndMyStructure.getValue().getAllNucleosidechains()[0]); assertTrue(sequence.equals(" DC DC DA DG DA DCUMP DG DA DAMG1 DAUMP5CMUMP DG DG")); }