Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/clump/StreamToOutput.java @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 package clump; | |
2 | |
3 import java.io.File; | |
4 import java.io.IOException; | |
5 import java.util.ArrayList; | |
6 | |
7 import fileIO.FileFormat; | |
8 import fileIO.ReadWrite; | |
9 import sort.SortByName; | |
10 import stream.ConcurrentReadInputStream; | |
11 import stream.ConcurrentReadOutputStream; | |
12 import stream.Read; | |
13 import structures.ListNum; | |
14 | |
15 public class StreamToOutput { | |
16 | |
17 public StreamToOutput(FileFormat ffin1, FileFormat ffin2, ConcurrentReadOutputStream[] rosa_, KmerComparator old, boolean sortByName_, boolean incrementComparator){ | |
18 final ConcurrentReadInputStream cris=ConcurrentReadInputStream.getReadInputStream(-1, false, ffin1, ffin2, null, null); | |
19 cris.start(); | |
20 rosa=rosa_; | |
21 kc=(incrementComparator ? new KmerComparator(old.k, old.seed+1, old.border-1, old.hashes, false, false) : old); | |
22 sortByName=sortByName_; | |
23 } | |
24 | |
25 public StreamToOutput(ConcurrentReadInputStream cris_, ConcurrentReadOutputStream[] rosa_, KmerComparator old, boolean sortByName_, boolean incrementComparator){ | |
26 cris=cris_; | |
27 rosa=rosa_; | |
28 kc=(incrementComparator ? new KmerComparator(old.k, old.seed+1, old.border-1, old.hashes, false, false) : old); | |
29 sortByName=sortByName_; | |
30 } | |
31 | |
32 public boolean process(){ | |
33 if(rosa==null || rosa.length==0){return errorState;} | |
34 | |
35 File temp=null; | |
36 if(sortByName){ | |
37 try { | |
38 temp=File.createTempFile("temp_namesort_", ".fq.gz"); | |
39 } catch (IOException e) { | |
40 // TODO Auto-generated catch block | |
41 e.printStackTrace(); | |
42 } | |
43 SortByName sbn=new SortByName(new String[] {"out="+temp.getAbsolutePath()}); | |
44 sbn.processInner(cris); | |
45 FileFormat ff=FileFormat.testInput(temp.getAbsolutePath(), null, false); | |
46 cris=ConcurrentReadInputStream.getReadInputStream(-1, false, ff, null, null, null); | |
47 } | |
48 | |
49 if(rosa.length==1){ | |
50 processSingle(cris); | |
51 }else{ | |
52 processMulti(cris); | |
53 } | |
54 | |
55 errorState|=ReadWrite.closeStream(cris); | |
56 if(temp!=null){ | |
57 temp.delete(); | |
58 } | |
59 return errorState; | |
60 } | |
61 | |
62 public void processSingle(ConcurrentReadInputStream cris){ | |
63 | |
64 ListNum<Read> ln=cris.nextList(); | |
65 ArrayList<Read> reads=(ln!=null ? ln.list : null); | |
66 | |
67 while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning | |
68 if(rosa!=null){rosa[0].add(reads, ln.id);} | |
69 | |
70 for(Read r : reads){ | |
71 readsIn+=r.pairCount(); | |
72 basesIn+=r.pairLength(); | |
73 } | |
74 | |
75 cris.returnList(ln); | |
76 | |
77 ln=cris.nextList(); | |
78 reads=(ln!=null ? ln.list : null); | |
79 } | |
80 | |
81 if(ln!=null){ | |
82 cris.returnList(ln.id, ln.list==null || ln.list.isEmpty()); | |
83 } | |
84 } | |
85 | |
86 public void processMulti(ConcurrentReadInputStream cris){ | |
87 final int groups=rosa.length; | |
88 | |
89 @SuppressWarnings("unchecked") | |
90 final ArrayList<Read>[] out=new ArrayList[groups]; | |
91 for(int i=0; i<out.length; i++){ | |
92 out[i]=new ArrayList<Read>(); | |
93 } | |
94 | |
95 ListNum<Read> ln=cris.nextList(); | |
96 ArrayList<Read> reads=(ln!=null ? ln.list : null); | |
97 | |
98 while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning | |
99 for(Read r : reads){ | |
100 long kmer=kc.hash(r, null, 0, false); | |
101 int group=(int)(kmer%groups); | |
102 out[group].add(r); | |
103 | |
104 readsIn+=r.pairCount(); | |
105 basesIn+=r.pairLength(); | |
106 } | |
107 for(int group=0; group<groups; group++){ | |
108 rosa[group].add(out[group], ln.id); | |
109 out[group]=new ArrayList<Read>(); | |
110 } | |
111 | |
112 cris.returnList(ln); | |
113 | |
114 ln=cris.nextList(); | |
115 reads=(ln!=null ? ln.list : null); | |
116 } | |
117 | |
118 if(ln!=null){ | |
119 cris.returnList(ln.id, ln.list==null || ln.list.isEmpty()); | |
120 } | |
121 } | |
122 | |
123 long readsIn=0; | |
124 long basesIn=0; | |
125 | |
126 // final FileFormat ffin1; | |
127 // final FileFormat ffin2; | |
128 ConcurrentReadInputStream cris; | |
129 ConcurrentReadOutputStream[] rosa; | |
130 final KmerComparator kc; | |
131 final boolean sortByName; | |
132 | |
133 boolean errorState=false; | |
134 | |
135 } |