2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // Copyright (C) 2000-2001 Washington University School of Medicine
8 // and Howard Hughes Medical Institute
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 // Contact: phylosoft @ gmail . com
26 // WWW: www.phylosoft.org/forester
28 package org.forester.sdi;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Arrays;
34 import java.util.HashMap;
35 import java.util.HashSet;
36 import java.util.List;
39 import org.forester.datastructures.IntMatrix;
40 import org.forester.io.parsers.PhylogenyParser;
41 import org.forester.io.parsers.nhx.NHXParser;
42 import org.forester.io.parsers.util.ParserUtils;
43 import org.forester.phylogeny.Phylogeny;
44 import org.forester.phylogeny.PhylogenyMethods;
45 import org.forester.phylogeny.PhylogenyNode;
46 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
47 import org.forester.phylogeny.factories.PhylogenyFactory;
48 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
49 import org.forester.util.ForesterUtil;
52 * @author Christian M. Zmasek
54 public final class RIO {
56 private final static boolean ROOT_BY_MINIMIZING_MAPPING_COST = false;
57 private final static boolean ROOT_BY_MINIMIZING_SUM_OF_DUPS = true;
58 private final static boolean ROOT_BY_MINIMIZING_TREE_HEIGHT = true;
59 private HashMap<String, HashMap<String, Integer>> _o_hash_maps;
60 private HashMap<String, HashMap<String, Integer>> _so_hash_maps;
61 private HashMap<String, HashMap<String, Integer>> _up_hash_maps;
62 private List<String> _seq_names;
64 private int _ext_nodes_;
67 * Default constructor.
73 public static IntMatrix calculateOrthologTable( final Phylogeny[] gene_trees ) {
74 final List<String> labels = new ArrayList<String>();
75 final Set<String> labels_set = new HashSet<String>();
77 for( final PhylogenyNode n : gene_trees[ 0 ].getExternalNodes() ) {
78 if ( n.getNodeData().isHasSequence() && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
79 label = n.getNodeData().getSequence().getName();
81 else if ( n.getNodeData().isHasSequence()
82 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
83 label = n.getNodeData().getSequence().getSymbol();
85 else if ( !ForesterUtil.isEmpty( n.getName() ) ) {
89 throw new IllegalArgumentException( "node " + n + " has no appropriate label" );
91 if ( labels_set.contains( label ) ) {
92 throw new IllegalArgumentException( "label " + label + " is not unique" );
94 labels_set.add( label );
97 final IntMatrix m = new IntMatrix( labels );
99 for( final Phylogeny gt : gene_trees ) {
100 System.out.println( counter );
102 PhylogenyMethods.preOrderReId( gt );
103 final HashMap<String, PhylogenyNode> map = PhylogenyMethods.createNameToExtNodeMap( gt );
104 for( int x = 0; x < m.size(); ++x ) {
105 final PhylogenyNode nx = map.get( m.getLabel( x ) );
106 for( int y = 0; y < m.size(); ++y ) {
107 if ( !PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( nx, map.get( m.getLabel( y ) ) )
109 m.inreaseByOne( x, y );
117 public final int getNumberOfSamples() {
121 // Helper method for inferredOrthologsToString.
122 // inferredOrthologsToArrayList,
123 // and inferredUltraParalogsToString.
124 private final double getBootstrapValueFromHash( final HashMap<String, Integer> h, final String name ) {
125 if ( !h.containsKey( name ) ) {
128 final int i = h.get( name );
129 return ( ( i * 100.0 ) / getNumberOfSamples() );
133 * Returns the numbers of number of ext nodes in gene trees analyzed (after
136 * @return number of ext nodes in gene trees analyzed (after stripping)
138 public final int getExtNodesOfAnalyzedGeneTrees() {
143 * Returns a HashMap containing the inferred orthologs of the external gene
144 * tree node with the sequence name seq_name. Sequence names are the keys
145 * (String), numbers of observations are the values (Int). Orthologs are to
146 * be inferred by method "inferOrthologs". Throws an exception if seq_name
150 * sequence name of a external node of the gene trees
151 * @return HashMap containing the inferred orthologs
152 * (name(String)->value(Int))
154 public final HashMap<String, Integer> getInferredOrthologs( final String seq_name ) {
155 if ( _o_hash_maps == null ) {
158 return _o_hash_maps.get( seq_name );
162 * Returns a HashMap containing the inferred "super orthologs" of the
163 * external gene tree node with the sequence name seq_name. Sequence names
164 * are the keys (String), numbers of observations are the values (Int).
165 * Super orthologs are to be inferred by method "inferOrthologs". Throws an
166 * exception if seq_name is not found.
169 * sequence name of a external node of the gene trees
170 * @return HashMap containing the inferred super orthologs
171 * (name(String)->value(Int))
173 public final HashMap<String, Integer> getInferredSuperOrthologs( final String seq_name ) {
174 if ( _so_hash_maps == null ) {
177 return _so_hash_maps.get( seq_name );
181 * Returns a HashMap containing the inferred "ultra paralogs" of the
182 * external gene tree node with the sequence name seq_name. Sequence names
183 * are the keys (String), numbers of observations are the values (Int).
184 * "ultra paralogs" are to be inferred by method "inferOrthologs". Throws an
185 * exception if seq_name is not found.
188 * sequence name of a external node of the gene trees
189 * @return HashMap containing the inferred ultra paralogs
190 * (name(String)->value(Int))
192 public final HashMap<String, Integer> getInferredUltraParalogs( final String seq_name ) {
193 if ( _up_hash_maps == null ) {
196 return _up_hash_maps.get( seq_name );
200 * Infers the orthologs (as well the "super orthologs", the "subtree
201 * neighbors", and the "ultra paralogs") for each external node of the gene
202 * Trees in multiple tree File gene_trees_file (=output of PHYLIP NEIGHBOR,
203 * for example). Tallies how many times each sequence is (super-)
204 * orthologous towards the query. Tallies how many times each sequence is
205 * ultra paralogous towards the query. Tallies how many times each sequence
206 * is a subtree neighbor of the query. Gene duplications are inferred using
207 * SDI. Modifies its argument species_tree. Is a little faster than
208 * "inferOrthologs(File,Phylogeny)" since orthologs are only inferred for
211 * To obtain the results use the methods listed below.
213 * @param gene_trees_file
214 * a File containing gene Trees in NH format, which is the result
215 * of performing a bootstrap analysis in PHYLIP
216 * @param species_tree
217 * a species Phylogeny, which has species names in its species
220 * the sequence name of the squence whose orthologs are to be
222 * @throws SDIException
224 public void inferOrthologs( final File gene_trees_file, final Phylogeny species_tree, final String query )
225 throws IOException, SDIException {
227 // Read in first tree to get its sequence names
228 // and strip species_tree.
229 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
230 final PhylogenyParser p = ParserUtils.createParserDependingOnFileType( gene_trees_file, true );
231 if ( p instanceof NHXParser ) {
232 final NHXParser nhx = ( NHXParser ) p;
233 nhx.setReplaceUnderscores( false );
234 nhx.setIgnoreQuotes( true );
235 nhx.setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
237 final Phylogeny[] gene_trees = factory.create( gene_trees_file, p );
238 // Removes from species_tree all species not found in gene_tree.
239 PhylogenyMethods.taxonomyBasedDeletionOfExternalNodes( gene_trees[ 0 ], species_tree );
240 PhylogenyMethods.taxonomyBasedDeletionOfExternalNodes( species_tree, gene_trees[ 0 ] );
241 _seq_names = getAllExternalSequenceNames( gene_trees[ 0 ] );
242 if ( ( _seq_names == null ) || ( _seq_names.size() < 1 ) ) {
243 throw new IOException( "could not get sequence names" );
245 _o_hash_maps = new HashMap<String, HashMap<String, Integer>>();
246 _so_hash_maps = new HashMap<String, HashMap<String, Integer>>();
247 _up_hash_maps = new HashMap<String, HashMap<String, Integer>>();
248 _o_hash_maps.put( query, new HashMap<String, Integer>( _seq_names.size() ) );
249 _so_hash_maps.put( query, new HashMap<String, Integer>( _seq_names.size() ) );
250 _up_hash_maps.put( query, new HashMap<String, Integer>( _seq_names.size() ) );
251 // Go through all gene trees in the file.
252 final Phylogeny[] assigned_trees = new Phylogeny[ gene_trees.length ];
253 System.out.println( "gene trees" + gene_trees.length );
255 for( final Phylogeny gt : gene_trees ) {
257 // Removes from gene_tree all species not found in species_tree.
258 PhylogenyMethods.taxonomyBasedDeletionOfExternalNodes( species_tree, gt );
259 assigned_trees[ c++ ] = inferOrthologsHelper( gt, species_tree, query );
261 final IntMatrix m = calculateOrthologTable( assigned_trees );
262 System.out.println( m.toString() );
263 setNumberOfSamples( gene_trees.length );
266 public List<PhylogenyNode> getNodesViaSequenceName( final Phylogeny phy, final String seq_name ) {
267 final List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();
268 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
269 final PhylogenyNode n = iter.next();
270 if ( n.getNodeData().isHasSequence() && n.getNodeData().getSequence().getName().equals( seq_name ) ) {
273 if ( !n.getNodeData().isHasSequence() && n.getName().equals( seq_name ) ) {
280 // Helper method which performs the actual ortholog inference for
281 // the external node with seqname query.
282 private Phylogeny inferOrthologsHelper( final Phylogeny gene_tree, final Phylogeny species_tree, final String query )
283 throws SDIException {
284 Phylogeny assigned_tree = null;
285 List<PhylogenyNode> nodes = null;
286 final SDIR sdiunrooted = new SDIR();
287 List<PhylogenyNode> orthologs = null;
288 List<PhylogenyNode> super_orthologs = null;
289 List<PhylogenyNode> ultra_paralogs = null;
290 assigned_tree = sdiunrooted.infer( gene_tree,
292 RIO.ROOT_BY_MINIMIZING_MAPPING_COST,
293 RIO.ROOT_BY_MINIMIZING_SUM_OF_DUPS,
294 RIO.ROOT_BY_MINIMIZING_TREE_HEIGHT,
297 setExtNodesOfAnalyzedGeneTrees( assigned_tree.getNumberOfExternalNodes() );
298 nodes = getNodesViaSequenceName( assigned_tree, query );
299 if ( nodes.size() > 1 ) {
300 throw new IllegalArgumentException( "node named [" + query + "] not unique" );
302 else if ( nodes.isEmpty() ) {
303 throw new IllegalArgumentException( "no node containing a sequence named [" + query + "] found" );
305 final PhylogenyNode query_node = nodes.get( 0 );
306 orthologs = PhylogenyMethods.getOrthologousNodes( assigned_tree, query_node );
307 updateHash( _o_hash_maps, query, orthologs );
308 super_orthologs = PhylogenyMethods.getSuperOrthologousNodes( query_node );
309 updateHash( _so_hash_maps, query, super_orthologs );
310 ultra_paralogs = PhylogenyMethods.getUltraParalogousNodes( query_node );
311 updateHash( _up_hash_maps, query, ultra_paralogs );
312 return assigned_tree;
316 * Returns an ArrayList containg the names of orthologs of the PhylogenyNode
317 * with seq name seq_name.
320 * sequence name of a external node of the gene trees
321 * @param threshold_orthologs
322 * the minimal number of observations for a a sequence to be
323 * reported as orthologous as percentage (0.0-100.0%)
324 * @return ArrayList containg the names of orthologs of the PhylogenyNode
325 * with seq name seq_name
327 public ArrayList<String> inferredOrthologsToArrayList( final String seq_name, double threshold_orthologs ) {
328 HashMap<String, Integer> o_hashmap = null;
331 final ArrayList<String> arraylist = new ArrayList<String>();
332 if ( _o_hash_maps == null ) {
333 throw new RuntimeException( "Orthologs have not been calculated (successfully)." );
335 if ( threshold_orthologs < 0.0 ) {
336 threshold_orthologs = 0.0;
338 else if ( threshold_orthologs > 100.0 ) {
339 threshold_orthologs = 100.0;
341 o_hashmap = getInferredOrthologs( seq_name );
342 if ( o_hashmap == null ) {
343 throw new RuntimeException( "Orthologs for " + seq_name + " were not established." );
345 if ( _seq_names.size() > 0 ) {
346 I: for( int i = 0; i < _seq_names.size(); ++i ) {
347 name = _seq_names.get( i );
348 if ( name.equals( seq_name ) ) {
351 o = getBootstrapValueFromHash( o_hashmap, name );
352 if ( o < threshold_orthologs ) {
355 arraylist.add( name );
362 * Returns a String containg the names of orthologs of the PhylogenyNode
363 * with seq name query_name. The String also contains how many times a
364 * particular ortholog has been observed.
367 * The output order is (per line): Name, Ortholog, Subtree neighbor, Super
371 * The sort priority of this is determined by sort in the following manner:
374 * <li>1 : Ortholog, Super ortholog
375 * <li>2 : Super ortholog, Ortholog
378 * Returns "-" if no putative orthologs have been found (given
379 * threshold_orthologs).
381 * Orthologs are to be inferred by method "inferOrthologs".
383 * (Last modified: 05/08/01)
386 * sequence name of a external node of the gene trees
388 * order and sort priority
389 * @param threshold_orthologs
390 * the minimal number of observations for a a sequence to be
391 * reported as orthologous, in percents (0.0-100.0%)
392 * @param threshold_subtreeneighborings
393 * the minimal number of observations for a a sequence to be
394 * reported as orthologous, in percents (0.0-100.0%)
395 * @return String containing the inferred orthologs, String containing "-"
396 * if no orthologs have been found null in case of error
397 * @see #inferOrthologs(File,Phylogeny,String)
398 * @see #inferOrthologs(Phylogeny[],Phylogeny)
399 * @see #inferOrthologs(File,Phylogeny)
400 * @see #getOrder(int)
402 public StringBuffer inferredOrthologsToString( final String query_name, int sort, double threshold_orthologs ) {
403 HashMap<String, Integer> o_hashmap = null;
404 HashMap<String, Integer> s_hashmap = null;
406 double o = 0.0; // Orthologs.
407 double s = 0.0; // Super orthologs.
410 final ArrayList<ResultLine> nv = new ArrayList<ResultLine>();
411 if ( ( _o_hash_maps == null ) || ( _so_hash_maps == null ) ) {
412 throw new RuntimeException( "orthologs have not been calculated (successfully)" );
414 if ( ( sort < 0 ) || ( sort > 2 ) ) {
417 if ( threshold_orthologs < 0.0 ) {
418 threshold_orthologs = 0.0;
420 else if ( threshold_orthologs > 100.0 ) {
421 threshold_orthologs = 100.0;
423 o_hashmap = getInferredOrthologs( query_name );
424 s_hashmap = getInferredSuperOrthologs( query_name );
425 if ( ( o_hashmap == null ) || ( s_hashmap == null ) ) {
426 throw new RuntimeException( "Orthologs for " + query_name + " were not established" );
428 final StringBuffer orthologs = new StringBuffer();
429 if ( _seq_names.size() > 0 ) {
430 I: for( int i = 0; i < _seq_names.size(); ++i ) {
431 name = _seq_names.get( i );
432 if ( name.equals( query_name ) ) {
435 o = getBootstrapValueFromHash( o_hashmap, name );
436 if ( o < threshold_orthologs ) {
439 s = getBootstrapValueFromHash( s_hashmap, name );
442 nv.add( new ResultLine( name, o, 5 ) );
445 nv.add( new ResultLine( name, o, s, 5 ) );
448 nv.add( new ResultLine( name, s, o, 5 ) );
451 nv.add( new ResultLine( name, o, 5 ) );
453 } // End of I for loop.
454 if ( ( nv != null ) && ( nv.size() > 0 ) ) {
455 orthologs.append( "[seq name]\t\t[ortho]\t[st-n]\t[sup-o]\t[dist]" + ForesterUtil.LINE_SEPARATOR );
456 final ResultLine[] nv_array = new ResultLine[ nv.size() ];
457 for( int j = 0; j < nv.size(); ++j ) {
458 nv_array[ j ] = nv.get( j );
460 Arrays.sort( nv_array );
461 for( final ResultLine element : nv_array ) {
462 name = element.getKey();
463 value1 = element.getValue1();
464 value2 = element.getValue2();
465 orthologs.append( addNameAndValues( name, value1, value2, sort ) );
469 // No orthologs found.
470 if ( ( orthologs == null ) || ( orthologs.length() < 1 ) ) {
471 orthologs.append( "-" );
474 } // inferredOrthologsToString( String, int, double )
477 * Returns a String containg the names of orthologs of the PhylogenyNode
478 * with seq name query_name. The String also contains how many times a
479 * particular ortholog has been observed. Returns "-" if no putative
480 * orthologs have been found (given threshold_orthologs).
482 * Orthologs are to be inferred by method "inferOrthologs".
485 * sequence name of a external node of the gene trees
486 * @param return_dists
487 * @param threshold_ultra_paralogs
489 * @return String containing the inferred orthologs, String containing "-"
490 * if no orthologs have been found null in case of error
492 public String inferredUltraParalogsToString( final String query_name, double threshold_ultra_paralogs ) {
493 HashMap<String, Integer> sp_hashmap = null;
494 String name = "", ultra_paralogs = "";
499 final List<ResultLine> nv = new ArrayList<ResultLine>();
500 if ( threshold_ultra_paralogs < 1.0 ) {
501 threshold_ultra_paralogs = 1.0;
503 else if ( threshold_ultra_paralogs > 100.0 ) {
504 threshold_ultra_paralogs = 100.0;
506 if ( _up_hash_maps == null ) {
507 throw new RuntimeException( "Ultra paralogs have not been calculated (successfully)." );
509 sp_hashmap = getInferredUltraParalogs( query_name );
510 if ( sp_hashmap == null ) {
511 throw new RuntimeException( "Ultra paralogs for " + query_name + " were not established" );
513 if ( _seq_names.size() > 0 ) {
514 I: for( int i = 0; i < _seq_names.size(); ++i ) {
515 name = _seq_names.get( i );
516 if ( name.equals( query_name ) ) {
519 sp = getBootstrapValueFromHash( sp_hashmap, name );
520 if ( sp < threshold_ultra_paralogs ) {
523 nv.add( new ResultLine( name, sp, 5 ) );
524 } // End of I for loop.
525 if ( ( nv != null ) && ( nv.size() > 0 ) ) {
526 final ResultLine[] nv_array = new ResultLine[ nv.size() ];
527 for( int j = 0; j < nv.size(); ++j ) {
528 nv_array[ j ] = nv.get( j );
530 Arrays.sort( nv_array );
532 for( final ResultLine element : nv_array ) {
533 name = element.getKey();
534 value1 = element.getValue1();
535 value2 = element.getValue2();
536 ultra_paralogs += addNameAndValues( name, value1, value2, sort );
540 // No ultra paralogs found.
541 if ( ( ultra_paralogs == null ) || ( ultra_paralogs.length() < 1 ) ) {
542 ultra_paralogs = "-";
544 return ultra_paralogs;
548 * Brings this into the same state as immediately after construction.
550 private final void reset() {
552 _so_hash_maps = null;
553 _up_hash_maps = null;
559 private void setNumberOfSamples( int i ) {
563 System.out.println( "samples: " + i );
568 * Sets number of ext nodes in gene trees analyzed (after stripping).
570 * number of ext nodes in gene trees analyzed (after stripping)
572 private void setExtNodesOfAnalyzedGeneTrees( int i ) {
579 // Helper for doInferOrthologs( Phylogeny, Phylogeny, String )
580 // and doInferOrthologs( Phylogeny, Phylogeny ).
581 private void updateHash( final HashMap<String, HashMap<String, Integer>> counter_map,
582 final String query_seq_name,
583 final List<PhylogenyNode> nodes ) {
584 final HashMap<String, Integer> hash_map = counter_map.get( query_seq_name );
585 if ( hash_map == null ) {
586 throw new RuntimeException( "Unexpected failure in method updateHash." );
588 for( int j = 0; j < nodes.size(); ++j ) {
590 if ( ( nodes.get( j ) ).getNodeData().isHasSequence()
591 && !ForesterUtil.isEmpty( ( nodes.get( j ) ).getNodeData().getSequence().getName() ) ) {
592 seq_name = ( nodes.get( j ) ).getNodeData().getSequence().getName();
595 seq_name = ( nodes.get( j ) ).getName();
597 if ( hash_map.containsKey( seq_name ) ) {
598 hash_map.put( seq_name, hash_map.get( seq_name ) + 1 );
601 hash_map.put( seq_name, 1 );
606 // Helper method for inferredOrthologsToString
607 // and inferredUltraParalogsToString.
608 private final static String addNameAndValues( final String name,
612 final java.text.DecimalFormat df = new java.text.DecimalFormat( "0.#####" );
613 df.setDecimalSeparatorAlwaysShown( false );
615 if ( name.length() < 8 ) {
616 line += ( name + "\t\t\t" );
618 else if ( name.length() < 16 ) {
619 line += ( name + "\t\t" );
622 line += ( name + "\t" );
626 line += addToLine( value1, df );
630 line += addToLine( value1, df );
631 line += addToLine( value2, df );
634 line += addToLine( value2, df );
635 line += addToLine( value1, df );
638 line += addToLine( value1, df );
642 line += addToLine( value1, df );
643 line += addToLine( value2, df );
646 line += ForesterUtil.LINE_SEPARATOR;
650 // Helper for addNameAndValues.
651 private final static String addToLine( final double value, final java.text.DecimalFormat df ) {
653 if ( value != ResultLine.DEFAULT ) {
654 s = df.format( value ) + "\t";
662 private static List<String> getAllExternalSequenceNames( final Phylogeny phy ) {
663 final List<String> names = new ArrayList<String>();
664 for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) {
665 final PhylogenyNode n = iter.next();
666 if ( n.getNodeData().isHasSequence() && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
667 names.add( n.getNodeData().getSequence().getName() );
669 else if ( !ForesterUtil.isEmpty( n.getName() ) ) {
670 names.add( n.getName() );
673 throw new IllegalArgumentException( "node has no (sequence) name: " + n );
680 * Returns the order in which ortholog (o), "super ortholog" (s) and
681 * distance (d) are returned and sorted (priority of sort always goes from
682 * left to right), given sort. For the meaning of sort
684 * @see #inferredOrthologsToString(String,int,double,double)
687 * determines order and sort priority
688 * @return String indicating the order
690 public final static String getOrder( final int sort ) {
694 order = "orthologies";
697 order = "orthologies > super orthologies";
700 order = "super orthologies > orthologies";
703 order = "orthologies";
709 public final static StringBuffer getOrderHelp() {
710 final StringBuffer sb = new StringBuffer();
711 sb.append( " 0: orthologies" + ForesterUtil.LINE_SEPARATOR );
712 sb.append( " 1: orthologies > super orthologies" + ForesterUtil.LINE_SEPARATOR );
713 sb.append( " 2: super orthologies > orthologies" + ForesterUtil.LINE_SEPARATOR );
717 class ResultLine implements Comparable<ResultLine> {
719 public static final int DEFAULT = -999;
720 private final String _key;
721 private final double _value1;
722 private final double _value2;
728 _value1 = ResultLine.DEFAULT;
729 _value2 = ResultLine.DEFAULT;
732 ResultLine( final String name, final double value1, final double value2, final int c ) {
737 if ( ( c >= 0 ) && ( c <= 2 ) ) {
742 ResultLine( final String name, final double value1, final int c ) {
746 _value2 = ResultLine.DEFAULT;
753 public int compareTo( final ResultLine n ) {
754 if ( ( getValue1() != ResultLine.DEFAULT ) && ( n.getValue1() != ResultLine.DEFAULT ) ) {
755 if ( getValue1() < n.getValue1() ) {
758 if ( getValue1() > n.getValue1() ) {
762 if ( ( getValue2() != ResultLine.DEFAULT ) && ( n.getValue2() != ResultLine.DEFAULT ) ) {
763 if ( getValue2() < n.getValue2() ) {
766 if ( getValue2() > n.getValue2() ) {
770 return ( getKey().compareTo( n.getKey() ) );
785 private void setSigns() {
787 _p[ 0 ] = _p[ 1 ] = +1;