--- /dev/null
+package jalview.datamodel;
+
+public class DynamicData
+{
+
+ private String fieldTitle;
+
+ private String fieldValue;
+
+ private DataType dataType;
+
+ private String source;
+
+ private Boolean display;
+
+ public enum DataType
+ {
+ N("Number"), S("String"), B("Boolean");
+
+ private String name;
+
+ DataType(String name)
+ {
+ this.setName(name);
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+ }
+
+ public DynamicData(String fieldTitle, String fieldValue,
+ DataType dataType, String source, Boolean display)
+ {
+ this.fieldTitle = fieldTitle;
+ this.fieldValue = fieldValue;
+ this.dataType = dataType;
+ this.source = source;
+ this.display = display;
+ }
+
+ public String getFieldTitle()
+ {
+ return fieldTitle;
+ }
+
+ public void setFieldTitle(String fieldTitle)
+ {
+ this.fieldTitle = fieldTitle;
+ }
+
+ public String getSource()
+ {
+ return source;
+ }
+
+ public void setSource(String source)
+ {
+ this.source = source;
+ }
+
+ public DataType getDataType()
+ {
+ return dataType;
+ }
+
+ public void setDataType(DataType dataType)
+ {
+ this.dataType = dataType;
+ }
+
+ public String getFieldValue()
+ {
+ return fieldValue;
+ }
+
+ public void setFieldValue(String fieldValue)
+ {
+ this.fieldValue = fieldValue;
+ }
+
+ public Boolean isDisplay()
+ {
+ return display;
+ }
+
+ public void setDisplay(Boolean display)
+ {
+ this.display = display;
+ }
+}
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.DynamicData;
+import jalview.datamodel.DynamicData.DataType;
import jalview.datamodel.GraphLine;
import jalview.datamodel.HiddenSequences;
import jalview.datamodel.PDBEntry;
PDBEntry phyre2PDBEntry = new PDBEntry(modelName, " ",
Type.PDB,
structureModelFile);
- String phyre2ModelDesc = generatePhyre2InfoHTMLTable(
+ List<DynamicData> phyreDD = generatePhyreDynamicDataList(
structModelHeader, structModelData);
- phyre2PDBEntry.setProperty("PHYRE2_MODEL_INFO", phyre2ModelDesc);
+ phyre2PDBEntry.setProperty("DYNAMIC_DATA_PHYRE2", phyreDD);
templateSeq.getDatasetSequence().addPDBId(phyre2PDBEntry);
if (querySequence != null)
{
return added;
}
- static String generatePhyre2InfoHTMLTable(String[] structModelHeader,
- String[] structModelData)
+ static List<DynamicData> generatePhyreDynamicDataList(
+ String[] headerArray,
+ String[] dataArray)
{
- StringBuilder phyre2InfoBuilder = new StringBuilder();
- if (isGenerateStructInfoHtml(structModelHeader, structModelData))
+
+ if (headerArray == null || dataArray == null)
{
- phyre2InfoBuilder.append("<html><table border=\"1\" width=100%>")
- .append("<tr><td colspan=\"2\"><strong>Phyre2 Template Info</strong></td></tr>");
- for (int x = 4; x < structModelData.length; x++)
- {
- phyre2InfoBuilder.append("<tr><td>").append(structModelHeader[x])
- .append("</td><td>").append(structModelData[x])
- .append("</td></tr>");
- }
- phyre2InfoBuilder.append("</table></html>");
+ throw new IllegalArgumentException(
+ "Header or data arrays must not be null");
}
- return phyre2InfoBuilder.toString();
- }
- static boolean isGenerateStructInfoHtml(String[] header, String[] data)
- {
- boolean generate = true;
- if (header == null || data == null)
+ if (headerArray.length != dataArray.length)
{
- return false;
+ throw new IllegalArgumentException(
+ "Header and data arrays must be of same lenght");
}
- if (header.length < 3 || data.length < 3)
+ List<DynamicData> dynamicDataList = new ArrayList<DynamicData>();
+ int x = 0;
+ for (String data : dataArray)
{
- generate = false;
+ // first four column should be hidden;
+ boolean show = (x > 4);
+ dynamicDataList.add(new DynamicData(headerArray[x], data, DataType.S,
+ "PHYRE2", show));
+ x++;
}
- return generate;
+ return dynamicDataList;
}
static String resolveAbsolutePath(String relURI, String _baseUri)
--- /dev/null
+package jalview.io;
+
+import jalview.analysis.AAFrequency;
+import jalview.analysis.Conservation;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.ProfilesI;
+import jalview.datamodel.SequenceI;
+
+public class AnnotationUtil
+{
+
+ public static AlignmentAnnotation getConsensusAnnotationFromFile(
+ String file)
+ {
+ AlignmentI alignment = readAlignmentFile(file);
+ // AlignFrame af = new AlignFrame(alignment, 5, 5);
+ // af.setVisible(false);
+ // AlignmentAnnotation consensus = af.getViewport()
+ // .getAlignmentConsensusAnnotation();
+ // af.dispose();
+ // System.out.println(consensus);
+
+ SequenceI[] alignmentSeqs = alignment.getSequencesArray();
+ int width = alignment.getWidth();
+ long nseq = alignmentSeqs.length;
+ boolean ignoreGapsConsensus = true;
+ boolean showSequenceLogo = false;
+
+ AlignmentAnnotation consensusAnnotation = new AlignmentAnnotation(
+ "Consensus",
+ "PID", new Annotation[1], 0f, 100f,
+ AlignmentAnnotation.BAR_GRAPH);
+ consensusAnnotation.hasText = true;
+ consensusAnnotation.autoCalculated = true;
+
+ alignment.addAnnotation(consensusAnnotation);
+ ProfilesI hconsensus = AAFrequency.calculate(alignmentSeqs, width, 0,
+ width,
+ true);
+
+ AAFrequency.completeConsensus(consensusAnnotation, hconsensus,
+ hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1,
+ ignoreGapsConsensus, showSequenceLogo, nseq);
+
+ System.out.println(">>>>> Consensus Annotation : "
+ + consensusAnnotation);
+ return consensusAnnotation;
+ }
+
+ public static AlignmentAnnotation getConservationAnnotationFromFile(
+ String file, SequenceI seqRef)
+ {
+ AlignmentAnnotation conservationAnnotation = null;
+ int foundAnnotCount = seqRef.getAnnotation().length;
+ if (seqRef != null && foundAnnotCount < 3)
+ {
+ AlignmentI alignment = readAlignmentFile("/Users/tcnofoegbu/Desktop/query.jal");
+ // AlignmentI alignment = readAlignmentFile(file);
+ // ColumnSelection cs = new ColumnSelection();
+ // SequenceI querySeq = alignment.getSequenceAt(0);
+ // cs.hideInsertionsFor(querySeq);
+ // AlignViewport av = new AlignViewport(alignment);
+ // av.setColumnSelection(cs);
+ //
+ // alignment = av.getAlignment();
+ int alWidth = alignment.getWidth();
+ int ConsPercGaps = 25;
+
+ AlignmentAnnotation quality = new AlignmentAnnotation("Quality",
+ "Alignment Quality based on Blosum62 scores",
+ new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
+ quality.hasText = true;
+ quality.autoCalculated = true;
+
+ conservationAnnotation = new AlignmentAnnotation("Conservation",
+ "PID", new Annotation[1], 0f, 100f,
+ AlignmentAnnotation.BAR_GRAPH);
+ conservationAnnotation.hasText = true;
+ conservationAnnotation.autoCalculated = true;
+ alignment.addAnnotation(conservationAnnotation);
+ Conservation cons = Conservation.calculateConservation("All",
+ alignment.getSequences(), 0, alWidth - 1, false,
+ ConsPercGaps, quality != null);
+ cons.completeAnnotations(conservationAnnotation, quality, 0, alWidth);
+ System.out.println(">>>");
+
+ conservationAnnotation.createSequenceMapping(seqRef, 1, true);
+ seqRef.addAlignmentAnnotation(conservationAnnotation);
+
+ // conservationAnnotation.createSequenceMapping(
+ // seqRef.getDatasetSequence(), 1, true);
+ // seqRef.getDatasetSequence().addAlignmentAnnotation(
+ // conservationAnnotation);
+ }
+
+ return conservationAnnotation;
+ }
+
+ private static AlignmentI readAlignmentFile(String f)
+ {
+ System.out.println("Reading file: " + f);
+ try
+ {
+ FormatAdapter rf = new FormatAdapter();
+ DataSourceType protocol = AppletFormatAdapter.checkProtocol(f);
+ AlignmentI al = rf.readFile(f, protocol,
+ new IdentifyFile().identify(f, protocol));
+ return al;
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static void main(String[] args)
+ {
+ // getConservationAnnotationFromFile("http://www.sbg.bio.ic.ac.uk/phyre2/phyre2_output/cd1b897af035cdf5/query.jal");
+ getConsensusAnnotationFromFile("http://www.sbg.bio.ic.ac.uk/phyre2/phyre2_output/cd1b897af035cdf5/query.jal");
+ }
+
+}
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.DBRefSource;
+import jalview.datamodel.DynamicData;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
}
}
sb.append("</i>");
+ List<PDBEntry> pdbEntries = ds.getAllPDBEntries();
+ sb.append(getToolTipTextFromPDBEntries(pdbEntries));
+ return maxWidth;
+ }
- for (PDBEntry pdb : ds.getAllPDBEntries())
+ private String getToolTipTextFromPDBEntries(List<PDBEntry> pdbEntries)
+ {
+ String tooltip = "";
+ if (pdbEntries.isEmpty())
{
- if (pdb != null && pdb.getProperty("PHYRE2_MODEL_INFO") != null)
+ return tooltip;
+ }
+ if (pdbEntries.size() > 1)
+ {
+ int x = 0;
+ PDBEntry bestRanked = null;
+ for (PDBEntry pdb : pdbEntries)
{
- sb.append(pdb.getProperty("PHYRE2_MODEL_INFO"));
+ if (pdb.getProperty("DYNAMIC_DATA_PHYRE2") != null)
+ {
+ x++;
+ }
+ // best ranked entry must be from a Phyre
+ if (x > 0 && bestRanked == null)
+ {
+ bestRanked = pdb;
+ }
}
+ tooltip = (x > 0) ? "<table border=\"1\" width=100%><tr><td>Contains <b>"
+ + x
+ + "</b> Phyre2 model structure(s)</td></tr>"
+ + "<tr><td>Best ranked Phyre2 model is <b>"
+ + bestRanked.getId() + "</b></td></tr></table>"
+ : "";
}
- return maxWidth;
+ else
+ {
+ PDBEntry pdb = pdbEntries.iterator().next();
+ if (pdb.getProperty("DYNAMIC_DATA_PHYRE2") != null)
+ {
+ tooltip = getPhyreToolTipFromDynamicData((List<DynamicData>) pdb
+ .getProperty("DYNAMIC_DATA_PHYRE2"));
+ }
+ }
+ return tooltip;
+ }
+
+ private String getPhyreToolTipFromDynamicData(
+ List<DynamicData> dynamicDataList)
+ {
+ StringBuilder phyre2InfoBuilder = new StringBuilder();
+ phyre2InfoBuilder
+ .append("<html><table border=\"1\" width=100%>")
+ .append("<tr><td colspan=\"2\"><strong>Phyre2 Template Info</strong></td></tr>");
+ for (DynamicData data : dynamicDataList)
+ {
+ if (data.isDisplay())
+ {
+ phyre2InfoBuilder.append("<tr><td>").append(data.getFieldTitle())
+ .append("</td><td>").append(data.getFieldValue())
+ .append("</td></tr>");
+ }
+ }
+ phyre2InfoBuilder.append("</table></html>");
+ return phyre2InfoBuilder.toString();
}
public void createTooltipAnnotationReport(final StringBuilder tip,
import jalview.datamodel.AlignmentI;
import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.DynamicData;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.PDBEntry.Type;
import jalview.datamodel.SequenceI;
-import jalview.gui.Desktop;
import jalview.gui.JvOptionPane;
import jalview.io.AnnotationFile.ViewDef;
import jalview.structure.StructureSelectionManager;
import java.io.File;
import java.util.Hashtable;
+import java.util.List;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
@BeforeClass(alwaysRun = true)
void testProcessStructModel()
{
+ try
+ {
+
+ ssm = StructureSelectionManager.getStructureSelectionManager();
+ } catch (NullPointerException e)
+ {
+ ssm = new StructureSelectionManager();
+ }
File alignmentFile = new File(
"examples/testdata/phyre2results/56da5616b4559c93/allhits.fasta");
String annotationFile = "examples/testdata/phyre2results/56da5616b4559c93/allhits.ann";
boolean annotationRead = new AnnotationFile().readAnnotationFile(al,
cs, annotationFile, DataSourceType.FILE);
Assert.assertTrue(annotationRead);
- ssm = StructureSelectionManager
- .getStructureSelectionManager(Desktop.instance);
System.out.println("bla");
}
PDBEntry expectedPDBEntry = new PDBEntry(pdbId, " ", Type.PDB, baseDir
+ pdbId);
- String phyre2ModelDesc = AnnotationFile.generatePhyre2InfoHTMLTable(structModelHeader,
- structModelData);
- expectedPDBEntry.setProperty("PHYRE2_MODEL_INFO", phyre2ModelDesc);
+ List<DynamicData> phyreDD = AnnotationFile
+ .generatePhyreDynamicDataList(structModelHeader,
+ structModelData);
+ expectedPDBEntry.setProperty("DYNAMIC_DATA_PHYRE2", phyreDD);
+
Assert.assertEquals(actualPDBEntry, expectedPDBEntry);
}
expectedPhyre2FastaMappingFile);
}
- @Test(
- groups = { "Functional" },
- dataProvider = "phyre2InfoHTMLTableDataProvider")
- void testGeneratePhyre2InfoHTMLTable(String caseDescription,
- String[] header, String[] data, String expectedHtml)
- {
- System.out.println(">>>> Testing Case - " + caseDescription);
- String actualHtmlGenerated = AnnotationFile
- .generatePhyre2InfoHTMLTable(header, data);
- System.out.println("-----> " + actualHtmlGenerated);
- Assert.assertEquals(actualHtmlGenerated, expectedHtml);
- }
-
- @Test(
- groups = { "Functional" },
- dataProvider = "StructModelHtmlDataProvider")
- void testIsGenerateStructInfoHtml(String caseDescription,
- String[] header, String[] data, boolean expectedOutcome)
- {
- System.out.println(">>>> Testing Case - " + caseDescription);
- boolean actual = AnnotationFile.isGenerateStructInfoHtml(header, data);
- Assert.assertEquals(actual, expectedOutcome);
- }
-
@Test(groups = { "Functional" }, dataProvider = "FilePathProvider")
void testResolveAbsolutePath(String caseDescription, String suppliedPath,
String baseURI, String expectedURI)