| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | import org.slf4j.Logger; | |
| 24 | 24 | import org.slf4j.LoggerFactory; | |
| 25 | 25 | ||
| 26 | + import java.nio.CharBuffer; | ||
| 26 | 27 | import java.util.HashSet; | |
| 27 | 28 | import java.util.Set; | |
| 28 | 29 | ||
@@ -68,10 +69,10 @@ public final static double roundToDecimals(double d, int c) { | |||
| 68 | 69 | * true if invalid characters are found, else return false. | |
| 69 | 70 | */ | |
| 70 | 71 | public final static boolean doesSequenceContainInvalidChar(String sequence, Set<Character> cSet){ | |
| 71 | - for(char c:sequence.toCharArray()){ | ||
| 72 | - if(!cSet.contains(c)) return true; | ||
| 73 | - } | ||
| 74 | - return false; | ||
| 72 | + for(char c:sequence.toCharArray()){ | ||
| 73 | + if(!cSet.contains(c)) return true; | ||
| 74 | + } | ||
| 75 | + return false; | ||
| 75 | 76 | } | |
| 76 | 77 | ||
| 77 | 78 | /** | |
@@ -86,15 +87,10 @@ public final static boolean doesSequenceContainInvalidChar(String sequence, Set< | |||
| 86 | 87 | * @return | |
| 87 | 88 | * the number of invalid characters in sequence. | |
| 88 | 89 | */ | |
| 89 | - public final static int getNumberOfInvalidChar(String sequence, Set<Character> cSet, boolean ignoreCase){ | ||
| 90 | - int total = 0; | ||
| 91 | - char[] cArray; | ||
| 92 | - if(ignoreCase) cArray = sequence.toUpperCase().toCharArray(); | ||
| 93 | - else cArray = sequence.toCharArray(); | ||
| 94 | - if(cSet == null) cSet = PeptideProperties.standardAASet; | ||
| 95 | - for(char c:cArray){ | ||
| 96 | - if(!cSet.contains(c)) total++; | ||
| 97 | - } | ||
| 90 | + public final static int getNumberOfInvalidChar(String sequence, Set<Character> cSet, boolean ignoreCase){ | ||
| 91 | + char[] cArray = ignoreCase ? sequence.toUpperCase().toCharArray(): sequence.toCharArray(); | ||
| 92 | + final Set<Character> characterSet = cSet == null ?PeptideProperties.standardAASet: cSet ; | ||
| 93 | + int total = (int)CharBuffer.wrap(cArray).chars().filter(character -> !characterSet.contains((char)character)).count(); | ||
| 98 | 94 | return total; | |
| 99 | 95 | } | |
| 100 | 96 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,9 +44,7 @@ private int getTotalCount(String convertedSeq, GROUPING group) throws Exception{ | |||
| 44 | 44 | default: throw new Exception("Unhandled Case: " + group); | |
| 45 | 45 | } | |
| 46 | 46 | int total = 0; | |
| 47 | - for(char c:convertedSeq.toCharArray()){ | ||
| 48 | - if(c == g) total++; | ||
| 49 | - } | ||
| 47 | + total = (int)convertedSeq.chars().filter(c ->(char) c == g) .count(); | ||
| 50 | 48 | return total; | |
| 51 | 49 | } | |
| 52 | 50 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,8 @@ | |||
| 20 | 20 | */ | |
| 21 | 21 | package org.biojava.nbio.aaproperties.profeat.convertor; | |
| 22 | 22 | ||
| 23 | + import java.util.stream.Collectors; | ||
| 24 | + | ||
| 23 | 25 | import org.biojava.nbio.core.sequence.ProteinSequence; | |
| 24 | 26 | ||
| 25 | 27 | public abstract class Convertor { | |
@@ -78,12 +80,8 @@ public abstract class Convertor { | |||
| 78 | 80 | * @return the converted sequence | |
| 79 | 81 | */ | |
| 80 | 82 | public String convert(ProteinSequence sequence){ | |
| 81 | - String convertedSequence = ""; | ||
| 82 | 83 | String uppercaseSequence = sequence.getSequenceAsString().toUpperCase(); | |
| 83 | - for(int x = 0; x < uppercaseSequence.length(); x++){ | ||
| 84 | - convertedSequence += String.valueOf(convert(uppercaseSequence.charAt(x))); | ||
| 85 | - } | ||
| 84 | + String convertedSequence = uppercaseSequence.chars().mapToObj(upperCaseSeq -> String.valueOf(convert((char)(upperCaseSeq)))).collect(Collectors.joining()); | ||
| 86 | 85 | return convertedSequence; | |
| 87 | 86 | } | |
| 88 | - | ||
| 89 | 87 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,10 @@ | |||
| 29 | 29 | import java.nio.file.Files; | |
| 30 | 30 | import java.nio.file.StandardCopyOption; | |
| 31 | 31 | import java.util.ArrayList; | |
| 32 | + import java.util.Arrays; | ||
| 32 | 33 | import java.util.List; | |
| 34 | + import java.util.stream.Collectors; | ||
| 35 | + import java.util.stream.Stream; | ||
| 33 | 36 | ||
| 34 | 37 | /** | |
| 35 | 38 | * Phosphosite is available under the PhosphoSitePlus® is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License and is freely available for non-commercial purposes from | |
@@ -76,27 +79,12 @@ private String[] getRemoteFiles(){ | |||
| 76 | 79 | } | |
| 77 | 80 | ||
| 78 | 81 | public File[] getLocalFiles(){ | |
| 79 | - | ||
| 80 | 82 | String[] rfiles = getRemoteFiles(); | |
| 81 | - | ||
| 82 | - | ||
| 83 | 83 | File dir = getLocalDir(); | |
| 84 | - | ||
| 85 | - List<File> files = new ArrayList<File>(); | ||
| 86 | - for ( String f : rfiles) { | ||
| 87 | - | ||
| 88 | - | ||
| 89 | - int slashIndex = f.lastIndexOf("/"); | ||
| 90 | - | ||
| 91 | - String fileName = f.substring(slashIndex); | ||
| 92 | - | ||
| 93 | - File localFile = new File(dir+"/" + fileName); | ||
| 94 | - | ||
| 95 | - if ( localFile.exists()){ | ||
| 96 | - files.add(localFile); | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - } | ||
| 84 | + List<File> files = Arrays.stream(rfiles).map(remoteFileName -> remoteFileName.substring(remoteFileName.lastIndexOf("/"))) | ||
| 85 | + .map(localFile -> new File(dir+"/"+localFile)) | ||
| 86 | + .filter(file -> file.exists()) | ||
| 87 | + .collect(Collectors.toList()); | ||
| 100 | 88 | ||
| 101 | 89 | return files.toArray(new File[files.size()]); | |
| 102 | 90 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -180,11 +180,9 @@ private static float[] predictSerial(FastaSequence fsequence) { | |||
| 180 | 180 | try { | |
| 181 | 181 | ronn = new ORonn(fsequence, loader); | |
| 182 | 182 | disorder = ronn.call().getMeanScores(); | |
| 183 | - } catch (NumberFormatException e) { | ||
| 184 | - throw new RuntimeException("Jronn fails to load models " + e.getLocalizedMessage(), e); | ||
| 185 | - } catch (IOException e) { | ||
| 183 | + } catch (NumberFormatException | IOException e) { | ||
| 186 | 184 | throw new RuntimeException("Jronn fails to load models " + e.getLocalizedMessage(), e); | |
| 187 | - } | ||
| 185 | + } | ||
| 188 | 186 | return disorder; | |
| 189 | 187 | } | |
| 190 | 188 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,8 @@ | |||
| 39 | 39 | import java.util.List; | |
| 40 | 40 | import java.util.Locale; | |
| 41 | 41 | import java.util.concurrent.*; | |
| 42 | + import java.util.stream.IntStream; | ||
| 43 | + import java.util.stream.Stream; | ||
| 42 | 44 | ||
| 43 | 45 | ||
| 44 | 46 | /** | |
@@ -139,13 +141,9 @@ static boolean isValidSequence(final FastaSequence fsequence) { | |||
| 139 | 141 | public ORonn call() throws NumberFormatException, IOException { | |
| 140 | 142 | final String seq = sequence.getSequence(); | |
| 141 | 143 | // Calculate for each model | |
| 142 | - for (int m = 0; m < ORonn.NUMBER_OF_MODELS; m++) { | ||
| 143 | - final Model model = mloader.getModel(m); | ||
| 144 | - final ORonnModel rmodel = new ORonnModel(seq, model, disorder); | ||
| 145 | - final float[] scores = rmodel.detect(); | ||
| 146 | - addScore(scores); | ||
| 147 | - } | ||
| 148 | - | ||
| 144 | + Stream.iterate(0, n -> n +1).limit(NUMBER_OF_MODELS).map(modelNumber -> mloader.getModel(modelNumber)) | ||
| 145 | + .map(rmodel -> new ORonnModel(seq, rmodel, disorder).detect()) | ||
| 146 | + .forEach(score ->addScore(score)); | ||
| 149 | 147 | final char[] ch = seq.toCharArray(); | |
| 150 | 148 | final float[] meanScores = getMeanScores(); | |
| 151 | 149 | assert meanScores.length == seq.length() : "Scores are not calculated for " | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,7 @@ | |||
| 44 | 44 | import java.util.ArrayList; | |
| 45 | 45 | import java.util.Iterator; | |
| 46 | 46 | import java.util.List; | |
| 47 | + import java.util.stream.Stream; | ||
| 47 | 48 | ||
| 48 | 49 | ||
| 49 | 50 | /** | |
@@ -796,12 +797,9 @@ public String printHelp() { | |||
| 796 | 797 | Iterator<String> helpIt = paramHelp.iterator(); | |
| 797 | 798 | ||
| 798 | 799 | buf.append("--- ").append(alg.getAlgorithmName()).append(" parameters: ---").append(newline); | |
| 799 | - for(int i = 0; i< size; i++) { | ||
| 800 | - String name = namesIt.next(); | ||
| 801 | - buf.append(" -").append(Introspector.decapitalize(name)); | ||
| 802 | - buf.append(" ").append(helpIt.next()); | ||
| 803 | - buf.append(newline); | ||
| 804 | - } | ||
| 800 | + Stream.iterate(0, n -> n + 1).limit(size) | ||
| 801 | + .map(i -> namesIt.next()) | ||
| 802 | + .forEach(name -> buf.append(" -").append(Introspector.decapitalize(name)).append(" ").append(helpIt.next()).append(newline)); | ||
| 805 | 803 | } | |
| 806 | 804 | buf.append(newline); | |
| 807 | 805 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments