Skip to content

Commit e75eae5

Browse files
committed
Merge branch 'master' of github.com:biojava/biojava
2 parents 222a8ae + 5b41ddf commit e75eae5

7 files changed

Lines changed: 31 additions & 57 deletions

File tree

biojava-aa-prop/src/main/java/org/biojava/nbio/aaproperties/Utils.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
2525

26+
import java.nio.CharBuffer;
2627
import java.util.HashSet;
2728
import java.util.Set;
2829

@@ -68,10 +69,10 @@ public final static double roundToDecimals(double d, int c) {
6869
* true if invalid characters are found, else return false.
6970
*/
7071
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;
7576
}
7677

7778
/**
@@ -86,15 +87,10 @@ public final static boolean doesSequenceContainInvalidChar(String sequence, Set<
8687
* @return
8788
* the number of invalid characters in sequence.
8889
*/
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();
9894
return total;
9995
}
10096

biojava-aa-prop/src/main/java/org/biojava/nbio/aaproperties/profeat/ProfeatPropertiesImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ private int getTotalCount(String convertedSeq, GROUPING group) throws Exception{
4444
default: throw new Exception("Unhandled Case: " + group);
4545
}
4646
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();
5048
return total;
5149
}
5250

biojava-aa-prop/src/main/java/org/biojava/nbio/aaproperties/profeat/convertor/Convertor.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
package org.biojava.nbio.aaproperties.profeat.convertor;
2222

23+
import java.util.stream.Collectors;
24+
2325
import org.biojava.nbio.core.sequence.ProteinSequence;
2426

2527
public abstract class Convertor {
@@ -78,12 +80,8 @@ public abstract class Convertor {
7880
* @return the converted sequence
7981
*/
8082
public String convert(ProteinSequence sequence){
81-
String convertedSequence = "";
8283
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());
8685
return convertedSequence;
8786
}
88-
8987
}

biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Dataset.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
import java.nio.file.Files;
3030
import java.nio.file.StandardCopyOption;
3131
import java.util.ArrayList;
32+
import java.util.Arrays;
3233
import java.util.List;
34+
import java.util.stream.Collectors;
35+
import java.util.stream.Stream;
3336

3437
/**
3538
* 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(){
7679
}
7780

7881
public File[] getLocalFiles(){
79-
8082
String[] rfiles = getRemoteFiles();
81-
82-
8383
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());
10088

10189
return files.toArray(new File[files.size()]);
10290
}

biojava-protein-disorder/src/main/java/org/biojava/nbio/ronn/Jronn.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,9 @@ private static float[] predictSerial(FastaSequence fsequence) {
180180
try {
181181
ronn = new ORonn(fsequence, loader);
182182
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) {
186184
throw new RuntimeException("Jronn fails to load models " + e.getLocalizedMessage(), e);
187-
}
185+
}
188186
return disorder;
189187
}
190188

biojava-protein-disorder/src/main/java/org/biojava/nbio/ronn/ORonn.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import java.util.List;
4040
import java.util.Locale;
4141
import java.util.concurrent.*;
42+
import java.util.stream.IntStream;
43+
import java.util.stream.Stream;
4244

4345

4446
/**
@@ -139,13 +141,9 @@ static boolean isValidSequence(final FastaSequence fsequence) {
139141
public ORonn call() throws NumberFormatException, IOException {
140142
final String seq = sequence.getSequence();
141143
// 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));
149147
final char[] ch = seq.toCharArray();
150148
final float[] meanScores = getMeanScores();
151149
assert meanScores.length == seq.length() : "Scores are not calculated for "

biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/AbstractUserArgumentProcessor.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.ArrayList;
4545
import java.util.Iterator;
4646
import java.util.List;
47+
import java.util.stream.Stream;
4748

4849

4950
/**
@@ -796,12 +797,9 @@ public String printHelp() {
796797
Iterator<String> helpIt = paramHelp.iterator();
797798

798799
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));
805803
}
806804
buf.append(newline);
807805

0 commit comments

Comments
 (0)