Example usage for java.io DataInputStream readUTF

List of usage examples for java.io DataInputStream readUTF

Introduction

In this page you can find the example usage for java.io DataInputStream readUTF.

Prototype

public final String readUTF() throws IOException 

Source Link

Document

See the general contract of the readUTF method of DataInput.

Usage

From source file:org.apache.giraph.master.BspServiceMaster.java

/**
 * Read the finalized checkpoint file and associated metadata files for the
 * checkpoint.  Modifies the {@link PartitionOwner} objects to get the
 * checkpoint prefixes.  It is an optimization to prevent all workers from
 * searching all the files.  Also read in the aggregator data from the
 * finalized checkpoint file and setting it.
 *
 * @param superstep Checkpoint set to examine.
 * @throws IOException// w ww.jav  a  2  s  .  c  o  m
 * @throws InterruptedException
 * @throws KeeperException
 * @return Collection of generated partition owners.
 */
private Collection<PartitionOwner> prepareCheckpointRestart(long superstep)
        throws IOException, KeeperException, InterruptedException {
    List<PartitionOwner> partitionOwners = new ArrayList<>();
    FileSystem fs = getFs();
    String finalizedCheckpointPath = getSavedCheckpointBasePath(superstep)
            + CheckpointingUtils.CHECKPOINT_FINALIZED_POSTFIX;
    LOG.info("Loading checkpoint from " + finalizedCheckpointPath);
    DataInputStream finalizedStream = fs.open(new Path(finalizedCheckpointPath));
    GlobalStats globalStats = new GlobalStats();
    globalStats.readFields(finalizedStream);
    updateCounters(globalStats);
    SuperstepClasses superstepClasses = SuperstepClasses.createToRead(getConfiguration());
    superstepClasses.readFields(finalizedStream);
    getConfiguration().updateSuperstepClasses(superstepClasses);
    int prefixFileCount = finalizedStream.readInt();

    String checkpointFile = finalizedStream.readUTF();
    for (int i = 0; i < prefixFileCount; ++i) {
        int mrTaskId = finalizedStream.readInt();

        DataInputStream metadataStream = fs.open(
                new Path(checkpointFile + "." + mrTaskId + CheckpointingUtils.CHECKPOINT_METADATA_POSTFIX));
        long partitions = metadataStream.readInt();
        WorkerInfo worker = getWorkerInfoById(mrTaskId);
        for (long p = 0; p < partitions; ++p) {
            int partitionId = metadataStream.readInt();
            PartitionOwner partitionOwner = new BasicPartitionOwner(partitionId, worker);
            partitionOwners.add(partitionOwner);
            LOG.info("prepareCheckpointRestart partitionId=" + partitionId + " assigned to " + partitionOwner);
        }
        metadataStream.close();
    }
    //Ordering appears to be important as of right now we rely on this ordering
    //in WorkerGraphPartitioner
    Collections.sort(partitionOwners, new Comparator<PartitionOwner>() {
        @Override
        public int compare(PartitionOwner p1, PartitionOwner p2) {
            return Integer.compare(p1.getPartitionId(), p2.getPartitionId());
        }
    });

    globalCommHandler.getAggregatorHandler().readFields(finalizedStream);
    aggregatorTranslation.readFields(finalizedStream);
    masterCompute.readFields(finalizedStream);
    finalizedStream.close();

    return partitionOwners;
}

From source file:org.spout.engine.filesystem.WorldFiles.java

public static void readColumn(InputStream in, SpoutColumn column, AtomicInteger lowestY,
        BlockMaterial[][] topmostBlocks) {
    if (in == null) {
        //The inputstream is null because no height map data exists
        for (int x = 0; x < SpoutColumn.BLOCKS.SIZE; x++) {
            for (int z = 0; z < SpoutColumn.BLOCKS.SIZE; z++) {
                column.getAtomicInteger(x, z).set(Integer.MIN_VALUE);
                topmostBlocks[x][z] = null;
                column.setDirty(x, z);//  w  ww  .j  a  va2 s.c om
            }
        }
        lowestY.set(Integer.MAX_VALUE);
        return;
    }

    DataInputStream dataStream = new DataInputStream(in);
    try {
        for (int x = 0; x < SpoutColumn.BLOCKS.SIZE; x++) {
            for (int z = 0; z < SpoutColumn.BLOCKS.SIZE; z++) {
                column.getAtomicInteger(x, z).set(dataStream.readInt());
            }
        }
        @SuppressWarnings("unused")
        int version = dataStream.readInt();

        lowestY.set(dataStream.readInt());

        //Save heightmap
        StringMap global = ((SpoutEngine) Spout.getEngine()).getEngineItemMap();
        StringMap itemMap = column.getWorld().getItemMap();
        boolean warning = false;
        for (int x = 0; x < SpoutColumn.BLOCKS.SIZE; x++) {
            for (int z = 0; z < SpoutColumn.BLOCKS.SIZE; z++) {
                if (!dataStream.readBoolean()) {
                    continue;
                }
                int blockState = dataStream.readInt();
                short blockId = BlockFullState.getId(blockState);
                short blockData = BlockFullState.getData(blockState);
                blockId = (short) itemMap.convertTo(global, blockId);
                blockState = BlockFullState.getPacked(blockId, blockData);
                BlockMaterial m;
                try {
                    m = (BlockMaterial) MaterialRegistry.get(blockState);
                } catch (ClassCastException e) {
                    m = null;
                    if (!warning) {
                        Spout.getLogger().severe(
                                "Error reading column topmost block information, block was not a valid BlockMaterial");
                        warning = false;
                    }
                }
                if (m == null) {
                    column.setDirty(x, z);
                }
                topmostBlocks[x][z] = m;
            }
        }

        //Save Biomes
        BiomeManager manager = null;
        try {
            //Biome manager is serialized with:
            // - boolean, if a biome manager exists
            // - String, the class name
            // - int, the number of bytes of data to read
            // - byte[], size of the above int in length
            boolean exists = dataStream.readBoolean();
            if (exists) {
                String biomeManagerClass = dataStream.readUTF();
                int biomeSize = dataStream.readInt();
                byte[] biomes = new byte[biomeSize];
                dataStream.readFully(biomes);

                //Attempt to create the biome manager class from the class name
                @SuppressWarnings("unchecked")
                Class<? extends BiomeManager> clazz = (Class<? extends BiomeManager>) Class
                        .forName(biomeManagerClass);
                Class<?>[] params = { int.class, int.class };
                manager = clazz.getConstructor(params).newInstance(column.getX(), column.getZ());
                manager.deserialize(biomes);
                column.setBiomeManager(manager);
            }
        } catch (Exception e) {
            Spout.getLogger().log(Level.SEVERE, "Failed to read biome data for column", e);
        }

    } catch (IOException e) {
        Spout.getLogger()
                .severe("Error reading column height-map for column" + column.getX() + ", " + column.getZ());
    }
}

From source file:org.hyperic.hq.agent.server.AgentDListProvider.java

/**
 * DList info string is a series of properties seperated by '|'
 * Three properties are expected./*w  ww .  j ava  2  s.  com*/
 *
 * Directory to place the data files
 * Size in MB to start checking for unused blocks
 * Maximum percentage of free blocks allowed
 *
 * Default is 'data|20|50'
 */
public void init(String info) throws AgentStorageException {
    BufferedInputStream bIs;
    FileInputStream fIs = null;
    DataInputStream dIs;
    long nEnts;

    // Parse out configuration
    StringTokenizer st = new StringTokenizer(info, "|");
    if (st.countTokens() != 5) {
        throw new AgentStorageException(info + " is an invalid agent storage provider configuration");
    }

    keyVals = new HashMap<EncVal, EncVal>();
    lists = new HashMap<String, DiskList>();
    overloads = new HashMap<String, ListInfo>();
    String dir = st.nextToken();
    this.writeDir = new File(dir);
    this.keyValFile = new File(writeDir, "keyvals");
    this.keyValFileBackup = new File(writeDir, "keyvals.backup");

    String s = st.nextToken().trim();
    long factor;
    if ("m".equalsIgnoreCase(s)) {
        factor = 1024 * 1024;
    } else if ("k".equalsIgnoreCase(s)) {
        factor = 1024;
    } else {
        throw new AgentStorageException(info + " is an invalid agent storage provider configuration");
    }
    try {
        maxSize = Long.parseLong(st.nextToken().trim()) * factor;
        chkSize = Long.parseLong(st.nextToken().trim()) * factor;
        chkPerc = Integer.parseInt(st.nextToken().trim());
    } catch (NumberFormatException e) {
        throw new AgentStorageException("Invalid agent storage provider " + "configuration: " + e);
    }

    if (this.writeDir.exists() == false) {
        // Try to create it
        this.writeDir.mkdir();
    }

    if (this.writeDir.isDirectory() == false) {
        throw new AgentStorageException(dir + " is not a directory");
    }

    try {
        fIs = new FileInputStream(this.keyValFile);
        bIs = new BufferedInputStream(fIs);
        dIs = new DataInputStream(bIs);
        nEnts = dIs.readLong();
        while (nEnts-- != 0) {
            String encKey = dIs.readUTF();
            String encVal = dIs.readUTF();
            String key = SecurityUtil.isMarkedEncrypted(encKey)
                    ? SecurityUtil.decryptRecursiveUnmark(encryptor, encKey)
                    : encKey;
            String val = SecurityUtil.isMarkedEncrypted(encVal)
                    ? SecurityUtil.decryptRecursiveUnmark(encryptor, encVal)
                    : encVal;
            this.keyVals.put(new EncVal(encryptor, key, encKey), new EncVal(encryptor, val, encVal));
        }
    } catch (FileNotFoundException exc) {
        // Normal when it doesn't exist
        log.debug("file not found (this is ok): " + exc);
    } catch (IOException exc) {
        log.error("Error reading " + this.keyValFile + " loading " + "last known good version");
        // Close old stream
        close(fIs);
        // Fall back to last known good keyvals file
        try {
            fIs = new FileInputStream(this.keyValFileBackup);
            bIs = new BufferedInputStream(fIs);
            dIs = new DataInputStream(bIs);
            nEnts = dIs.readLong();
            while (nEnts-- != 0) {
                String encKey = dIs.readUTF();
                String encVal = dIs.readUTF();
                String key = SecurityUtil.encrypt(this.encryptor, encKey);
                String val = SecurityUtil.encrypt(this.encryptor, encVal);
                this.keyVals.put(new EncVal(encryptor, key, encKey), new EncVal(encryptor, val, encVal));
            }
        } catch (FileNotFoundException e) {
            log.warn(e);
            log.debug(e, e);
        } catch (IOException e) {
            AgentStorageException toThrow = new AgentStorageException(
                    "Error reading " + this.keyValFile + ": " + e);
            toThrow.initCause(e);
            throw toThrow;
        }
    } finally {
        close(fIs);
    }
}

From source file:com.android.launcher2.Launcher.java

private static void readConfiguration(Context context, LocaleConfiguration configuration) {
    DataInputStream in = null;
    try {/*from   w  w  w.  j  a  v  a 2  s . c o  m*/
        in = new DataInputStream(context.openFileInput(PREFERENCES));
        configuration.locale = in.readUTF();
        configuration.mcc = in.readInt();
        configuration.mnc = in.readInt();
    } catch (FileNotFoundException e) {
        // Ignore
    } catch (IOException e) {
        // Ignore
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // Ignore
            }
        }
    }
}

From source file:org.alfresco.repo.search.impl.lucene.index.IndexInfo.java

/**
 * Get the deletions for a given index (there is no check if they should be applied that is up to the calling layer)
 * /*from  w w  w .  j a  v a  2  s .  c  o  m*/
 * @param id String
 * @param fileName String
 * @return Set<String>
 * @throws IOException
 */
private Set<String> getDeletions(String id, String fileName) throws IOException {
    if (id == null) {
        throw new IndexerException("\"null\" is not a valid identifier for a transaction");
    }
    // Check state
    Set<String> deletions = new HashSet<String>();
    File location = new File(indexDirectory, id).getCanonicalFile();
    File file = new File(location, fileName).getCanonicalFile();
    if (!file.exists()) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No deletions for " + id);
        }
        return Collections.<String>emptySet();
    }
    DataInputStream is = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
    int size = is.readInt();
    for (int i = 0; i < size; i++) {
        String ref = is.readUTF();
        deletions.add(ref);
    }
    is.close();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("There are " + deletions.size() + " deletions for " + id);
    }
    return deletions;

}

From source file:com.ocpsoft.pretty.faces.config.annotation.ByteCodeAnnotationFilter.java

/**
 * <p>//from   w  w w .  ja  v a2 s.co  m
 * Checks whether that supplied {@link InputStream} contains a Java class
 * file that might contain PrettyFaces annotations.
 * </p>
 * <p>
 * The caller of this method is responsible to close the supplied
 * {@link InputStream}. This method won't do it!
 * </p>
 * 
 * @param classFileStream
 *           The stream to read the class file from.
 * @return <code>true</code> for files that should be further checked for
 *         annotations
 * @throws IOException
 *            for any kind of IO problem
 */
@SuppressWarnings("unused")
public boolean accept(InputStream classFileStream) throws IOException {

    // open a DataInputStream
    DataInputStream in = new DataInputStream(classFileStream);

    // read magic and abort if it doesn't match
    int magic = in.readInt();
    if (magic != CLASS_FILE_MAGIC) {
        if (log.isDebugEnabled()) {
            log.debug("Magic not found! Not a valid class file!");
        }
        return false;
    }

    // check for at least JDK 1.5
    int minor = in.readUnsignedShort();
    int major = in.readUnsignedShort();
    if (major < 49) {
        // JDK 1.4 or less
        if (log.isTraceEnabled()) {
            log.trace("Not a JDK5 class! It cannot contain annotations!");
        }
        return false;
    }

    // this values is equal to the number entries in the constants pool + 1
    int constantPoolEntries = in.readUnsignedShort() - 1;

    // loop over all entries in the constants pool
    for (int i = 0; i < constantPoolEntries; i++) {

        // the tag to identify the record type
        int tag = in.readUnsignedByte();

        // process record according to its type
        switch (tag) {

        case CONSTANT_Class:
            /*
             * CONSTANT_Class_info { 
             *   u1 tag; 
             *   u2 name_index; 
             * }
             */
            in.readUnsignedShort();
            break;

        case CONSTANT_Fieldref:
        case CONSTANT_Methodref:
        case CONSTANT_InterfaceMethodref:
            /*
             * CONSTANT_[Fieldref|Methodref|InterfaceMethodref]_info { 
             *   u1 tag; 
             *   u2 class_index; 
             *   u2 name_and_type_index; 
             * }
             */
            in.readUnsignedShort();
            in.readUnsignedShort();
            break;

        case CONSTANT_String:
            /*
             * CONSTANT_String_info { 
             *   u1 tag; 
             *   u2 string_index; 
             * }
             */
            in.readUnsignedShort();
            break;

        case CONSTANT_Integer:
        case CONSTANT_Float:
            /*
             * CONSTANT_[Integer|Float]_info { 
             *   u1 tag; 
             *   u4 bytes; 
             * }
             */
            in.readInt();
            break;

        case CONSTANT_Long:
        case CONSTANT_Double:

            /*
             * CONSTANT_Long_info { 
             *   u1 tag; 
             *   u4 high_bytes; 
             *   u4 low_bytes; 
             * }
             */
            in.readLong();

            /*
             * We must increase the constant pool index because this tag
             * type takes two entries
             */
            i++;

            break;

        case CONSTANT_NameAndType:
            /*
             * CONSTANT_NameAndType_info { 
             *   u1 tag; 
             *   u2 name_index; 
             *   u2 descriptor_index; 
             * }
             */
            in.readUnsignedShort();
            in.readUnsignedShort();
            break;

        case CONSTANT_Utf8:
            /*
             * CONSTANT_Utf8_info { 
             *   u1 tag; 
             *   u2 length; 
             *   u1 bytes[length]; 
             * }
             */
            String str = in.readUTF();

            // check if this string sounds interesting
            if (str.contains(SEARCH_STRING)) {
                if (log.isTraceEnabled()) {
                    log.trace("Found PrettyFaces annotation reference in constant pool: " + str);
                }
                return true;
            }
            break;

        default:
            /*
             * Unknown tag! Should not happen! We will scan the class in this case.
             */
            if (log.isDebugEnabled()) {
                log.debug("Unknown constant pool tag found: " + tag);
            }
            return true;
        }
    }

    /*
     * We are finished with reading the interesting parts of the class file.
     * We stop here because the file doesn't seem to be interesting.
     */
    if (log.isTraceEnabled()) {
        log.trace("No reference to PrettyFaces annotations found!");
    }
    return false;

}

From source file:UnicodeUtil.java

private static void loadCompositions(ClassLoader loader) {

    DataInputStream in = null;
    try {//w  w w. j a  v  a 2 s.  co m
        InputStream source = loader.getResourceAsStream("nu/xom/compositions.dat");
        in = new DataInputStream(source);
        // ???? would it make sense to store a serialized HashMap instead????
        compositions = new HashMap();
        try {
            while (true) {
                String composed = in.readUTF();
                String decomposed = in.readUTF();
                compositions.put(decomposed, composed);
            }
        } catch (java.io.EOFException ex) {
            // finished
        }
    } catch (IOException ex) {
        return;
    } finally {
        try {
            if (in != null)
                in.close();
        } catch (IOException ex) {
            // no big deal
        }
    }

}

From source file:org.nd4j.linalg.factory.Nd4j.java

/**
 * Read in an ndarray from a data input stream
 *
 * @param dis the data input stream to read from
 * @return the ndarray//from  w w  w  .j ava2  s .  c o  m
 * @throws IOException
 */
public static IComplexNDArray readComplex(DataInputStream dis) throws IOException {
    int dimensions = dis.readInt();
    int[] shape = new int[dimensions];
    int[] stride = new int[dimensions];

    for (int i = 0; i < dimensions; i++)
        shape[i] = dis.readInt();
    for (int i = 0; i < dimensions; i++)
        stride[i] = dis.readInt();
    String dataType = dis.readUTF();

    String type = dis.readUTF();

    if (!type.equals("complex"))
        throw new IllegalArgumentException("Trying to read in a real ndarray");

    if (dataType.equals("double")) {
        double[] data = ArrayUtil.readDouble(ArrayUtil.prod(shape), dis);
        return createComplex(data, shape, stride, 0);
    }

    double[] data = ArrayUtil.read(ArrayUtil.prod(shape), dis);
    return createComplex(data, shape, stride, 0);
}

From source file:MiGA.StatsSelection.java

public void getCompoundPerfectSSRs(String[] organisms, int length, boolean flag, int gap)
        throws SQLException, ClassNotFoundException, FileNotFoundException, IOException {
    String statsfile = "";
    for (int i = 0; i < organisms.length; i++) {
        boolean found = false;
        String buffer = new String();
        int seekstart = 0;
        int seekend = 0;
        List<String> ssrs = new ArrayList<String>();
        // 18/11/2013 added starting here
        String filetype = "";
        String filepro = "";

        if (flag) {
            filetype = "organisms";
            filepro = "organisms/" + organisms[i] + "/data/";
            int ret = getOrganismStatus(organisms[i]);
            if (ret == -1)
                indexer = new Indexer(chromosomelist);
            else//from   w ww  .j  a  v  a 2 s  . com
                indexer = new Indexer(ret);

        } else {
            filetype = "local";
            filepro = "local/" + organisms[i] + "/data/";
            String indexfile = "local/" + organisms[i] + "/index.txt";
            indexer = new Indexer(indexfile);
        }
        //List<String> files = getFiles(organisms[i], minlen, flag);

        // 18/11/2013 added ending here

        PrintWriter stats = null;
        PrintWriter html = null;

        PrintWriter out;
        DataOutputStream lt = null;
        if (filetype.contains("organism")) {

            File f = new File("organisms/" + organisms[i] + "/stats/");
            if (!f.exists()) {
                f.mkdir();
            }

            stats = new PrintWriter(
                    new FileWriter("organisms/" + organisms[i] + "/stats/" + "summary_statistics"
                            + now.toString().replace(':', '_').replace(' ', '_') + ".txt", true));
            lt = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("organisms/" + organisms[i]
                    + "/data/" + now.toString().replace(':', '_').replace(' ', '_') + ".compp")));
            html = new PrintWriter(new FileWriter("organisms/" + organisms[i] + "/stats/" + "summary_statistics"
                    + now.toString().replace(':', '_').replace(' ', '_') + ".html", true));

            File fi = new File("organisms/" + organisms[i] + "/results/");
            if (!fi.exists()) {
                fi.mkdir();
            }
            String toopen = "organisms/" + organisms[i] + "/results/allCompPerfect_"
                    + now.toString().replace(':', '_').replace(' ', '_') + ".txt";
            statsfile = toopen;
            out = new PrintWriter(toopen);
            out.println("Results for organism: " + organisms[i]
                    + "\t Search Parameters --> Maximum Inter-repeat Region for Perfect Compound SSRs (bp) : "
                    + gap + " - minimum SSR length (bp): " + length);
        } else {
            File f = new File("local/" + organisms[i] + "/stats/");
            if (!f.exists()) {
                f.mkdir();
            }

            stats = new PrintWriter(new FileWriter("local/" + organisms[i] + "/stats/" + "summary_statistics"
                    + now.toString().replace(':', '_').replace(' ', '_') + ".txt", true));
            lt = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("local/" + organisms[i]
                    + "/data/" + now.toString().replace(':', '_').replace(' ', '_') + ".compp")));
            html = new PrintWriter(new FileWriter("local/" + organisms[i] + "/stats/" + "summary_statistics"
                    + now.toString().replace(':', '_').replace(' ', '_') + ".html", true));

            File fi = new File("local/" + organisms[i] + "/results/");
            if (!fi.exists()) {
                fi.mkdir();
            }
            String toopen = "local/" + organisms[i] + "/results/allCompPerfect_"
                    + now.toString().replace(':', '_').replace(' ', '_') + ".txt";
            statsfile = toopen;
            out = new PrintWriter(toopen);
            out.println("Results for project: " + organisms[i]
                    + "\t Search Parameters --> Maximum Inter-repeat Region for Perfect Compound SSRs (bp) : "
                    + gap + " - minimum SSR length (bp): " + length);
        }

        int countpc = 0;
        int bpcount = 0, Aperc = 0, Tperc = 0, Gperc = 0, Cperc = 0;

        while (indexer.hasNext()) {
            String files = filepro + indexer.getNextFileName();
            DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(files)));

            boolean eof = false;
            while (!eof) {
                try {
                    SSR = new ArrayList<String>();
                    repeats = new ArrayList<Integer>();
                    EndOfSsr = new ArrayList<Integer>();
                    start = new ArrayList<Integer>();

                    int len = in.readInt();
                    int line = in.readInt();
                    for (int k = 0; k < len; k++) {
                        String temp = in.readUTF();
                        if (!temp.contains("N")) {
                            SSR.add(temp);
                            EndOfSsr.add(in.readInt());
                            repeats.add(in.readInt());
                            int st = EndOfSsr.get(k) - (SSR.get(k).length() * repeats.get(k));
                            if (st >= 0)
                                start.add(st);
                            else
                                start.add(0);
                        } else {
                            int junk = in.readInt();
                            junk = in.readInt();
                        }

                        /*
                        int real_end = end+(line-1)*20000;
                                
                        int start = real_end - (ssr.length()*reps);
                                
                        //SSR.add(ssr);
                        repeats.add(in.readInt());
                        EndOfSsr.add(real_end);
                        this.start.add(start);
                         * 
                         */
                    }

                    List<String> SSRlen = new ArrayList<String>();
                    List<Integer> Endlen = new ArrayList<Integer>();
                    List<Integer> repslen = new ArrayList<Integer>();
                    List<Integer> startlen = new ArrayList<Integer>();

                    for (int k = 0; k < SSR.size(); k++) {
                        if (SSR.get(k).length() * repeats.get(k) >= length) {
                            SSRlen.add(SSR.get(k));
                            Endlen.add(EndOfSsr.get(k));
                            repslen.add(repeats.get(k));
                            startlen.add(start.get(k));
                        }
                    }

                    List<Integer> sortedstart = new ArrayList<Integer>();

                    List<Integer> sortedend = new ArrayList<Integer>();
                    for (int t = 0; t < startlen.size(); t++) {
                        sortedstart.add(startlen.get(t));
                        sortedend.add(Endlen.get(t));
                    }

                    Collections.sort(sortedstart);
                    Collections.sort(sortedend);

                    for (int k = 0; k < sortedstart.size() - 2; k++) {
                        found = false;

                        ssrs = new ArrayList<String>();
                        if (sortedstart.get(k + 1) - sortedend.get(k) <= gap
                                && sortedstart.get(k + 1) - sortedend.get(k) >= 0) {
                            seekstart = sortedstart.get(k);
                            while (k < sortedstart.size() - 1
                                    && sortedstart.get(k + 1) - sortedend.get(k) <= gap
                                    && sortedstart.get(k + 1) - sortedend.get(k) >= 0) {
                                for (int c = 0; c < startlen.size(); c++) {
                                    if (sortedstart.get(k) == startlen.get(c)) {
                                        ssrs.add(SSRlen.get(c));
                                    }
                                    if (sortedstart.get(k + 1) == startlen.get(c)) {
                                        ssrs.add(SSRlen.get(c));
                                        seekend = Endlen.get(c);
                                        found = true;
                                    }
                                }
                                k++;
                            }
                            k--;
                        }
                        boolean check = checkalldiff(ssrs);
                        if (found && check) {
                            BufferedReader stdin = null;
                            String newdir = "";
                            if (flag) {
                                String[] temp = files.split("/");

                                boolean type = CheckForKaryotype(organisms[i]);
                                newdir = "";
                                if (type) {
                                    newdir = temp[0] + "/" + temp[1] + "/chrom-"
                                            + temp[3].substring(0, temp[3].lastIndexOf('.')) + "-slices.txt";
                                } else {
                                    newdir = temp[0] + "/" + temp[1] + "/slice-"
                                            + temp[3].substring(0, temp[3].lastIndexOf('.')) + ".txt";
                                }
                                stdin = new BufferedReader(new FileReader(newdir));

                            } else {
                                String[] temp = files.split("data/");
                                newdir = temp[0] + "/" + temp[1].substring(0, temp[1].lastIndexOf('.'))
                                        + ".txt";
                                stdin = new BufferedReader(new FileReader(newdir));
                            }

                            buffer = "";
                            String prebuf = "";
                            for (int c = 0; c < line; c++) {
                                buffer = stdin.readLine();
                            }
                            stdin.close();
                            //System.out.println(buffer.length() + "\t" + seekstart + "\t" + seekend);
                            int real_end = (line - 1) * 20000 + seekend;
                            int real_start = (line - 1) * 20000 + seekstart;
                            //tofile.add("SSR: "+buffer.substring(seekstart, seekend) + "start-end: "+ real_start + "-" +real_end );
                            countpc++;
                            String tmp = "";
                            if (seekstart < 0) {
                                stdin = new BufferedReader(new FileReader(newdir));
                                for (int c = 0; c < line - 1; c++) {
                                    prebuf = stdin.readLine();
                                }
                                stdin.close();
                                tmp += prebuf.substring(prebuf.length() + seekstart);
                                tmp += buffer.substring(0, seekend);
                            } else
                                tmp = buffer.substring(seekstart, seekend);

                            bpcount += tmp.length();
                            if (tmp.contains("A")) {
                                Aperc += StringUtils.countMatches(tmp, "A");
                            }
                            if (tmp.contains("T")) {
                                Tperc += StringUtils.countMatches(tmp, "T");
                            }
                            if (tmp.contains("G")) {
                                Gperc += StringUtils.countMatches(tmp, "G");
                            }
                            if (tmp.contains("C")) {
                                Cperc += StringUtils.countMatches(tmp, "C");
                            }

                            out.println("SSR: " + tmp + " start-end: " + real_start + "-" + real_end
                                    + " Path(../data/chromosome): "
                                    + files.substring(0, files.lastIndexOf('.')));

                        }
                    }
                } catch (EOFException e) {
                    eof = true;
                }
            }
            in.close();
        }
        out.close();
        Runtime.getRuntime().exec("notepad " + statsfile);

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex);
        }
        Connection con = null;
        try {
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306", "biouser", "thesis2012");
        } catch (SQLException ex) {
            Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex);
        }
        Statement st = null;
        try {
            st = con.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex);
        }
        st.executeUpdate("use lobid");

        int seqcount = 0;

        if (filetype.contains("organisms")) {
            ResultSet rs = st.executeQuery(
                    "SELECT end FROM slices INNER JOIN organism WHERE slices.org_id=organism.org_id AND organism.name='"
                            + organisms[i] + "'");
            while (rs.next()) {
                seqcount += Long.parseLong(rs.getString(1));
            }
        } else if (filetype.contains("local")) {
            BufferedReader in = new BufferedReader(new FileReader("local/" + organisms[i] + "/index.txt"));
            int count = countlines("local/" + organisms[i] + "/index.txt");
            for (int c = 0; c < count; c++) {
                String temp = in.readLine();
                BufferedReader tmp = new BufferedReader(
                        new FileReader("local/" + organisms[i] + "/" + temp + ".txt"));

                boolean eof = false;
                while (!eof) {
                    String s = tmp.readLine();
                    if (s != null) {
                        seqcount += s.length();
                    } else {
                        eof = true;
                    }
                }
                tmp.close();
            }
        }

        DecimalFormat round = new DecimalFormat("#.###");

        html.println("<html><h1>******* Compound Perfect SSRs *******</h1>");
        html.println("<h4>Results for project: " + organisms[i]
                + "</h4><h4>Search Parameters --> Maximum Inter-repeat Region for Perfect Compound SSRs (bp) : "
                + gap + "</h4><h4>minimum SSR length (bp): " + length + "</h4>");
        html.println(
                "<table border=\"1\"><tr><td> </td><td><b>count</b></td><td><b>bp</b></td><td><b>A%</b></td><td><b>T%</b></td><td><b>C%</b></td><td><b>G%</b></td><td><b>Relative Frequency</b></td><td><b>Abundance</b></td><td><b>Relative Abundance</b></td></tr>");
        html.println("<tr><td><b>Compound Perf.</b></td><td>" + countpc + "</td><td>" + bpcount + "</td><td>"
                + round.format((float) Aperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Tperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Cperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Gperc * 100 / bpcount) + "</td><td>"
                + round.format((float) countpc / countpc) + "</td><td>"
                + round.format((float) bpcount / seqcount) + "</td><td>"
                + round.format((float) bpcount / bpcount) + "</td></tr>");
        html.println("<tr><td><b>TOTAL</b></td><td>" + countpc + "</td><td>" + bpcount + "</td><td>"
                + round.format((float) Aperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Tperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Cperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Gperc * 100 / bpcount) + "</td><td>"
                + round.format((float) countpc / countpc) + "</td><td>"
                + round.format((float) bpcount / seqcount) + "</td><td>"
                + round.format((float) bpcount / bpcount) + "</td></tr></table></html>");
        html.close();

        stats.println("******* Compound Perfect SSRs *******");
        stats.println("Results for project: " + organisms[i]
                + "\nSearch Parameters --> Maximum Inter-repeat Region for Perfect Compound SSRs (bp) : " + gap
                + "\nminimum SSR length (bp): " + length);

        stats.println(
                " ___________________________________________________________________________________________________________________ ");
        stats.println(
                "|              |       |            |       |       |       |       |   Relative    |               |   Relative    |");
        stats.println(
                "|              | count |     bp     |   A%  |   T%  |   C%  |   G%  |   Frequency   |   Abundance   |   Abundance   |");
        stats.println(
                "|==============|=======|============|=======|=======|=======|=======|===============|===============|===============|");
        stats.printf(
                "|Compound Perf.|" + cell(Integer.toString(countpc), 7) + "|"
                        + cell(Integer.toString(bpcount), 12) + "|%s|%s|%s|%s|"
                        + cell((float) countpc / countpc, 15) + "|" + cell((float) bpcount / seqcount, 15) + "|"
                        + cell((float) bpcount / bpcount, 15) + "|\n",
                cell((float) Aperc * 100 / bpcount, 7), cell((float) Tperc * 100 / bpcount, 7),
                cell((float) Cperc * 100 / bpcount, 7), cell((float) Gperc * 100 / bpcount, 7));
        stats.println(
                "|--------------|-------|------------|-------|-------|-------|-------|---------------|---------------|---------------|");

        lt.writeLong(seqcount);
        lt.writeInt(countpc);
        lt.writeInt(bpcount);
        lt.writeInt(Aperc);
        lt.writeInt(Tperc);
        lt.writeInt(Gperc);
        lt.writeInt(Cperc);

        stats.println("|TOTAL         |" + cell(Integer.toString(countpc), 7) + "|"
                + cell(Long.toString(bpcount), 12) + "|" + cell((float) Aperc * 100 / bpcount, 7) + "|"
                + cell((float) Tperc * 100 / bpcount, 7) + "|" + cell((float) Cperc * 100 / bpcount, 7) + "|"
                + cell((float) Gperc * 100 / bpcount, 7) + "|" + cell((float) countpc / countpc, 15) + "|"
                + cell((float) bpcount / seqcount, 15) + "|" + cell((float) bpcount / bpcount, 15) + "|");
        stats.println(
                "|______________|_______|____________|_______|_______|_______|_______|_______________|_______________|_______________|");
        stats.println("Genome length (bp): " + seqcount);
        stats.println("Relative Frequency: Count of each motif type / total SSR count");
        stats.println("Abundance: bp of each motif type / total sequence bp");
        stats.println("Relative Abundance: bp of each motif type / total microsatellites bp");
        stats.println();
        stats.println();
        stats.close();
        lt.close();

    }

}

From source file:MiGA.StatsSelection.java

public void getImPerfectCompoundSSRs(String[] organisms, int length, boolean flag, int gap)
        throws SQLException, ClassNotFoundException, FileNotFoundException, IOException {

    String statsfile = "";
    for (int i = 0; i < organisms.length; i++) {
        boolean found = false;
        String buffer = new String();
        int seekstart = 0;
        int seekend = 0;
        List<String> ssrs = new ArrayList<String>();
        // 18/11/2013 added starting here
        String filetype = "";
        String filepro = "";

        if (flag) {
            filetype = "organisms";
            filepro = "organisms/" + organisms[i] + "/data/";
            int ret = getOrganismStatus(organisms[i]);
            if (ret == -1)
                indexer = new Indexer(chromosomelist);
            else//from w w w .  ja  va  2s .c  om
                indexer = new Indexer(ret);

        } else {
            filetype = "local";
            filepro = "local/" + organisms[i] + "/data/";
            String indexfile = "local/" + organisms[i] + "/index.txt";
            indexer = new Indexer(indexfile);
        }
        //List<String> files = getFiles(organisms[i], minlen, flag);

        // 18/11/2013 added ending here
        PrintWriter out;
        PrintWriter stats;
        PrintWriter html;
        DataOutputStream lt = null;
        if (filetype.contains("organism")) {

            File f = new File("organisms/" + organisms[i] + "/stats/");
            if (!f.exists()) {
                f.mkdir();
            }

            stats = new PrintWriter(
                    new FileWriter("organisms/" + organisms[i] + "/stats/" + "summary_statistics"
                            + now.toString().replace(':', '_').replace(' ', '_') + ".txt", true));
            lt = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("organisms/" + organisms[i]
                    + "/data/" + now.toString().replace(':', '_').replace(' ', '_') + ".compim")));
            html = new PrintWriter(new FileWriter("organisms/" + organisms[i] + "/stats/" + "summary_statistics"
                    + now.toString().replace(':', '_').replace(' ', '_') + ".html", true));

            File fi = new File("organisms/" + organisms[i] + "/results/");
            if (!fi.exists()) {
                fi.mkdir();
            }

            String toopen = "organisms/" + organisms[i] + "/results/allCompImPerfect_"
                    + now.toString().replace(':', '_').replace(' ', '_') + ".txt";
            statsfile = toopen;
            out = new PrintWriter(toopen);
            out.println("Results for organism: " + organisms[i]
                    + "\t Search Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs(bp) : "
                    + gap + " - minimum SSR length(bp): " + length);

        } else {

            File f = new File("local/" + organisms[i] + "/stats/");
            if (!f.exists()) {
                f.mkdir();
            }

            stats = new PrintWriter(new FileWriter("local/" + organisms[i] + "/stats/" + "summary_statistics"
                    + now.toString().replace(':', '_').replace(' ', '_') + ".txt", true));
            lt = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("local/" + organisms[i]
                    + "/data/" + now.toString().replace(':', '_').replace(' ', '_') + ".compim")));
            html = new PrintWriter(new FileWriter("local/" + organisms[i] + "/stats/" + "summary_statistics"
                    + now.toString().replace(':', '_').replace(' ', '_') + ".html", true));

            File fi = new File("local/" + organisms[i] + "/results/");
            if (!fi.exists()) {
                fi.mkdir();
            }
            Calendar calendar = Calendar.getInstance();
            Date now = calendar.getTime();
            String toopen = "local/" + organisms[i] + "/results/allCompImPerfect_"
                    + now.toString().replace(':', '_').replace(' ', '_') + ".txt";
            statsfile = toopen;
            out = new PrintWriter(toopen);
            out.println("Results for project: " + organisms[i]
                    + "\t Search Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs(bp) : "
                    + gap + " - minimum SSR length(bp): " + length);

        }

        int countpc = 0;
        int bpcount = 0, Aperc = 0, Tperc = 0, Gperc = 0, Cperc = 0;

        while (indexer.hasNext()) {
            String files = filepro + indexer.getNextFileName();
            DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(files)));
            //PrintWriter out = new PrintWriter(files + "-minlentgh_" + length + "_ImPerfect.stats");
            boolean eof = false;
            while (!eof) {
                try {
                    SSR = new ArrayList<String>();
                    repeats = new ArrayList<Integer>();
                    EndOfSsr = new ArrayList<Integer>();
                    start = new ArrayList<Integer>();

                    int len = in.readInt();
                    int line = in.readInt();
                    for (int k = 0; k < len; k++) {
                        //THIS
                        String temp = in.readUTF();
                        if (!temp.contains("N")) {
                            SSR.add(temp);
                            EndOfSsr.add(in.readInt());
                            repeats.add(in.readInt());

                            start.add(EndOfSsr.get(k) - (SSR.get(k).length() * repeats.get(k)));
                        } else {
                            int junk = in.readInt();
                            junk = in.readInt();
                        }
                    }

                    List<String> SSRlen = new ArrayList<String>();
                    List<Integer> Endlen = new ArrayList<Integer>();
                    List<Integer> repslen = new ArrayList<Integer>();
                    List<Integer> startlen = new ArrayList<Integer>();

                    for (int k = 0; k < SSR.size(); k++) {
                        if (SSR.get(k).length() * repeats.get(k) >= length) {
                            SSRlen.add(SSR.get(k));
                            Endlen.add(EndOfSsr.get(k));
                            repslen.add(repeats.get(k));
                            startlen.add(start.get(k));
                        }
                    }

                    List<Integer> sortedstart = new ArrayList<Integer>();

                    List<Integer> sortedend = new ArrayList<Integer>();
                    for (int t = 0; t < startlen.size(); t++) {
                        sortedstart.add(startlen.get(t));
                        sortedend.add(Endlen.get(t));
                    }

                    Collections.sort(sortedstart);
                    Collections.sort(sortedend);

                    //List<String> tofile = new ArrayList<String>();
                    for (int k = 0; k < sortedstart.size() - 2; k++) {
                        found = false;
                        ssrs.clear();
                        ssrs = new ArrayList<String>();
                        if (sortedstart.get(k + 1) - sortedend.get(k) <= gap
                                && sortedstart.get(k + 1) - sortedend.get(k) >= 0) {
                            seekstart = sortedstart.get(k);
                            while (k < sortedstart.size() - 1
                                    && sortedstart.get(k + 1) - sortedend.get(k) <= gap
                                    && sortedstart.get(k + 1) - sortedend.get(k) >= 0) {
                                for (int c = 0; c < startlen.size(); c++) {
                                    if (sortedstart.get(k) == startlen.get(c)) {
                                        ssrs.add(SSRlen.get(c));
                                    }
                                    if (sortedstart.get(k + 1) == startlen.get(c)) {
                                        ssrs.add(SSRlen.get(c));
                                        seekend = Endlen.get(c);
                                        found = true;
                                    }
                                }
                                k++;
                            }
                            k--;
                        }
                        boolean check = checkallsame(ssrs);
                        boolean check2 = checkalldiff(ssrs);
                        if (found && !check && !check2) {
                            BufferedReader stdin = null;
                            if (flag) {
                                String[] temp = files.split("/");
                                boolean type = CheckForKaryotype(organisms[i]);
                                String newdir = "";
                                if (type) {
                                    newdir = temp[0] + "/" + temp[1] + "/chrom-"
                                            + temp[3].substring(0, temp[3].lastIndexOf('.')) + "-slices.txt";
                                } else {
                                    newdir = temp[0] + "/" + temp[1] + "/slice-"
                                            + temp[3].substring(0, temp[3].lastIndexOf('.')) + ".txt";
                                }

                                stdin = new BufferedReader(new FileReader(newdir));

                            } else {
                                String[] temp = files.split("data/");
                                String newdir = temp[0] + "/" + temp[1].substring(0, temp[1].lastIndexOf('.'))
                                        + ".txt";
                                stdin = new BufferedReader(new FileReader(newdir));
                            }
                            buffer = "";
                            for (int c = 0; c < line; c++) {
                                buffer = stdin.readLine();
                            }
                            //System.out.println(buffer.length() + "\t" + seekstart + "\t" + seekend);
                            int real_end = (line - 1) * 20000 + seekend;
                            int real_start = (line - 1) * 20000 + seekstart;
                            //tofile.add("SSR: "+buffer.substring(seekstart, seekend) + "start-end: "+ real_start + "-" +real_end );
                            countpc++;
                            if (seekstart < 0)
                                seekstart++;
                            String tmp = buffer.substring(seekstart, seekend);
                            bpcount += tmp.length();
                            if (tmp.contains("A")) {
                                Aperc += StringUtils.countMatches(tmp, "A");
                            }
                            if (tmp.contains("T")) {
                                Tperc += StringUtils.countMatches(tmp, "T");
                            }
                            if (tmp.contains("G")) {
                                Gperc += StringUtils.countMatches(tmp, "G");
                            }
                            if (tmp.contains("C")) {
                                Cperc += StringUtils.countMatches(tmp, "C");
                            }
                            out.println("SSR: " + tmp + " start-end: " + real_start + "-" + real_end
                                    + " Path(../data/chromosome): "
                                    + files.substring(0, files.lastIndexOf('.')));
                            stdin.close();

                        }

                    }

                } catch (EOFException e) {
                    eof = true;
                }
            }
            in.close();
        }
        out.close();
        Runtime.getRuntime().exec("notepad " + statsfile);
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex);
        }
        Connection con = null;
        try {
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306", "biouser", "thesis2012");
        } catch (SQLException ex) {
            Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex);
        }
        Statement st = null;
        try {
            st = con.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex);
        }
        st.executeUpdate("use lobid");

        int seqcount = 0;
        if (filetype.contains("organisms")) {
            ResultSet rs = st.executeQuery(
                    "SELECT end FROM slices INNER JOIN organism WHERE slices.org_id=organism.org_id AND organism.name='"
                            + organisms[i] + "'");
            while (rs.next()) {
                seqcount += Long.parseLong(rs.getString(1));
            }
        } else if (filetype.contains("local")) {
            BufferedReader in = new BufferedReader(new FileReader("local/" + organisms[i] + "/index.txt"));
            int count = countlines("local/" + organisms[i] + "/index.txt");
            for (int c = 0; c < count; c++) {
                String temp = in.readLine();
                BufferedReader tmp = new BufferedReader(
                        new FileReader("local/" + organisms[i] + "/" + temp + ".txt"));

                boolean eof = false;
                while (!eof) {
                    String s = tmp.readLine();
                    if (s != null) {
                        seqcount += s.length();
                    } else {
                        eof = true;
                    }
                }
                tmp.close();
            }
        }

        DecimalFormat round = new DecimalFormat("#.###");

        html.println("<html><h1>******* Compound Imperfect SSRs *******</h1>");
        html.println("<h4>Results for project: " + organisms[i]
                + "</h4><h4>Search Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs (bp) : "
                + gap + "</h4><h4>minimum SSR length (bp): " + length + "</h4>");
        html.println(
                "<table border=\"1\"><tr><td> </td><td><b>count</b></td><td><b>bp</b></td><td><b>A%</b></td><td><b>T%</b></td><td><b>C%</b></td><td><b>G%</b></td><td><b>Relative Frequency</b></td><td><b>Abundance</b></td><td><b>Relative Abundance</b></td></tr>");
        html.println("<tr><td><b>Compound Imperf.</b></td><td>" + countpc + "</td><td>" + bpcount + "</td><td>"
                + round.format((float) Aperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Tperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Cperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Gperc * 100 / bpcount) + "</td><td>"
                + round.format((float) countpc / countpc) + "</td><td>"
                + round.format((float) bpcount / seqcount) + "</td><td>"
                + round.format((float) bpcount / bpcount) + "</td></tr>");
        html.println("<tr><td><b>TOTAL</b></td><td>" + countpc + "</td><td>" + bpcount + "</td><td>"
                + round.format((float) Aperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Tperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Cperc * 100 / bpcount) + "</td><td>"
                + round.format((float) Gperc * 100 / bpcount) + "</td><td>"
                + round.format((float) countpc / countpc) + "</td><td>"
                + round.format((float) bpcount / seqcount) + "</td><td>"
                + round.format((float) bpcount / bpcount) + "</td></tr></table></html>");
        html.close();

        stats.println("******* Compound Imperfect SSRs *******");
        stats.println("Results for project: " + organisms[i]
                + "\nSearch Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs(bp) : " + gap
                + "\nminimum SSR length(bp): " + length);

        stats.println(
                " ____________________________________________________________________________________________________________________ ");
        stats.println(
                "|               |       |            |       |       |       |       |   Relative    |               |   Relative    |");
        stats.println(
                "|               | count |     bp     |   A%  |   T%  |   C%  |   G%  |   Frequency   |   Abundance   |   Abundance   |");
        stats.println(
                "|===============|=======|============|=======|=======|=======|=======|===============|===============|===============|");
        stats.printf(
                "|Compound Imper.|" + cell(Integer.toString(countpc), 7) + "|"
                        + cell(Integer.toString(bpcount), 12) + "|%s|%s|%s|%s|"
                        + cell((float) countpc / countpc, 15) + "|" + cell((float) bpcount / seqcount, 15) + "|"
                        + cell((float) bpcount / bpcount, 15) + "|\n",
                cell((float) Aperc * 100 / bpcount, 7), cell((float) Tperc * 100 / bpcount, 7),
                cell((float) Cperc * 100 / bpcount, 7), cell((float) Gperc * 100 / bpcount, 7));
        stats.println(
                "|---------------|-------|------------|-------|-------|-------|-------|---------------|---------------|---------------|");

        lt.writeLong(seqcount);
        lt.writeInt(countpc);
        lt.writeInt(bpcount);
        lt.writeInt(Aperc);
        lt.writeInt(Tperc);
        lt.writeInt(Gperc);
        lt.writeInt(Cperc);

        stats.println("|TOTAL          |" + cell(Integer.toString(countpc), 7) + "|"
                + cell(Long.toString(bpcount), 12) + "|" + cell((float) Aperc * 100 / bpcount, 7) + "|"
                + cell((float) Tperc * 100 / bpcount, 7) + "|" + cell((float) Cperc * 100 / bpcount, 7) + "|"
                + cell((float) Gperc * 100 / bpcount, 7) + "|" + cell((float) countpc / countpc, 15) + "|"
                + cell((float) bpcount / seqcount, 15) + "|" + cell((float) bpcount / bpcount, 15) + "|");
        stats.println(
                "|_______________|_______|____________|_______|_______|_______|_______|_______________|_______________|_______________|");
        stats.println("Genome length (bp): " + seqcount);
        stats.println("Relative Frequency: Count of each motif type / total SSR count");
        stats.println("Abundance: bp of each motif type / total sequence bp");
        stats.println("Relative Abundance: bp of each motif type / total microsatellites bp");
        stats.println();
        stats.println();
        stats.close();
        lt.close();

    }

}