File: FileOps.java

package info (click to toggle)
rockhopper 2.0.3%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 33,136 kB
  • sloc: java: 10,831; sh: 31; xml: 29; makefile: 14
file content (765 lines) | stat: -rw-r----- 29,152 bytes parent folder | download | duplicates (2)
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
/*
 * Copyright 2013 Brian Tjaden
 *
 * This file is part of Rockhopper.
 *
 * Rockhopper is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * Rockhopper is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * (in the file gpl.txt) along with Rockhopper.  
 * If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.zip.GZIPOutputStream;
import java.util.zip.GZIPInputStream;

/**
 * Supports reading and writing of compressed files.
 */
public class FileOps {

    /********************************************
     **********   Instance Variables   **********
     ********************************************/

    private String readFileName;
    private long readFileLength;
    private long readFileDate;
    private String repliconFileName;
    private long repliconFileLength;
    private long repliconFileDate;
    private String repliconHeader;
    private int repliconLength;
    private long avgLengthReads;
    private int[] coordinates_plus;
    private int[] coordinates_minus;
    private ArrayList<DeNovoTranscript> transcripts;  // For de novo assembly
    private boolean isValid;

    // Results
    private int totalReads;
    private int invalidQualityReads;      // Reads containing an invalid quality score
    private int ambiguousReads;           // Reads with ambiguous nucleotides
    private int lowQualityReads;          // Reads with quality scores too low for mapping
    private int mappedOnceReads;          // Reads mapping to one location
    private int mappedMoreThanOnceReads;  // Reads mapping to multiple locations
    private int exactMappedReads;         // Reads mapping without mismatches/errors
    private int inexactMappedReads;       // Reads mapping with mismatches/errors



    /*****************************************
     **********   Class Variables   **********
     *****************************************/

    private static String DIR = Rockhopper.output_DIR + "intermediary/";
    private static byte[] buffer1 = new byte[1];  // Temp array used when reading in GZIP file



    /**************************************
     **********   Constructors   **********
     **************************************/

    public FileOps(String inFileName) {
	isValid = readCompressedFile(inFileName);
    }

    public FileOps(String inFileName, String readFileName, String repliconFileName) {
	isValid = readCompressedFile(inFileName);
	File readFile = new File(readFileName);
	File repliconFile = new File(repliconFileName);
	isValid = isValid && (readFile.getName().equals(this.readFileName)) && (readFile.length() == readFileLength) && (readFile.lastModified() == readFileDate) && (repliconFile.getName().equals(this.repliconFileName)) && (repliconFile.length() == repliconFileLength) && (repliconFile.lastModified() == repliconFileDate);
    }

    /**
     * Constructor used for de novo transcript assembly.
     */
    public FileOps(String inFileName, ArrayList<String> conditionFiles) {
	isValid = readCompressedFile_DeNovo(inFileName, conditionFiles);
    }



    /*************************************************
     **********   Public Instance Methods   **********
     *************************************************/

    /**
     * Returns true if the input file is valid, i.e.,
     * the stats of the read-file and replicon-file file 
     * correspond to the stats from the input file.
     * Returns false otherwise.
     */
    public boolean isValid() {
	return this.isValid;
    }

    /**
     * Returns the name of the sequencing read file.
     */
    public String getReadFileName() {
	return this.readFileName;
    }

    /**
     * Returns the average length of sequencing reads
     * in the sequencing reads file.
     */
    public long getAvgLengthReads() {
	return avgLengthReads;
    }

    /**
     * Returns plus strand coordinates.
     */
    public int[] getCoordinates_plus() {
	return this.coordinates_plus;
    }

    /**
     * Returns minus strand coordinates.
     */
    public int[] getCoordinates_minus() {
	return this.coordinates_minus;
    }

    /**
     * Returns the total reads
     */
    public int getTotalReads() {
	return this.totalReads;
    }

    /**
     * Returns the invalide quality reads
     */
    public int getInvalidQualityReads() {
	return this.invalidQualityReads;
    }

    /**
     * Returns the ambiguous reads
     */
    public int getAmbiguousReads() {
	return this.ambiguousReads;
    }

    /**
     * Returns the low quality reads
     */
    public int getLowQualityReads() {
	return this.lowQualityReads;
    }

    /**
     * Returns the mapped once reads
     */
    public int getMappedOnceReads() {
	return this.mappedOnceReads;
    }

    /**
     * Returns the mapped more than once reads
     */
    public int getMappedMoreThanOnceReads() {
	return this.mappedMoreThanOnceReads;
    }

    /**
     * Returns the exact mapped reads
     */
    public int getExactMappedReads() {
	return this.exactMappedReads;
    }

    /**
     * Returns the inexact mapped reads
     */
    public int getInexactMappedReads() {
	return this.inexactMappedReads;
    }

    /**
     * Returns the de novo assembled transcripts
     */
    public ArrayList<DeNovoTranscript> getTranscripts() {
	return this.transcripts;
    }



    /**********************************************
     **********   Public Class Methods   **********
     **********************************************/

    /**
     * Converts the specified pair of int arrays to byte arrays
     * and writes these byte arrays to a compressed file. The following
     * header information is also written to the compressed output file:
     *      version
     *      read file name
     *      read file length
     *      read file last modified date
     *      replicon file name
     *      replicon file length
     *      replicon file last modified date
     *      replicon FASTA header line
     *      replicon length
     *      average length of reads
     *      total reads
     *      invalid quality reads
     *      ambiguous reads
     *      low quality reads
     *      mapped once reads
     *      mapped more than once reads
     *      exact mapped reads
     *      inexact mapped reads
     */
    public static void writeCompressedFile(String outFileName, String readFileName, String repliconFileName, String repliconHeader, int repliconLength, int totalReads, int invalidQualityReads, int ambiguousReads, int lowQualityReads, int mappedOnceReads, int mappedMoreThanOnceReads, int exactMappedReads, int inexactMappedReads, long avgLengthReads, int[] a1, int[] a2) {
	File readFile = new File(readFileName);
	File repliconFile = new File(repliconFileName);
	byte[] header = (Rockhopper.version + "\n" + readFile.getName() + "\n" + readFile.length() + "\n" + readFile.lastModified() + "\n" + repliconFile.getName() + "\n" + repliconFile.length() + "\n" + repliconFile.lastModified() + "\n" + repliconHeader + "\n" + repliconLength + "\n" + avgLengthReads + "\n" + totalReads + "\n" + invalidQualityReads + "\n" + ambiguousReads + "\n" + lowQualityReads + "\n" + mappedOnceReads + "\n" + mappedMoreThanOnceReads + "\n" + exactMappedReads + "\n" + inexactMappedReads + "\n").getBytes();
	byte[] b1 = intArrayToByteArray(a1);
	byte[] b2 = intArrayToByteArray(a2);
	try {
	    // Set up directory
	    File d = new File(DIR);
	    if (!d.isDirectory()) d.mkdir();
	    GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(DIR + outFileName + ".gz"));
	    gzos.write(header, 0, header.length);
	    gzos.write(b1, 0, b1.length);
	    gzos.write(b2, 0, b2.length);
	    gzos.close();
	} catch (IOException e) {
	    Rockhopper.output("Could not write to file " + outFileName + ".gz" + "\n");
	}
    }

    /**
     * Writes a list of de novo assembled transcripts to a compressed file.
     * The following header information is also written to the compressed file:
     *      version
     *      number of conditions
     *      number of replicates in each condition
     *      for each read file: its name, its length, and its last modified time
     *      number of files
     *      for each file: total reads, total mapping reads
     *      number of transcripts in list
     *      number of p-values per transcript
     *      for each transcript:
     *            sequence
     *            for each condition: rawCounts_nts, rawCounts_reads, normalizedCounts
     *            RPKMs, means, variances, lowess, pValues, qValues
     */
    public static void writeCompressedFile(String outFileName, ArrayList<String> conditionFiles, int[] numReads, int[] numMappingReads, DeNovoTranscripts transcripts) {

	// Version, number of conditions, and number of replicates in each condition
	StringBuilder header = new StringBuilder();
	header.append(Rockhopper.version + "\n");
	header.append(conditionFiles.size() + "\n");
	for (int i=0; i<conditionFiles.size(); i++) {
	    header.append(conditionFiles.get(i).split(",").length + "\n");
	}

	// Name, length, and last modified time of each file (including mate-pair files)
	for (int i=0; i<conditionFiles.size(); i++) {
	    String[] files = conditionFiles.get(i).split(",");
	    for (int j=0; j<files.length; j++) {
		String[] parse_readFiles = files[j].split("%");
		if (parse_readFiles.length == 1) {  // Using single-end reads
		    String file1 = parse_readFiles[0];
		    File readFile = new File(file1);
		    header.append(readFile.getName() + "\n" + readFile.length() + "\n" + readFile.lastModified() + "\n");
		} else {  // Using paired-end reads
		    String file1 = parse_readFiles[0];
		    File readFile1 = new File(file1);
		    header.append(readFile1.getName() + "\n" + readFile1.length() + "\n" + readFile1.lastModified() + "\n");
		    String file2 = parse_readFiles[1];
		    File readFile2 = new File(file2);
		    header.append(readFile2.getName() + "\n" + readFile2.length() + "\n" + readFile2.lastModified() + "\n");
		}
	    }
	}

	// Number of files. Total reads per file and total number of mapping reads per file
	header.append(numReads.length + "\n");
	for (int i=0; i<numReads.length; i++) header.append(numReads[i] + "\n" + numMappingReads[i] + "\n");

	// Number of transcripts and number of p-values per transcript
	header.append(transcripts.getNumTranscripts() + "\n");
	if (transcripts.getNumTranscripts() == 0) header.append("0" + "\n");
	else header.append(transcripts.getTranscript(0).getNumPvalues() + "\n");

	// Write header information and information for each transcript
	try {
	    // Set up directory
	    File d = new File(DIR);
	    if (!d.isDirectory()) d.mkdir();
	    GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(DIR + outFileName + ".gz"));
	    byte[] header_bytes = header.toString().getBytes();
	    gzos.write(header_bytes, 0, header_bytes.length);
	    for (int i=0; i<transcripts.getNumTranscripts(); i++) {
		DeNovoTranscript transcript = transcripts.getTranscript(i);
		byte[] b = (transcript.sequence() + "\n").getBytes();  // Add new line to sequence
		gzos.write(b, 0, b.length);
		for (int j=0; j<conditionFiles.size(); j++) {
		    b = longArrayToByteArray(transcript.getRawCounts_nts_array(j));
		    gzos.write(b, 0, b.length);
		    b = longArrayToByteArray(transcript.getRawCounts_reads_array(j));
		    gzos.write(b, 0, b.length);
		    b = longArrayToByteArray(transcript.getNormalizedCounts_array(j));
		    gzos.write(b, 0, b.length);
		}
		b = longArrayToByteArray(transcript.getRPKMs());
		gzos.write(b, 0, b.length);
		b = longArrayToByteArray(transcript.getMeans());
		gzos.write(b, 0, b.length);
		b = longArrayToByteArray(transcript.getVariances());
		gzos.write(b, 0, b.length);
		b = longArrayToByteArray(transcript.getLowess());
		gzos.write(b, 0, b.length);
		b = doubleArrayToByteArray(transcript.getPvalues());
		gzos.write(b, 0, b.length);
		b = doubleArrayToByteArray(transcript.getQvalues());
		gzos.write(b, 0, b.length);
	    }
	    gzos.close();
	} catch (IOException e) {
	    Rockhopper.output("Could not write to file " + outFileName + ".gz" + "\n");
	}
    }

    /**
     * Returns true is file is successfully read. False otherwise.
     */
    public boolean readCompressedFile(String inFileName) {
	try {
	    GZIPInputStream in = new GZIPInputStream(new FileInputStream(DIR + inFileName + ".gz"));

	    // Read in header information
	    String version = getLine(in);
	    if (!version.equals(Rockhopper.version)) return false;
	    this.readFileName = getLine(in);
	    this.readFileLength = Long.parseLong(getLine(in));
	    this.readFileDate = Long.parseLong(getLine(in));
	    this.repliconFileName = getLine(in);
	    this.repliconFileLength = Long.parseLong(getLine(in));
	    this.repliconFileDate = Long.parseLong(getLine(in));
	    this.repliconHeader = getLine(in);
	    this.repliconLength = Integer.parseInt(getLine(in));
	    this.avgLengthReads = Long.parseLong(getLine(in));
	    this.totalReads = Integer.parseInt(getLine(in));
	    this.invalidQualityReads = Integer.parseInt(getLine(in));
	    this.ambiguousReads = Integer.parseInt(getLine(in));
	    this.lowQualityReads = Integer.parseInt(getLine(in));
	    this.mappedOnceReads = Integer.parseInt(getLine(in));
	    this.mappedMoreThanOnceReads = Integer.parseInt(getLine(in));
	    this.exactMappedReads = Integer.parseInt(getLine(in));
	    this.inexactMappedReads = Integer.parseInt(getLine(in));

	    // Retrieve data
	    this.coordinates_plus = new int[repliconLength];
	    for (int i=0; i<repliconLength; i++) coordinates_plus[i] = getInt(in);
	    this.coordinates_minus = new int[repliconLength];
	    for (int i=0; i<repliconLength; i++) coordinates_minus[i] = getInt(in);
	    in.close();
	    return true;
	} catch (IOException e) {
	    return false;
	}
    }

    /**
     * Returns true is file is successfully read and is valid. False otherwise.
     */
    public boolean readCompressedFile_DeNovo(String inFileName, ArrayList<String> conditionFiles) {
	try {

	    // Read in file
	    GZIPInputStream in = new GZIPInputStream(new FileInputStream(DIR + inFileName + ".gz"));
	    ArrayList<Byte> bytes = new ArrayList<Byte>(1000000);
	    byte[] buffer = new byte[1024];
	    int len;
	    while ((len = in.read(buffer)) >= 0) {
		for (int i=0; i<len; i++)
		    bytes.add(buffer[i]);
	    }
	    in.close();

	    // First header line: version
	    int startIndex = 0;
	    int stopIndex = getStopIndex(bytes, startIndex);
	    String version = getLine(bytes, startIndex, stopIndex);
	    if (!version.equals(Rockhopper.version)) return false;

	    // Second header line: number of conditions
	    startIndex = stopIndex + 1;
	    stopIndex = getStopIndex(bytes, startIndex);
	    int numConditions = Integer.parseInt(getLine(bytes, startIndex, stopIndex));
	    startIndex = stopIndex + 1;

	    // One line for each condition indicating number of replicates in condition
	    int[] numReplicates = new int[numConditions];
	    for (int i=0; i<numConditions; i++) {
		stopIndex = getStopIndex(bytes, startIndex);
		numReplicates[i] = Integer.parseInt(getLine(bytes, startIndex, stopIndex));
		startIndex = stopIndex + 1;
	    }

	    // For each read file, we have its name, length, and last modified time
	    String[][][] names = new String[2][numConditions][];  // First coordinate is mate-pair
	    long[][][] lengths = new long[2][numConditions][];    // First coordinate is mate-pair
	    long[][][] times = new long[2][numConditions][];      // First coordinate is mate-pair
	    for (int i=0; i<numConditions; i++) {
		names[0][i] = new String[numReplicates[i]];
		lengths[0][i] = new long[numReplicates[i]];
		times[0][i] = new long[numReplicates[i]];
		names[1][i] = new String[numReplicates[i]];
		lengths[1][i] = new long[numReplicates[i]];
		times[1][i] = new long[numReplicates[i]];
		String[] files = conditionFiles.get(i).split(",");
		for (int j=0; j<numReplicates[i]; j++) {
		    stopIndex = getStopIndex(bytes, startIndex);
		    names[0][i][j] = getLine(bytes, startIndex, stopIndex);
		    startIndex = stopIndex + 1;
		    stopIndex = getStopIndex(bytes, startIndex);
		    lengths[0][i][j] = Long.parseLong(getLine(bytes, startIndex, stopIndex));
		    startIndex = stopIndex + 1;
		    stopIndex = getStopIndex(bytes, startIndex);
		    times[0][i][j] = Long.parseLong(getLine(bytes, startIndex, stopIndex));
		    startIndex = stopIndex + 1;

		    // Handle mate-pair files, if any
		    String[] parse_readFiles = files[j].split("%");
		    if (parse_readFiles.length > 1) {  // Using paired-end reads
			stopIndex = getStopIndex(bytes, startIndex);
			names[1][i][j] = getLine(bytes, startIndex, stopIndex);
			startIndex = stopIndex + 1;
			stopIndex = getStopIndex(bytes, startIndex);
			lengths[1][i][j] = Long.parseLong(getLine(bytes, startIndex, stopIndex));
			startIndex = stopIndex + 1;
			stopIndex = getStopIndex(bytes, startIndex);
			times[1][i][j] = Long.parseLong(getLine(bytes, startIndex, stopIndex));
			startIndex = stopIndex + 1;
		    }
		}
	    }

	    // Number of files. For each file, number of reads and number of mapping reads
	    stopIndex = getStopIndex(bytes, startIndex);
	    int numFiles = Integer.parseInt(getLine(bytes, startIndex, stopIndex));
	    startIndex = stopIndex + 1;
	    int[] numReads = new int[numFiles];
	    int[] numMappingReads = new int[numFiles];
	    for (int i=0; i<numFiles; i++) {
		stopIndex = getStopIndex(bytes, startIndex);
		numReads[i] = Integer.parseInt(getLine(bytes, startIndex, stopIndex));
		startIndex = stopIndex + 1;
		stopIndex = getStopIndex(bytes, startIndex);
		numMappingReads[i] = Integer.parseInt(getLine(bytes, startIndex, stopIndex));
		startIndex = stopIndex + 1;
	    }

	    // Final two header lines
	    stopIndex = getStopIndex(bytes, startIndex);
	    int numTranscripts = Integer.parseInt(getLine(bytes, startIndex, stopIndex));
	    startIndex = stopIndex + 1;
	    stopIndex = getStopIndex(bytes, startIndex);
	    int numPvalues = Integer.parseInt(getLine(bytes, startIndex, stopIndex));
	    startIndex = stopIndex + 1;

	    // Transcripts
	    ArrayList<DeNovoTranscript> transcripts = new ArrayList<DeNovoTranscript>(numTranscripts);
	    for (int i=0; i<numTranscripts; i++) {  // For each transcript
		stopIndex = getStopIndex(bytes, startIndex);
		String sequence = getLine(bytes, startIndex, stopIndex);
		startIndex = stopIndex + 1;
		ArrayList<ArrayList<Long>> rawCounts_nts = new ArrayList<ArrayList<Long>>(numConditions);
		ArrayList<ArrayList<Long>> rawCounts_reads = new ArrayList<ArrayList<Long>>(numConditions);
		ArrayList<ArrayList<Long>> normalizedCounts = new ArrayList<ArrayList<Long>>(numConditions);
		for (int j=0; j<numConditions; j++) {
		    byte[] tempData = new byte[numReplicates[j]*8];
		    for (int k=startIndex; k<startIndex+numReplicates[j]*8; k++) tempData[k-startIndex] = bytes.get(k).byteValue();
		    rawCounts_nts.add(byteToLongList(tempData));
		    startIndex += numReplicates[j]*8;
		    for (int k=startIndex; k<startIndex+numReplicates[j]*8; k++) tempData[k-startIndex] = bytes.get(k).byteValue();
		    rawCounts_reads.add(byteToLongList(tempData));
		    startIndex += numReplicates[j]*8;
		    for (int k=startIndex; k<startIndex+numReplicates[j]*8; k++) tempData[k-startIndex] = bytes.get(k).byteValue();
		    normalizedCounts.add(byteToLongList(tempData));
		    startIndex += numReplicates[j]*8;
		}
		byte[] tempData = new byte[numConditions*8];
		for (int k=startIndex; k<startIndex+numConditions*8; k++) tempData[k-startIndex] = bytes.get(k).byteValue();
		ArrayList<Long> RPKMs = byteToLongList(tempData);
		startIndex += numConditions*8;
		for (int k=startIndex; k<startIndex+numConditions*8; k++) tempData[k-startIndex] = bytes.get(k).byteValue();
		ArrayList<Long> means = byteToLongList(tempData);
		startIndex += numConditions*8;
		tempData = new byte[numConditions*numConditions*8];
		for (int k=startIndex; k<startIndex+numConditions*numConditions*8; k++) tempData[k-startIndex] = bytes.get(k).byteValue();
		long[][] variances = byteToLong2Darray(tempData);
		startIndex += numConditions*numConditions*8;
		for (int k=startIndex; k<startIndex+numConditions*numConditions*8; k++) tempData[k-startIndex] = bytes.get(k).byteValue();
		long[][] lowess = byteToLong2Darray(tempData);
		startIndex += numConditions*numConditions*8;
		tempData = new byte[numPvalues*8];
		for (int k=startIndex; k<startIndex+numPvalues*8; k++) tempData[k-startIndex] = bytes.get(k).byteValue();
		ArrayList<Double> pValues = byteToDoubleList(tempData);
		startIndex += numPvalues*8;
		for (int k=startIndex; k<startIndex+numPvalues*8; k++) tempData[k-startIndex] = bytes.get(k).byteValue();
		ArrayList<Double> qValues = byteToDoubleList(tempData);
		startIndex += numPvalues*8;
		transcripts.add(new DeNovoTranscript(sequence, rawCounts_nts, rawCounts_reads, normalizedCounts, RPKMs, means, variances, lowess, pValues, qValues));
	    }

	    // Check validity
	    if (numConditions != conditionFiles.size()) return false;
	    for (int i=0; i<numConditions; i++) {
		String[] files = conditionFiles.get(i).split(",");
		if (numReplicates[i] != files.length) return false;
		for (int j=0; j<numReplicates[i]; j++) {
		    String[] parse_readFiles = files[j].split("%");
		    if (parse_readFiles.length == 1) {  // Using single-end reads
			String file1 = parse_readFiles[0];
			File f = new File(file1);
			if (!names[0][i][j].equals(f.getName())) return false;
			if (lengths[0][i][j] != f.length()) return false;
			if (times[0][i][j] != f.lastModified()) return false;
		    } else {  // Using paired-end reads
			String file1 = parse_readFiles[0];
			String file2 = parse_readFiles[1];
			File f1 = new File(file1);
			if (!names[0][i][j].equals(f1.getName())) return false;
			if (lengths[0][i][j] != f1.length()) return false;
			if (times[0][i][j] != f1.lastModified()) return false;
			File f2 = new File(file2);
			if (!names[1][i][j].equals(f2.getName())) return false;
			if (lengths[1][i][j] != f2.length()) return false;
			if (times[1][i][j] != f2.lastModified()) return false;
		    }
		}
	    }
	    this.transcripts = transcripts;
	    DeNovoTranscripts.numReads = numReads;
	    DeNovoTranscripts.numMappingReads = numMappingReads;
	    return true;
	} catch (Exception e) {
	    return false;
	}
    }

    /**
     * Returns true if the specified file is in gzip format.
     * Returns false otherwise.
     */
    public static boolean isGZIP(String fileName) {
	try {
	    GZIPInputStream in = new GZIPInputStream(new FileInputStream(fileName));
	    in.close();
	    return true;
	} catch (Exception e) {
	    return false;
	}
    }



    /**************************************************
     **********   Private Instance Methods   **********
     **************************************************/

    /**
     * Returns the first index after the specified startIndex in the Byte list 
     * corresponding to a new line (end of line).
     */
    private int getStopIndex(ArrayList<Byte> bytes, int startIndex) {
	int stopIndex = startIndex;
	while ((stopIndex < bytes.size()) && (bytes.get(stopIndex).byteValue() != 10)) stopIndex++;
	return stopIndex;
    }

    /**
     * Returns a String corresponding to one line, i.e., the bytes from
     * startIndex to stopIndex.
     */
    private String getLine(ArrayList<Byte> bytes, int startIndex, int stopIndex) {
	// Convert sequence of bytes to a String representing a line
	byte[] bytesInLine = new byte[stopIndex - startIndex];
	for (int i=startIndex; i<stopIndex; i++) bytesInLine[i - startIndex] = bytes.get(i).byteValue();
	return (new String(bytesInLine));
    }



    /***********************************************
     **********   Private Class Methods   **********
     ***********************************************/

    /**
     * Returns one line from the specified input stream.
     */
    private static String getLine(GZIPInputStream in) {
	try {
	    int len = -1;
	    ArrayList<Byte> buffer = new ArrayList<Byte>();
	    while (((len = in.read(buffer1)) >= 0) && (buffer1[0] != 10)) {
		buffer.add(buffer1[0]);
	    }
	    byte[] buffer_bytes = new byte[buffer.size()];
	    for (int i=0; i<buffer.size(); i++) buffer_bytes[i] = buffer.get(i).byteValue();
	    return (new String(buffer_bytes));
	} catch (IOException e) {
	    return "";
	}
    }

    /**
     * Returns one integer from the specified input stream.
     */
    private static int getInt(GZIPInputStream in) {
	try {
	    int result = 0;
	    in.read(buffer1);
	    result += (buffer1[0] & 0xFF) << 24;
	    in.read(buffer1);
	    result += (buffer1[0] & 0xFF) << 16;
	    in.read(buffer1);
	    result += (buffer1[0] & 0xFF) << 8;
	    in.read(buffer1);
	    result += (buffer1[0] & 0xFF);
	    return result;
	} catch (IOException e) {
	    return -1;
	}
    }

    /**
     * Returns a byte array representation of the specified int array.
     */
    private static byte[] intArrayToByteArray(int[] a) {
	byte[] b = new byte[a.length*4];
	for (int i=0; i<a.length; i++) {
	    b[4*i+0] = (byte)(a[i] >>> 24);
	    b[4*i+1] = (byte)(a[i] >>> 16);
	    b[4*i+2] = (byte)(a[i] >>> 8);
	    b[4*i+3] = (byte)(a[i] >>> 0);
	}
	return b;
    }

    /**
     * Returns a byte array representation of the specified long array.
     */
    private static byte[] longArrayToByteArray(long[] a) {
	byte[] b = new byte[a.length*8];
	for (int i=0; i<a.length; i++) {
	    b[8*i+0] = (byte)(a[i] >>> 56);
	    b[8*i+1] = (byte)(a[i] >>> 48);
	    b[8*i+2] = (byte)(a[i] >>> 40);
	    b[8*i+3] = (byte)(a[i] >>> 32);
	    b[8*i+4] = (byte)(a[i] >>> 24);
	    b[8*i+5] = (byte)(a[i] >>> 16);
	    b[8*i+6] = (byte)(a[i] >>> 8);
	    b[8*i+7] = (byte)(a[i] >>> 0);
	}
	return b;
    }

    /**
     * Returns a byte array representation of the specified double array.
     */
    private static byte[] doubleArrayToByteArray(double[] a) {
	byte[] b = new byte[a.length*8];
	for (int i=0; i<a.length; i++) {
	    b[8*i+0] = (byte)(Double.doubleToRawLongBits(a[i]) >>> 56);
	    b[8*i+1] = (byte)(Double.doubleToRawLongBits(a[i]) >>> 48);
	    b[8*i+2] = (byte)(Double.doubleToRawLongBits(a[i]) >>> 40);
	    b[8*i+3] = (byte)(Double.doubleToRawLongBits(a[i]) >>> 32);
	    b[8*i+4] = (byte)(Double.doubleToRawLongBits(a[i]) >>> 24);
	    b[8*i+5] = (byte)(Double.doubleToRawLongBits(a[i]) >>> 16);
	    b[8*i+6] = (byte)(Double.doubleToRawLongBits(a[i]) >>> 8);
	    b[8*i+7] = (byte)(Double.doubleToRawLongBits(a[i]) >>> 0);
	}
	return b;
    }

    /**
     * Returns an int array representation of the specified byte array.
     */
    private static int[] byteToIntArray(byte[] b) {
	int[] a = new int[b.length/4];
	for (int i=0; i<b.length; i+=4) {
	    a[i/4] = (b[i+0] << 24) + ((b[i+1] & 0xFF) << 16) + ((b[i+2] & 0xFF) << 8) + (b[i+3] & 0xFF);
	}
	return a;
    }

    /**
     * Returns a long list representation of the specified byte array.
     */
    private static ArrayList<Long> byteToLongList(byte[] b) {
	ArrayList<Long> a = new ArrayList<Long>(b.length/8);
	for (int i=0; i<b.length; i+=8) {
	    a.add(((long)(b[i+0] & 0xFF) << 56) | ((long)(b[i+1] & 0xFF) << 48) | ((long)(b[i+2] & 0xFF) << 40) | ((long)(b[i+3] & 0xFF) << 32) | ((long)(b[i+4] & 0xFF) << 24) | ((long)(b[i+5] & 0xFF) << 16) | ((long)(b[i+6] & 0xFF) << 8) | ((long)(b[i+7] & 0xFF) << 0));
	}
	return a;
    }

    /**
     * Returns a double list representation of the specified byte array.
     */
    private static ArrayList<Double> byteToDoubleList(byte[] b) {
	ArrayList<Double> a = new ArrayList<Double>(b.length/8);
	for (int i=0; i<b.length; i+=8) {
	    a.add(Double.longBitsToDouble(((long)(b[i+0] & 0xFF) << 56) | ((long)(b[i+1] & 0xFF) << 48) | ((long)(b[i+2] & 0xFF) << 40) | ((long)(b[i+3] & 0xFF) << 32) | ((long)(b[i+4] & 0xFF) << 24) | ((long)(b[i+5] & 0xFF) << 16) | ((long)(b[i+6] & 0xFF) << 8) | ((long)(b[i+7] & 0xFF) << 0)));
	}
	return a;
    }

    /**
     * Returns a 2D long array representation of the specified byte array.
     */
    private static long[][] byteToLong2Darray(byte[] b) {
	ArrayList<Long> a = byteToLongList(b);

	// Convert 1D long list into 2D long array
	int size = (int)(Math.sqrt(a.size()));
	long[][] c = new long[size][size];
	int index = 0;
	for (int x=0; x<size; x++) {
	    for (int y=0; y<size; y++) {
		c[x][y] = a.get(index);
		index++;
	    }
	}
	return c;
    }



    /*************************************
     **********   Main Method   **********
     *************************************/

    public static void main(String[] args) {

    }

}