1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
| public class TestWb {
public static void main (String [] args) {
////////////Attributs////////////
String inputline;
String html = "";
String url = "http://weblogo.threeplusone.com/create.cgi";
try {
//////////////Permettre de lire le fichier en string pour les paramètres//////////////
File file = new File("/home/poo/Téléchargements/INSULINE.aln-fa");
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
StringBuffer sb = new StringBuffer();
String line;
while((line = br.readLine()) != null)
{
// ajoute la ligne au buffer
sb.append(line);
sb.append("\n");
}
fr.close();
System.out.println(sb.toString());
//////////////Connexion à l'URL//////////////
URL logo = new URL(url);
// Ouvrir la connexion
URLConnection co = logo.openConnection();
co.setDoOutput(true);
// Permettre de régler les paramètres du site
PrintStream o = new PrintStream(co.getOutputStream());
// Paramètre permettant de mettre les uploads des séquences
o.print("sequences=" + sb);
o.print("&");
// Paramètre permettant de mettre le titre du logo
o.print("logo_title=" + "SEQUENCES LOGO");
o.print("&");
// Paramètre permettant le choix de sortie de l'image (PNG, JPEG, EPS, PDF, SVG)
o.print("format=" + "png");
o.print("&");
// Paramètre permettant de chosir le type de séquences (protéiques ou nucléiques). Choisir "auto" pour que les séquences soient reconnu automatiquement
o.print("alphabet=" + "alphabet_auto");
o.print("&");
// Paramètre permettant de choisir la taille du logo. Choisir entre "small", "medium" et "large"
o.print("stack_width=" + "medium");
o.print("&");
// Paramètre permettant
o.print("stacks_per_line=" + "40");
o.print("&");
// Paramètre permettant de voir ou non les cases en minuscules. Choisir "off"
o.print("ignore_lower_case=" + "off");
o.print("&");
// Paramètre permettant de choisir le type d'unité. Choisir "bits"
o.print("unit_name=" + "bits");
o.print("&");
// Paramètre permettant de chosir le position du premier nombre
o.print("first_index=" + "1");
o.print("&");
// Paramètre permettant de choisir le commencement et fin du logo
o.print("logo_start=" + "");
o.print("&");
o.print("logo_end=" + "");
o.print("&");
// Paramètre Figure Label
o.print("logo_label=" + "");
o.print("&");
// Paramètre permettant de mettre à l'échelle les largeurs de pile
o.print("scale_width=" + "on");
o.print("&");
// Paramètre permettant de chosir la compôsition. Choisir "auto"
o.print("composition=" + "comp_auto");
o.print("&");
// Paramètre permettant d'activer les barres d'erreur. Choisir "on"
o.print("show_errorbars=" + "on");
o.print("&");
// Paramètre permettant d'afficher les étiquettes de fin de séquence. Choisir "off"
o.print("show_ends=" + "off");
o.print("&");
// Paramètre permettant d'activer une version avec des petis caractères
o.print("show_fineprint=" + "on");
o.print("&");
// Paramètre permettant de régler xaxis et yaxis.
o.print("show_xaxis=" + "on");
o.print("&");
o.print("xaxis_label=" + "auto");
o.print("&");
o.print("show_yaxis=" + "on");
o.print("&");
o.print("yaxis_label=" + "auto");
o.print("&");
o.print("yaxis_scale=" + "auto");
o.print("&");
o.print("yaxis_tic_interval" + "1.0");
o.print("&");
// Paramètre permettant de choisir la couleur du schéma
o.print("color_scheme=" + "color_auto");
o.print("&");
// Paramètre color key
o.print("show_color_key=" + "on");
o.print("&");
// Paramètre permettant d'ajuster la couleur des symboles
o.print("symbols0=" + "");
o.print("&");
o.print("color0=" + "");
o.print("&");
o.print("symbols1=" + "");
o.print("&");
o.print("color1=" + "");
o.print("&");
o.print("symbols2=" + "");
o.print("&");
o.print("color2=" + "");
o.print("&");
o.print("symbols3=" + "");
o.print("&");
o.print("color3=" + "");
o.print("&");
o.print("symbols4=" + "");
o.print("&");
o.print("color4=" + "");
o.print("&");
// Paramètre permettant de créer le logo
o.print("cmd_create=" + "Create WebLogo");
o.close();
// Lire du texte à partir d'un flux d'entrée de caractères
BufferedReader i = new BufferedReader(
new InputStreamReader(
co.getInputStream(),"UTF-8"));
// Lecture ligne par ligne
while((inputline = i.readLine())!=null){
// concaténation + retour à la ligne (\n)
html += inputline+"\n";
}
// Lire types primitifs
DataInputStream in = new DataInputStream(co.getInputStream());
// Récupèrer la valeur du paramètre désigné sous forme dobjet URL
url = (co.getURL()).toString();
in.close();
System.out.println(html);
////////////Récupération image et stockage////////////
URL imageURL = new URL (url);
//RenderedImage img = ImageIO.read(imageURL);
//Image img = ImageIO.read(imageURL);
/*byte[] bytes = html.getBytes();
System.out.println("Text [Byte Format] : " + bytes);
ByteArrayOutputStream output = new ByteArrayOutputStream();
InputStream inputStream = co.getInputStream();
int n = 0;
bytes = new byte[1024];
while (-1 != (n = inputStream.read(bytes))) {
output.write(bytes, 0, n);
}
System.out.println("Text [Byte Format] : " + bytes);*/
int width = 400, height = 300;////////
// Create a `BufferedImage` and create the its `Graphics`
BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration()
.createCompatibleImage(width, height);
Graphics graphics = image.createGraphics();
// Create an `JEditorPane` and invoke `print(Graphics)`
JEditorPane jep = new JEditorPane("text/html", html);
jep.setSize(width, height);
jep.print(graphics);
// Output the `BufferedImage` via `ImageIO`
ImageIO.write( image, "png", new File("/home/poo/Image.png"));
/*RenderedImage bImage = ImageIO.read(bytes);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(bImage, "jpg", bos );
byte [] data = bos.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream();
BufferedImage bImage2 = ImageIO.read(bis);
ImageIO.write(bImage2, "png", new File("/home/poo/output.png") );
System.out.println("image created");*/
////////////Création de JFrame////////////
JFrame frame = new JFrame("SEQUENCES LOGO");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
//URL de l'image
String lienFichier = "/home/poo/Image.png";
ImageIcon icone = new ImageIcon(lienFichier);
//Création de JLable avec un alignement gauche
JLabel jlabel = new JLabel(icone, JLabel.CENTER);
jlabel.setSize(400, 320);
BufferedImage img = new BufferedImage(
jlabel.getWidth(), jlabel.getHeight(),
BufferedImage.TYPE_INT_ARGB);
{
// paint the html to an image
Graphics g = img.getGraphics();
g.setColor(Color.BLACK);
jlabel.paint(g);
g.dispose();
}
// get the byte array of the image
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "png", baos);
byte[] bytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
BufferedImage bIsmage = ImageIO.read(bais);
ImageIO.write(bIsmage, "png", new File("/home/poo/output.png") );
System.out.println("image created");
//ajouter les deux JLabel a JFrame
frame.getContentPane().add(jlabel, BorderLayout.CENTER);
frame.validate();
} catch (MalformedURLException e1) {
e1.printStackTrace(); // Gère les exceptions et les erreurs
} catch (IOException e2) {
e2.printStackTrace(); // Gère les exceptions et les erreurs
} catch (Exception e3) {
e3.printStackTrace(); // Gère les exceptions et les erreurs
}
}
} |