Debian Codegraph @

current/stream/ReadInputStream.java

raw symbols SCIP
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 /* Start an input stream */
26 ConcurrentReadInputStream cris=ConcurrentReadInputStream.getReadInputStream(maxReads, false, ff, null);
27 cris.start(); //4567
28 ListNum<Read> ln=cris.nextList();
29 ArrayList<Read> reads=(ln!=null ? ln.list : null);
30
31 /* Iterate through read lists from the input stream */
32 while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning
33 list.addAll(reads);
34
35 /* Dispose of the old list and fetch a new one */
36 cris.returnList(ln);
37 ln=cris.nextList();
38 reads=(ln!=null ? ln.list : null);
39 }
40 /* Cleanup */
41 cris.returnList(ln);
42 ReadWrite.closeStream(cris);
43 return list;
44 }
45
46
47 public abstract Read next();
48
49 // public final ArrayList<Read> fetchAll(){
50 // ArrayList<Read> out=new ArrayList<Read>();
51 // for(ArrayList<Read> list=nextList(); list!=null && list.size()>0; list=nextList()){
52 // out.addAll(list);
53 // }
54 // close();
55 // return out;
56 // }
57
58 public abstract ArrayList<Read> nextList();
59
60 public abstract boolean hasMore();
61
62 public abstract void restart();
63
64 /** Returns true if there was an error, false otherwise */
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 /** Return true if this stream has detected an error */
77 public boolean errorState(){return errorState;}
78 /** TODO */
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 }