Debian Codegraph @

api_examples/CgviewTest3.java

raw symbols SCIP
1 import ca.ualberta.stothard.cgview.*;
2 import java.io.*;
3 import java.awt.*;
4
5 public class CgviewTest3 implements CgviewConstants {
6
7 public static void main( String args[] ) {
8
9 int length = 9000;
10 Cgview cgview = new Cgview(length);
11
12 //some optional settings
13 cgview.setWidth(750);
14 cgview.setHeight(750);
15 cgview.setBackboneRadius(150.0f);
16 cgview.setBackboneColor(Color.blue);
17 cgview.setTitle("Example");
18 cgview.setLabelPlacementQuality(5);
19 cgview.setShowWarning(true);
20 cgview.setLabelLineThickness(1.5f);
21 cgview.setRulerTextPadding(6.0f);
22
23 Legend legend = new Legend(cgview);
24 legend.setPosition(LEGEND_UPPER_CENTER);
25 LegendItem legendItem = new LegendItem(legend);
26 legendItem.setLabel("Point to labels to view mouseover information.");
27 legendItem.setFont(new Font("SansSerif", Font.PLAIN, 20));
28 legendItem.setTextAlignment(LEGEND_ITEM_ALIGN_CENTER);
29
30 legendItem = new LegendItem(legend);
31 legendItem.setLabel("Click on labels to test hyperlinks.");
32 legendItem.setFont(new Font("SansSerif", Font.PLAIN, 20));
33 legendItem.setTextAlignment(LEGEND_ITEM_ALIGN_CENTER);
34
35 //create a FeatureSlot to hold sequence features
36 FeatureSlot featureSlot = new FeatureSlot(cgview, DIRECT_STRAND);
37
38 //create random sequence features
39 for (int i = 1; i <= 50; i = i + 1) {
40
41 int j = Math.round((float)((float)(length - 2) * Math.random())) + 1;
42
43 //a Feature to add to our FeatureSlot
44 Feature feature = new Feature(featureSlot, "label");
45 feature.setColor(Color.gray);
46
47 //a single FeatureRange to add the Feature
48 FeatureRange featureRange = new FeatureRange (feature, j, j + 1);
49 featureRange.setDecoration(DECORATION_CLOCKWISE_ARROW);
50 //add a link and mouseover. Normally you would use a link to a specific
51 //gene or protein
52 featureRange.setHyperlink("http://www.ncbi.nlm.nih.gov/entrez/query.fcgi");
53 featureRange.setMouseover("Start = " + j + ", stop = " + (j + 1));
54
55 }
56
57 try {
58 //create a PNG map.
59 CgviewIO.writeToPNGFile(cgview, "mouseover_links.png");
60 //for PNG and JPG files the mouseover and link information
61 //must be placed in an image map. To generate the image map,
62 //use the CgviewIO.writeHTMLFile() method after the image
63 //has been written to file.
64
65 //the overLIB javascript library (http://www.bosrup.com/web/overlib/)
66 //can be used for displaying mouseovers. You will need to make overlib.js
67 //available to the html file by placing overlib.js inside an 'includes'
68 //directory
69 boolean useOverlib = true;
70 CgviewIO.writeHTMLFile(cgview, "mouseover_links.png", "png", "mouseover_links.html", useOverlib);
71
72 //create an SVG file. The mouseover and links are included in the SVG.
73 boolean embedFonts = true;
74 boolean useCompression = false;
75
76 //The previous call to writeToPNGFile generated and positioned
77 //the feature labels in a non-overlapping arrangement.
78 //Label positioning can be slow. Supplying usePreviousDrawnLabels
79 //set to true tells CgviewIO to use the previously arranged labels
80 //instead of generating and positioning new labels.
81 boolean usePreviouslyDrawnLabels = true;
82 CgviewIO.writeToSVGFile(cgview,
83 "mouseover_links.svg",
84 embedFonts,
85 useCompression,
86 usePreviouslyDrawnLabels);
87
88 }
89 catch (Exception e) {
90 e.printStackTrace(System.err);
91 System.exit(1);
92 }
93 }
94 }