1 /*************************************************************** 2 * 3 * This program is free software; you can redistribute it and/or 4 * modify it under the terms of the GNU General Public License 5 * as published by the Free Software Foundation; either version 2 6 * of the License, or (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program; if not, write to the Free Software 15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * 17 * @author: Copyright (C) Tim Carver 18 * 19 ***************************************************************/ 20 21 package org.emboss.jemboss.draw; 22 23 import javax.swing.*; 24 import java.awt.Color; 25 import java.io.*; 26 import java.util.Vector; 27 import java.util.StringTokenizer; 28 29 /** 30 * 31 * 32 */ 33 public class EmbossCirdnaReader 34 { 35 36 /** cirdna file */ 37 private File cirdnaFile; 38 /** true if read ok */ 39 private boolean reading = false; 40 /** */ 41 private Vector restrictionEnzyme = new Vector(); 42 /** genetic markers */ 43 private Vector block = new Vector(); 44 /** emboss colour scheme for cirdna */ 45 private Color[] embossColor = { 46 Color.black, 47 Color.red, 48 Color.yellow, 49 Color.green, 50 Color.decode("#99CCFF"), //AQUAMARINE 51 Color.decode("#FFCCCC"), //pink 52 Color.decode("#FFFFCC"), //wheat 53 Color.gray, 54 Color.decode("#993300"), //brown 55 Color.blue, 56 Color.decode("#9933FF"), //blueviolet 57 Color.cyan, 58 Color.decode("#33FFCC"), //turqoise 59 Color.decode("#FF00FF"), //magenta 60 Color.decode("#FF9966"), //salmon 61 Color.white 62 }; 63 int start = 0; 64 int end = 0; 65 66 EmbossCirdnaReader()67 public EmbossCirdnaReader() 68 { 69 SecurityManager sm = System.getSecurityManager(); 70 System.setSecurityManager(null); 71 JFileChooser fc = new JFileChooser(System.getProperty("user.home")); 72 System.setSecurityManager(sm); 73 74 int returnVal = fc.showOpenDialog(fc); 75 76 if(returnVal == JFileChooser.APPROVE_OPTION) 77 { 78 cirdnaFile = fc.getSelectedFile(); 79 readFile(); 80 reading = true; 81 } 82 } 83 84 /** 85 * 86 * @param cirdnaFile cirdna file 87 * 88 */ EmbossCirdnaReader(File cirdnaFile)89 public EmbossCirdnaReader(File cirdnaFile) 90 { 91 this.cirdnaFile = cirdnaFile; 92 readFile(); 93 reading = true; 94 } 95 96 97 /** 98 * 99 * 100 */ isReading()101 public boolean isReading() 102 { 103 return reading; 104 } 105 106 /** 107 * 108 * Read a cirdna file 109 * 110 */ readFile()111 public Vector readFile() 112 { 113 BufferedReader in = null; 114 try 115 { 116 in = new BufferedReader(new FileReader(cirdnaFile)); 117 String line; 118 while((line = in.readLine()) != null ) 119 { 120 line = line.trim().toLowerCase(); 121 if(!line.equals("")) 122 { 123 StringTokenizer stok = new StringTokenizer(line," "); 124 if(line.startsWith("start ")) 125 { 126 stok.nextElement(); 127 start = Integer.parseInt((String)stok.nextElement()); 128 } 129 else if(line.startsWith("end ")) 130 { 131 stok.nextElement(); 132 end = Integer.parseInt((String)stok.nextElement()); 133 } 134 else if(line.startsWith("group")) 135 { 136 while((line = in.readLine()) != null ) 137 { 138 line = line.trim().toLowerCase(); 139 if(line.startsWith("endgroup")) 140 break; 141 else if(line.startsWith("block ")) 142 { 143 stok = new StringTokenizer(line," "); 144 Vector marker = new Vector(); 145 stok.nextElement(); 146 Integer bstart = new Integer((String)stok.nextElement()); 147 Integer bend = new Integer((String)stok.nextElement()); 148 Color col = Color.red; 149 150 if(stok.hasMoreTokens()) 151 col = embossColor[Integer.parseInt((String)stok.nextElement())]; 152 String name = in.readLine().trim(); 153 if(name.equals("endlabel")) 154 name = ""; 155 156 marker.add(name); 157 marker.add(bstart); 158 marker.add(bend); 159 marker.add(col); 160 marker.add(new Float(10.f)); 161 marker.add(new Boolean(false)); 162 marker.add(new Boolean(false)); 163 block.add(marker); 164 } 165 else if(line.startsWith("tick")) 166 { 167 stok = new StringTokenizer(line," "); 168 169 stok.nextElement(); 170 Integer pos = new Integer((String)stok.nextElement()); 171 Color col = Color.red; 172 if(stok.hasMoreTokens()) 173 col = embossColor[Integer.parseInt((String)stok.nextElement())]; 174 String name = in.readLine(); 175 if(line.equals("endlabel")) 176 name = ""; 177 178 Vector re = new Vector(); 179 re.add(name); 180 re.add(pos); 181 re.add(col); 182 restrictionEnzyme.add(re); 183 } 184 } 185 } 186 187 188 } 189 } 190 } 191 catch (IOException e) 192 { 193 System.out.println("SequenceReader Error"); 194 } 195 finally 196 { 197 if(in!=null) 198 try { 199 in.close(); 200 } catch (IOException e) { 201 // TODO Auto-generated catch block 202 e.printStackTrace(); 203 } 204 } 205 206 System.out.println("Start : "+start); 207 System.out.println("End : "+end); 208 209 return null; 210 } 211 212 getRestrictionEnzyme()213 protected Vector getRestrictionEnzyme() 214 { 215 return restrictionEnzyme; 216 } 217 218 getBlock()219 protected Vector getBlock() 220 { 221 return block; 222 } 223 getStart()224 protected int getStart() 225 { 226 return start; 227 } 228 getEnd()229 protected int getEnd() 230 { 231 return end; 232 } 233 234 } 235 236