Public feed #893278

Someone

public java v1 · immutable
Raw Edit
·published 2008-02-06 00:37 UTC
rendered paste body
/* * AntigenSource.java * * Created on November 11, 2007, 10:19 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package aisim;import org.apache.xerces.utils.Base64;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.StringTokenizer;import java.util.logging.Level;import java.util.logging.Logger;/** * * @author saraiva */public class AntigenSource {    private static BufferedReader antigenSource;    /**     * Creates a new instance of AntigenSource     */    public AntigenSource() {    }    private static String obtainNewAntigen(boolean testingMode) {        String aux = null;        try {            if ((!testingMode && Configuration.isTrainingSTDIN()) || (testingMode && Configuration.isTestingSTDIN())) {                aux = readFromStdin();            } else {                aux = AntigenSource.antigenSource.readLine();            }        } catch (Exception ex) {            ex.printStackTrace();        }        return aux;    ///////////////////////ALTERADO/////////////////////////////////////////////////////    ///////////////////////ALTERADO/////////////////////////////////////////////////////     }    private static void antigenSource(boolean testingMode) {        try {            if (testingMode) {                if (!Configuration.isTestingSTDIN()) {                    AntigenSource.antigenSource = new BufferedReader(new FileReader(Configuration.getTestingFileData()));                }            } else {                if (!Configuration.isTrainingSTDIN()) {                    AntigenSource.antigenSource = new BufferedReader(new FileReader(Configuration.getTrainingFileData()));                }            }            AntigenSource.processAntigenSource(testingMode);        } catch (Exception ex) {            ex.printStackTrace();        ///////////////////////ALTERADO/////////////////////////////////////////////////////        ///////////////////////ALTERADO/////////////////////////////////////////////////////         } finally {            try {                if (antigenSource != null) {                    antigenSource.close();                }            } catch (IOException ex) {                Logger.getLogger(AntigenSource.class.getName()).log(Level.SEVERE, null, ex);            }        }    }    private static void processAntigenSource(boolean testingMode) {        int iterationAPC = 0;        APC antigenPresentingCell = new APC();        String aux;        while ((aux = AntigenSource.obtainNewAntigen(testingMode)) != null) {            if ((Configuration.isTestingSTDIN() || Configuration.isTrainingSTDIN()) && aux.equals(Configuration.getToken())) {                break;            }            AntigenSource.processAntigen(aux, antigenPresentingCell);            iterationAPC++;            antigenPresentingCell.processAPC(testingMode, iterationAPC);            antigenPresentingCell = new APC();        }        antigenPresentingCell = null;    }    private static void processAntigen(String antigenPart, APC antigenPresentingCell) {        StringTokenizer peptides = new StringTokenizer(antigenPart, Configuration.getToken());        String pep = null;        antigenPresentingCell.setMETA_INFO(peptides.nextToken());        try {            while (peptides.hasMoreTokens()) {                pep = peptides.nextToken();                if (Configuration.isBase64()) {                    //byte[] decoded = Base64.decode(pep);                    byte[] decoded = Base64.decode(pep.getBytes());                    pep = new String(decoded, "ISO-8859-1");                }                antigenPresentingCell.updateAPC(pep);            }            peptides = null;        } catch (Exception e) {        }    }    protected static void antigenSourceTraining() {        AntigenSource.antigenSource(false);    }    protected static void antigenSourceTesting() {        AntigenSource.antigenSource(true);    }    private static String readFromStdin() {        try {            java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));            String line = stdin.readLine();            return line;        } catch (java.io.IOException e) {            System.out.println(e);        } catch (NumberFormatException e) {            System.out.println(e);        }        return null;    }}