// java -Xmx2048m -cp
// ~/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester/java/forester.jar
-// org.forester.application.decorator2
+// org.forester.application.decoratorX
// RRMa_ALL_plus_RRMa_ee3_50_hmmalign_05_40_fme_with_seqs_2.phylo.xml
// nature12311-s3_cz_4.txt x
final PhyloXmlParser xml_parser = new PhyloXmlParser();
final Phylogeny phy = factory.create( intree, xml_parser )[ 0 ];
final BasicTable<String> t = BasicTableParser.parse( intable, '\t' );
- System.out.println( t.toString() );
- final PhylogenyNodeIterator it = phy.iteratorPostorder();
+ // System.out.println( t.toString() );
+ final PhylogenyNodeIterator it = phy.iteratorExternalForward();
int i = 0;
while ( it.hasNext() ) {
final PhylogenyNode node = it.next();
- if ( node.isExternal() ) {
- processNode( node, t );
- }
+ processNode( node, t );
i++;
}
+ final PhylogenyNodeIterator it2 = phy.iteratorExternalForward();
+ while ( it2.hasNext() ) {
+ final PhylogenyNode node = it2.next();
+ processNode2( node, phy );
+ }
final PhylogenyWriter writer = new PhylogenyWriter();
writer.toPhyloXML( outtree, phy, 0 );
}
}
}
- private static void processNode( final PhylogenyNode node, BasicTable<String> t ) throws Exception {
- String node_seq = node.getNodeData().getSequence().getMolecularSequence().toUpperCase();
+ private static void processNode( final PhylogenyNode node, final BasicTable<String> t ) throws Exception {
+ final String node_seq = node.getNodeData().getSequence().getMolecularSequence().toUpperCase();
boolean found = false;
for( int col = 0; col < t.getNumberOfRows(); ++col ) {
- String table_seq = t.getValueAsString( SEQ_COLUMN, col ).toUpperCase();
+ final String table_seq = t.getValueAsString( SEQ_COLUMN, col ).toUpperCase();
if ( table_seq.contains( node_seq ) ) {
if ( found ) {
- throw new Exception( "Sequence from node " + node + " is not unique: " + node_seq );
+ // throw new Exception( "Sequence from node " + node + " is not unique: " + node_seq );
}
found = true;
- Annotation annotation = new Annotation( "target:" + t.getValueAsString( TARGET_COLUMN, col ) );
+ final Annotation annotation = new Annotation( "target", t.getValueAsString( TARGET_COLUMN, col ) );
node.getNodeData().getSequence().addAnnotation( annotation );
System.out.println( node + "->" + annotation );
}
// throw new Exception( "Sequence from node " + node + " not found: " + node_seq );
// }
}
+
+ private static void processNode2( final PhylogenyNode node, final Phylogeny t ) {
+ if ( ( node.getNodeData().getSequence().getAnnotations() == null )
+ || node.getNodeData().getSequence().getAnnotations().isEmpty() ) {
+ t.deleteSubtree( node, true );
+ }
+ }
}
import java.net.URL;
import java.net.URLEncoder;
import java.text.ParseException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
+import java.util.SortedMap;
import java.util.SortedSet;
+import java.util.TreeMap;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
import org.forester.phylogeny.PhylogenyNode;
import org.forester.phylogeny.data.Accession;
+import org.forester.phylogeny.data.Annotation;
import org.forester.phylogeny.data.BranchColor;
import org.forester.phylogeny.data.Taxonomy;
import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
public final class AptxUtil {
+ private final static String[] AVAILABLE_FONT_FAMILIES_SORTED = GraphicsEnvironment.getLocalGraphicsEnvironment()
+ .getAvailableFontFamilyNames();
private final static Pattern seq_identifier_pattern_1 = Pattern
.compile( "^([A-Za-z]{2,5})[|=:]([0-9A-Za-z_\\.]{5,40})\\s*$" );
private final static Pattern seq_identifier_pattern_2 = Pattern
.compile( "^([A-Za-z]{2,5})[|=:]([0-9A-Za-z_\\.]{5,40})[|,; ].*$" );
- private final static String[] AVAILABLE_FONT_FAMILIES_SORTED = GraphicsEnvironment.getLocalGraphicsEnvironment()
- .getAvailableFontFamilyNames();
static {
Arrays.sort( AVAILABLE_FONT_FAMILIES_SORTED );
}
+ public static MaskFormatter createMaskFormatter( final String s ) {
+ MaskFormatter formatter = null;
+ try {
+ formatter = new MaskFormatter( s );
+ }
+ catch ( final ParseException e ) {
+ throw new IllegalArgumentException( e );
+ }
+ return formatter;
+ }
+
public final static String createUriForSeqWeb( final PhylogenyNode node,
final Configuration conf,
final TreePanel tp ) {
return uri_str;
}
- public static MaskFormatter createMaskFormatter( final String s ) {
- MaskFormatter formatter = null;
- try {
- formatter = new MaskFormatter( s );
- }
- catch ( final ParseException e ) {
- throw new IllegalArgumentException( e );
- }
- return formatter;
- }
-
final static public boolean isHasAtLeastNodeWithEvent( final Phylogeny phy ) {
final PhylogenyNodeIterator it = phy.iteratorPostorder();
while ( it.hasNext() ) {
lookAtSomeTreePropertiesForAptxControlSettings( phy, main_panel.getControlPanel(), configuration );
}
- final static Color calculateColorFromString( final String str ) {
- final String species_uc = str.toUpperCase();
- char first = species_uc.charAt( 0 );
+ final static Color calculateColorFromString( final String str, final boolean is_taxonomy ) {
+ final String my_str = str.toUpperCase();
+ char first = my_str.charAt( 0 );
char second = ' ';
char third = ' ';
- if ( species_uc.length() > 1 ) {
- second = species_uc.charAt( 1 );
- if ( species_uc.length() > 2 ) {
- if ( species_uc.indexOf( " " ) > 0 ) {
- third = species_uc.charAt( species_uc.indexOf( " " ) + 1 );
- }
- else {
- third = species_uc.charAt( 2 );
+ if ( my_str.length() > 1 ) {
+ if ( is_taxonomy ) {
+ second = my_str.charAt( 1 );
+ }
+ else {
+ second = my_str.charAt( my_str.length() - 1 );
+ }
+ if ( is_taxonomy ) {
+ if ( my_str.length() > 2 ) {
+ if ( my_str.indexOf( " " ) > 0 ) {
+ third = my_str.charAt( my_str.indexOf( " " ) + 1 );
+ }
+ else {
+ third = my_str.charAt( 2 );
+ }
}
}
+ else if ( my_str.length() > 2 ) {
+ third = ( char ) ( Math.abs( str.hashCode() / 16909320 ) );
+ System.out.println( str.hashCode() );
+ }
}
first = AptxUtil.normalizeCharForRGB( first );
second = AptxUtil.normalizeCharForRGB( second );
- third = AptxUtil.normalizeCharForRGB( third );
+ if ( is_taxonomy ) {
+ third = AptxUtil.normalizeCharForRGB( third );
+ }
+ else {
+ third = third > 255 ? 255 : third;
+ }
if ( ( first > 235 ) && ( second > 235 ) && ( third > 235 ) ) {
first = 0;
}
return colorizations;
}
+ final static String createAnnotationString( final SortedSet<Annotation> annotations ) {
+ final SortedMap<String, List<Annotation>> m = new TreeMap<String, List<Annotation>>();
+ for( final Annotation an : annotations ) {
+ final String ref_source = ForesterUtil.isEmpty( an.getRefSource() ) ? "?" : an.getRefSource();
+ if ( !m.containsKey( ref_source ) ) {
+ m.put( ref_source, new ArrayList<Annotation>() );
+ }
+ m.get( ref_source ).add( an );
+ }
+ final StringBuilder sb = new StringBuilder();
+ for( final Entry<String, List<Annotation>> e : m.entrySet() ) {
+ final String ref_source = e.getKey();
+ final List<Annotation> ans = e.getValue();
+ if ( m.size() > 1 ) {
+ sb.append( "[" );
+ }
+ if ( !ref_source.equals( "?" ) ) {
+ sb.append( ref_source );
+ sb.append( ": " );
+ }
+ for( int i = 0; i < ans.size(); ++i ) {
+ final Annotation an = ans.get( i );
+ if ( !ForesterUtil.isEmpty( an.getRefValue() ) ) {
+ sb.append( an.getRefValue() );
+ sb.append( " " );
+ }
+ if ( !ForesterUtil.isEmpty( an.getDesc() ) ) {
+ sb.append( an.getDesc() );
+ }
+ if ( sb.charAt( sb.length() - 1 ) == ' ' ) {
+ sb.deleteCharAt( sb.length() - 1 );
+ }
+ if ( i < ans.size() - 1 ) {
+ sb.append( ", " );
+ }
+ }
+ if ( m.size() > 1 ) {
+ sb.append( "] " );
+ }
+ }
+ return sb.toString();
+ }
+
final static String createBasicInformation( final Phylogeny phy ) {
final StringBuilder desc = new StringBuilder();
if ( ( phy != null ) && !phy.isEmpty() ) {
// br.close();
// }
public static enum GraphicsExportType {
- GIF( "gif" ), JPG( "jpg" ), PDF( "pdf" ), PNG( "png" ), TIFF( "tif" ), BMP( "bmp" );
+ BMP( "bmp" ), GIF( "gif" ), JPG( "jpg" ), PDF( "pdf" ), PNG( "png" ), TIFF( "tif" );
private final String _suffix;
if ( getControlPanel().isShowAnnotation()
&& ( node.getNodeData().getSequence().getAnnotations() != null )
&& !node.getNodeData().getSequence().getAnnotations().isEmpty() ) {
- sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAnnotation( 0 )
- .asSimpleText()
+ sum += getTreeFontSet()._fm_large.stringWidth( AptxUtil.createAnnotationString( node.getNodeData()
+ .getSequence().getAnnotations() )
+ " " );
}
if ( getControlPanel().isShowDomainArchitectures()
}
if ( c == null ) {
if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
- c = AptxUtil.calculateColorFromString( tax.getTaxonomyCode() );
+ c = AptxUtil.calculateColorFromString( tax.getTaxonomyCode(), true );
getControlPanel().getSpeciesColors().put( tax.getTaxonomyCode(), c );
}
else {
- c = AptxUtil.calculateColorFromString( tax.getScientificName() );
+ c = AptxUtil.calculateColorFromString( tax.getScientificName(), true );
getControlPanel().getSpeciesColors().put( tax.getScientificName(), c );
}
}
if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
final StringBuilder sb = new StringBuilder();
for( final Annotation a : ann ) {
- sb.append( !ForesterUtil.isEmpty( a.getRef() ) ? a.getRef() : a.getDesc() );
+ sb.append( !ForesterUtil.isEmpty( a.getRefValue() ) ? a.getRefValue() : a.getDesc() );
}
final String ann_str = sb.toString();
if ( !ForesterUtil.isEmpty( ann_str ) ) {
c = getControlPanel().getAnnotationColors().get( ann_str );
if ( c == null ) {
- c = AptxUtil.calculateColorFromString( ann_str );
+ c = AptxUtil.calculateColorFromString( ann_str, false );
getControlPanel().getAnnotationColors().put( ann_str, c );
}
if ( c == null ) {
repaint();
}
- private String createAnnotationString( final SortedSet<Annotation> ann ) {
- final StringBuilder sb = new StringBuilder();
- boolean first = true;
- for( final Annotation a : ann ) {
- if ( !first ) {
- sb.append( "+" );
- }
- else {
- first = false;
- }
- sb.append( a.asSimpleText() );
- }
- final String ann_str = sb.toString();
- return ann_str;
- }
-
final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
final String tax = PhylogenyMethods.getSpecies( node );
String label = node.getName();
else if ( getControlPanel().isColorAccordingToAnnotation() ) {
g.setColor( calculateColorForAnnotation( ann ) );
}
- final String ann_str = createAnnotationString( ann );
+ final String ann_str = AptxUtil.createAnnotationString( ann );
TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + half_box_size, node.getYcoord()
+ ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
_sb.setLength( 0 );
public class Annotation implements PhylogenyData, MultipleUris, Comparable<Annotation> {
+ private Confidence _confidence;
private String _desc;
- private String _type;
- private String _source;
- private final String _ref;
private String _evidence;
- private Confidence _confidence;
private PropertiesMap _properties;
+ private final String _ref_source;
+ private final String _ref_value;
+ private String _source;
+ private String _type;
private List<Uri> _uris;
+ public Annotation() {
+ _ref_value = "";
+ _ref_source = "";
+ init();
+ }
+
public Annotation( final String ref ) {
if ( ForesterUtil.isEmpty( ref ) ) {
throw new IllegalArgumentException( "annotation reference is empty or null" );
}
- if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ref.length() - 2 ) || ( ref.length() < 3 ) ) {
+ final String s[] = ref.split( ":" );
+ if ( ( s.length != 2 ) || ForesterUtil.isEmpty( s[ 0 ] ) || ForesterUtil.isEmpty( s[ 1 ] ) ) {
throw new IllegalArgumentException( "illegal format for annotation reference: [" + ref + "]" );
}
- _ref = ref;
+ _ref_source = s[ 0 ];
+ _ref_value = s[ 1 ];
init();
}
- public Annotation() {
- _ref = "";
+ public Annotation( final String ref_source, final String ref_value ) {
+ if ( ForesterUtil.isEmpty( ref_source ) || ForesterUtil.isEmpty( ref_value ) ) {
+ throw new IllegalArgumentException( "illegal format for annotation reference" );
+ }
+ _ref_source = ref_source;
+ _ref_value = ref_value;
init();
}
@Override
+ public void addUri( final Uri uri ) {
+ if ( getUris() == null ) {
+ setUris( new ArrayList<Uri>() );
+ }
+ getUris().add( uri );
+ }
+
+ @Override
public StringBuffer asSimpleText() {
return new StringBuffer( !ForesterUtil.isEmpty( getRef() ) ? getRef() : getDesc() );
}
}
@Override
+ public int compareTo( final Annotation o ) {
+ if ( equals( o ) ) {
+ return 0;
+ }
+ if ( getRef().equals( o.getRef() ) ) {
+ return getDesc().compareTo( o.getDesc() );
+ }
+ return getRef().compareTo( o.getRef() );
+ }
+
+ @Override
public PhylogenyData copy() {
- final Annotation ann = new Annotation( new String( getRef() ) );
+ final Annotation ann = new Annotation( getRefSource(), getRefValue() );
if ( getConfidence() != null ) {
ann.setConfidence( ( Confidence ) getConfidence().copy() );
}
else {
ann.setConfidence( null );
}
- ann.setType( new String( getType() ) );
- ann.setDesc( new String( getDesc() ) );
- ann.setEvidence( new String( getEvidence() ) );
+ ann.setType( getType() );
+ ann.setDesc( getDesc() );
+ ann.setEvidence( getEvidence() );
ann.setSource( new String( getSource() ) );
if ( getProperties() != null ) {
ann.setProperties( ( PropertiesMap ) getProperties().copy() );
return ann;
}
+ @Override
+ public boolean equals( final Object o ) {
+ if ( this == o ) {
+ return true;
+ }
+ else if ( o == null ) {
+ return false;
+ }
+ else if ( o.getClass() != this.getClass() ) {
+ throw new IllegalArgumentException( "attempt to check [" + this.getClass() + "] equality to " + o + " ["
+ + o.getClass() + "]" );
+ }
+ else {
+ return isEqual( ( Annotation ) o );
+ }
+ }
+
public Confidence getConfidence() {
return _confidence;
}
}
public String getRef() {
- return _ref;
+ if ( ForesterUtil.isEmpty( _ref_source ) ) {
+ return "";
+ }
+ final StringBuilder sb = new StringBuilder();
+ sb.append( _ref_source );
+ sb.append( ':' );
+ sb.append( _ref_value );
+ return sb.toString();
+ }
+
+ public final String getRefSource() {
+ return _ref_source;
+ }
+
+ public final String getRefValue() {
+ return _ref_value;
}
public String getSource() {
return _type;
}
- private void init() {
- _desc = "";
- _type = "";
- _source = "";
- _evidence = "";
- _confidence = null;
- _properties = null;
- setUris( null );
+ @Override
+ public Uri getUri( final int index ) {
+ return getUris().get( index );
+ }
+
+ @Override
+ public List<Uri> getUris() {
+ return _uris;
}
@Override
}
@Override
+ public void setUris( final List<Uri> uris ) {
+ _uris = uris;
+ }
+
+ @Override
public StringBuffer toNHX() {
throw new UnsupportedOperationException();
}
return asText().toString();
}
- @Override
- public void addUri( final Uri uri ) {
- if ( getUris() == null ) {
- setUris( new ArrayList<Uri>() );
- }
- getUris().add( uri );
- }
-
- @Override
- public Uri getUri( final int index ) {
- return getUris().get( index );
- }
-
- @Override
- public List<Uri> getUris() {
- return _uris;
- }
-
- @Override
- public void setUris( final List<Uri> uris ) {
- _uris = uris;
- }
-
- @Override
- public boolean equals( final Object o ) {
- if ( this == o ) {
- return true;
- }
- else if ( o == null ) {
- return false;
- }
- else if ( o.getClass() != this.getClass() ) {
- throw new IllegalArgumentException( "attempt to check [" + this.getClass() + "] equality to " + o + " ["
- + o.getClass() + "]" );
- }
- else {
- return isEqual( ( Annotation ) o );
- }
- }
-
- @Override
- public int compareTo( final Annotation o ) {
- if ( equals( o ) ) {
- return 0;
- }
- if ( getRef().equals( o.getRef() ) ) {
- return getDesc().compareTo( o.getDesc() );
- }
- return getRef().compareTo( o.getRef() );
+ private void init() {
+ _desc = "";
+ _type = "";
+ _source = "";
+ _evidence = "";
+ _confidence = null;
+ _properties = null;
+ setUris( null );
}
}
if ( !node.getNodeData().isHasSequence() ) {
node.getNodeData().setSequence( new Sequence() );
}
- final Annotation annotation = new Annotation( "?" );
+ final Annotation annotation = new Annotation();
annotation.setDesc( new_value );
node.getNodeData().getSequence().addAnnotation( annotation );
break;