| 1 |
package stream; |
| 2 |
|
| 3 |
import java.util.ArrayList; |
| 4 |
|
| 5 |
import fileIO.FileFormat; |
| 6 |
import fileIO.ReadWrite; |
| 7 |
import structures.ListNum; |
| 8 |
|
| 9 |
public abstract class ReadInputStream { |
| 10 |
|
| 11 |
public static final ArrayList<Read> toReads(String fname, int defaultFormat, long maxReads){ |
| 12 |
if(fname==null){return null;} |
| 13 |
FileFormat ff=FileFormat.testInput(fname, defaultFormat, null, false, true); |
| 14 |
return toReads(ff, maxReads); |
| 15 |
} |
| 16 |
|
| 17 |
public static final Read[] toReadArray(FileFormat ff, long maxReads){ |
| 18 |
ArrayList<Read> list=toReads(ff, maxReads); |
| 19 |
return list==null ? null : list.toArray(new Read[0]); |
| 20 |
} |
| 21 |
|
| 22 |
public static final ArrayList<Read> toReads(FileFormat ff, long maxReads){ |
| 23 |
ArrayList<Read> list=new ArrayList<Read>(); |
| 24 |
|
| 25 |
|
| 26 |
ConcurrentReadInputStream cris=ConcurrentReadInputStream.getReadInputStream(maxReads, false, ff, null); |
| 27 |
cris.start(); |
| 28 |
ListNum<Read> ln=cris.nextList(); |
| 29 |
ArrayList<Read> reads=(ln!=null ? ln.list : null); |
| 30 |
|
| 31 |
|
| 32 |
while(ln!=null && reads!=null && reads.size()>0){ |
| 33 |
list.addAll(reads); |
| 34 |
|
| 35 |
|
| 36 |
cris.returnList(ln); |
| 37 |
ln=cris.nextList(); |
| 38 |
reads=(ln!=null ? ln.list : null); |
| 39 |
} |
| 40 |
|
| 41 |
cris.returnList(ln); |
| 42 |
ReadWrite.closeStream(cris); |
| 43 |
return list; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
public abstract Read next(); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public abstract ArrayList<Read> nextList(); |
| 59 |
|
| 60 |
public abstract boolean hasMore(); |
| 61 |
|
| 62 |
public abstract void restart(); |
| 63 |
|
| 64 |
|
| 65 |
public abstract boolean close(); |
| 66 |
|
| 67 |
public abstract boolean paired(); |
| 68 |
|
| 69 |
protected static final ArrayList<Read> toList(Read[] array){ |
| 70 |
if(array==null || array.length==0){return null;} |
| 71 |
ArrayList<Read> list=new ArrayList<Read>(array.length); |
| 72 |
for(int i=0; i<array.length; i++){list.add(array[i]);} |
| 73 |
return list; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
public boolean errorState(){return errorState;} |
| 78 |
|
| 79 |
protected boolean errorState=false; |
| 80 |
|
| 81 |
public final boolean preferLists(){return true;} |
| 82 |
|
| 83 |
public abstract void start(); |
| 84 |
|
| 85 |
public abstract String fname(); |
| 86 |
|
| 87 |
} |