X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Futil%2FForesterUtil.java;h=f144a81684894675f7a3442a03586b1560e9b619;hb=aff0b302cc19e0ee3e73bc4a87884b4591ac5f08;hp=48d973b500c4c6fdaf95c192f82888caf7769b69;hpb=fea4064e24c6cb362b0e033cf7047afd20f5f53f;p=jalview.git
diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java
index 48d973b..f144a81 100644
--- a/forester/java/src/org/forester/util/ForesterUtil.java
+++ b/forester/java/src/org/forester/util/ForesterUtil.java
@@ -34,6 +34,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
+import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -98,7 +99,7 @@ public final class ForesterUtil {
public final static String OS_VERSION = System.getProperty( "os.version" );
public static final String PDB = "http://www.pdb.org/pdb/explore/explore.do?pdbId=";
public final static String UNIPROT_KB = "http://www.uniprot.org/uniprot/";
- public final static double ZERO_DIFF = 1.0E-9;
+ public final static double ZERO_DIFF = 1.0E-12;
private static final Pattern PARANTHESESABLE_NH_CHARS_PATTERN = Pattern.compile( "[(),;\\s:\\[\\]]" );
static {
final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
@@ -116,6 +117,13 @@ public final class ForesterUtil {
}
}
+ final public static String removeFileExtension( final String file_name ) {
+ if ( file_name.indexOf( "." ) > 0 ) {
+ return file_name.substring( 0, file_name.lastIndexOf( "." ) );
+ }
+ return file_name;
+ }
+
/**
* This calculates a color. If value is equal to min the returned color is
* minColor, if value is equal to max the returned color is maxColor,
@@ -220,7 +228,8 @@ public final class ForesterUtil {
final private static int calculateColorComponent( final double smallercolor_component_x,
final double largercolor_component_x,
final double x ) {
- return ( int ) ( smallercolor_component_x + ( ( x * ( largercolor_component_x - smallercolor_component_x ) ) / 255.0 ) );
+ return ( int ) ( smallercolor_component_x
+ + ( ( x * ( largercolor_component_x - smallercolor_component_x ) ) / 255.0 ) );
}
/**
@@ -533,15 +542,16 @@ public final class ForesterUtil {
}
final public static MolecularSequence.TYPE guessMolecularSequenceType( final String mol_seq ) {
- if ( mol_seq.contains( "L" ) || mol_seq.contains( "I" ) || mol_seq.contains( "E" ) || mol_seq.contains( "H" )
- || mol_seq.contains( "D" ) || mol_seq.contains( "Q" ) ) {
+ final String s = mol_seq.toUpperCase();
+ if ( s.contains( "L" ) || s.contains( "I" ) || s.contains( "E" ) || s.contains( "H" ) || s.contains( "D" )
+ || s.contains( "Q" ) ) {
return TYPE.AA;
}
else {
- if ( mol_seq.contains( "T" ) ) {
+ if ( s.contains( "T" ) ) {
return TYPE.DNA;
}
- else if ( mol_seq.contains( "U" ) ) {
+ else if ( s.contains( "U" ) ) {
return TYPE.RNA;
}
}
@@ -585,6 +595,13 @@ public final class ForesterUtil {
return ( ( s == null ) || ( s.length() < 1 ) );
}
+ final public static boolean isEmptyTrimmed( final String s ) {
+ if ( s == null ) {
+ return true;
+ }
+ return ( ( s.trim().length() < 1 ) );
+ }
+
/**
* Returns true is Domain domain falls in an uninterrupted stretch of
* covered positions.
@@ -606,6 +623,10 @@ public final class ForesterUtil {
return ( ( Math.abs( a - b ) ) < ZERO_DIFF );
}
+ final public static boolean isEqual( final double a, final double b, final double tolerance ) {
+ return ( ( Math.abs( a - b ) ) < tolerance );
+ }
+
final public static boolean isEven( final int n ) {
return ( n % 2 ) == 0;
}
@@ -703,6 +724,10 @@ public final class ForesterUtil {
return null;
}
+ final public static String isWritableFile( final String s ) {
+ return isWritableFile( new File( s ) );
+ }
+
/**
* Helper for method "stringToColor".
*
@@ -734,7 +759,8 @@ public final class ForesterUtil {
final public static void map2file( final File file,
final Map, ?> data,
final String entry_separator,
- final String data_separator ) throws IOException {
+ final String data_separator )
+ throws IOException {
final Writer writer = new BufferedWriter( new FileWriter( file ) );
map2writer( writer, data, entry_separator, data_separator );
writer.close();
@@ -743,7 +769,8 @@ public final class ForesterUtil {
final public static void map2writer( final Writer writer,
final Map, ?> data,
final String entry_separator,
- final String data_separator ) throws IOException {
+ final String data_separator )
+ throws IOException {
boolean first = true;
for( final Entry, ?> entry : data.entrySet() ) {
if ( !first ) {
@@ -758,7 +785,8 @@ public final class ForesterUtil {
}
}
- final public static StringBuffer mapToStringBuffer( final Map