Skip to content

Commit e1a3676

Browse files
committed
Formatted according to best practices
1 parent a231c94 commit e1a3676

144 files changed

Lines changed: 2786 additions & 3589 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/org/usadellab/trimmomatic/Pairomatic.java

Lines changed: 69 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -10,122 +10,110 @@
1010
import org.usadellab.trimmomatic.fastq.FastqRecord;
1111
import org.usadellab.trimmomatic.fastq.FastqSerializer;
1212

13-
public class Pairomatic
14-
{
13+
public class Pairomatic {
1514

1615
/**
1716
* Pairomatic: The FASTQ pair/unpairer
1817
*/
1918

20-
public Pairomatic()
21-
{
19+
public Pairomatic() {
2220

2321
}
2422

25-
private Set<String> getFastqNames(File file, Character delimiter) throws IOException
26-
{
23+
private Set<String> getFastqNames(File file, Character delimiter) throws IOException {
2724
Set<String> names = new LinkedHashSet<String>();
2825

2926
FastqParser parser = new FastqParser(0);
3027
parser.open(file);
3128

32-
while (parser.hasNext())
33-
{
29+
while (parser.hasNext()) {
3430
FastqRecord rec = parser.next();
3531

3632
String name = rec.getName();
3733

38-
if (delimiter != null)
39-
{
34+
if (delimiter != null) {
4035
int index = name.lastIndexOf(delimiter);
4136

4237
if (index == -1)
4338
throw new RuntimeException("Error: Failed to find expected delimiter '" + delimiter
4439
+ "' in record named '" + name + "'");
4540

4641
name = name.substring(0, index);
47-
}
48-
49-
if(names.contains(name))
50-
throw new RuntimeException("Error: Found "+name+" more than once in file - check delimiter is correct '"+delimiter+"'");
51-
52-
names.add(name);
5342
}
5443

44+
if (names.contains(name))
45+
throw new RuntimeException("Error: Found " + name
46+
+ " more than once in file - check delimiter is correct '" + delimiter + "'");
47+
48+
names.add(name);
49+
}
50+
5551
return names;
5652
}
5753

58-
59-
private boolean equalOrdering(Set<String> set1, Set<String> set2)
60-
{
61-
if(set1.size()!=set2.size())
54+
private boolean equalOrdering(Set<String> set1, Set<String> set2) {
55+
if (set1.size() != set2.size())
6256
return false;
63-
64-
Iterator<String> iter1=set1.iterator();
65-
Iterator<String> iter2=set2.iterator();
66-
67-
while(iter1.hasNext() && iter2.hasNext())
68-
{
69-
String str1=iter1.next();
70-
String str2=iter2.next();
71-
72-
if(!str1.equals(str2))
57+
58+
Iterator<String> iter1 = set1.iterator();
59+
Iterator<String> iter2 = set2.iterator();
60+
61+
while (iter1.hasNext() && iter2.hasNext()) {
62+
String str1 = iter1.next();
63+
String str2 = iter2.next();
64+
65+
if (!str1.equals(str2))
7366
return false;
74-
}
75-
76-
if(iter1.hasNext())
67+
}
68+
69+
if (iter1.hasNext())
7770
return false;
78-
79-
if(iter2.hasNext())
71+
72+
if (iter2.hasNext())
8073
return false;
81-
74+
8275
return true;
8376
}
84-
85-
77+
8678
private void splitFastq(File input, File match, File unmatch, Set<String> toKeep, Character delimiter)
87-
throws IOException
88-
{
79+
throws IOException {
8980
FastqParser parser = new FastqParser(0);
9081
parser.open(input);
9182

92-
FastqSerializer matchSerializer=new FastqSerializer();
83+
FastqSerializer matchSerializer = new FastqSerializer();
9384
matchSerializer.open(match);
94-
95-
FastqSerializer unmatchSerializer=new FastqSerializer();
85+
86+
FastqSerializer unmatchSerializer = new FastqSerializer();
9687
unmatchSerializer.open(unmatch);
97-
98-
while (parser.hasNext())
99-
{
88+
89+
while (parser.hasNext()) {
10090
FastqRecord rec = parser.next();
10191

10292
String name = rec.getName();
10393

104-
if (delimiter != null)
105-
{
94+
if (delimiter != null) {
10695
int index = name.indexOf(delimiter);
10796

10897
if (index == -1)
109-
throw new RuntimeException("Failed to find expected delimiter '" + delimiter
110-
+ "' in record named '" + name + "'");
98+
throw new RuntimeException(
99+
"Failed to find expected delimiter '" + delimiter + "' in record named '" + name + "'");
111100

112101
name = name.substring(0, index);
113-
}
114-
115-
if(toKeep.contains(name))
102+
}
103+
104+
if (toKeep.contains(name))
116105
matchSerializer.writeRecord(rec);
117106
else
118107
unmatchSerializer.writeRecord(rec);
119-
}
120-
108+
}
109+
121110
matchSerializer.close();
122111
unmatchSerializer.close();
123112

124113
}
125114

126115
public void process(File input1, File input2, File output1P, File output1U, File output2P, File output2U,
127-
Character delimiter) throws IOException
128-
{
116+
Character delimiter) throws IOException {
129117
Set<String> names1 = getFastqNames(input1, delimiter);
130118
System.err.println("First input file contains " + names1.size() + " records");
131119

@@ -134,56 +122,49 @@ public void process(File input1, File input2, File output1P, File output1U, File
134122

135123
names1.retainAll(names2);
136124
System.err.println("Files shared " + names1.size() + " records");
137-
125+
138126
names2.retainAll(names1);
139-
if(!equalOrdering(names1,names2))
140-
{
127+
if (!equalOrdering(names1, names2)) {
141128
System.err.println("Error: Common records are not in identical order, cowardly refusing to do anything");
142129
return;
143-
}
144-
130+
}
131+
145132
System.err.println("Splitting first file");
146133
splitFastq(input1, output1P, output1U, names1, delimiter);
147-
134+
148135
System.err.println("Splitting second file");
149136
splitFastq(input2, output2P, output2U, names1, delimiter);
150-
137+
151138
System.err.println("All done");
152139
}
153140

154-
public static void main(String[] args) throws IOException
155-
{
141+
public static void main(String[] args) throws IOException {
156142
int argIndex = 0;
157-
Character delim=null;
158-
143+
Character delim = null;
144+
159145
boolean badOption = false;
160146

161-
while (argIndex < args.length && args[argIndex].startsWith("-"))
162-
{
147+
while (argIndex < args.length && args[argIndex].startsWith("-")) {
163148
String arg = args[argIndex++];
164-
if(arg.equals("-delim"))
165-
{
166-
String delimStr=args[argIndex++];
167-
168-
if(delimStr.length()!=1)
169-
System.err.println("Delimiter must be exactly one character, got '"+delimStr+"'");
149+
if (arg.equals("-delim")) {
150+
String delimStr = args[argIndex++];
151+
152+
if (delimStr.length() != 1)
153+
System.err.println("Delimiter must be exactly one character, got '" + delimStr + "'");
170154
else
171-
delim=delimStr.charAt(0);
172-
}
173-
else
174-
{
155+
delim = delimStr.charAt(0);
156+
} else {
175157
System.err.println("Unknown option " + arg);
176158
badOption = true;
177-
}
178159
}
160+
}
179161

180-
if (args.length - argIndex < 6 || badOption)
181-
{
182-
System.err
183-
.println("Usage: Pairomatic [-delim delimChar] <inputFile1> <inputFile2> <outputFile1P> <outputFile1U> <outputFile2P> <outputFile2U>");
162+
if (args.length - argIndex < 6 || badOption) {
163+
System.err.println(
164+
"Usage: Pairomatic [-delim delimChar] <inputFile1> <inputFile2> <outputFile1P> <outputFile1U> <outputFile2P> <outputFile2U>");
184165
System.exit(1);
185-
}
186-
166+
}
167+
187168
File input1 = new File(args[argIndex++]);
188169
File input2 = new File(args[argIndex++]);
189170

@@ -195,6 +176,6 @@ public static void main(String[] args) throws IOException
195176

196177
Pairomatic pm = new Pairomatic();
197178
pm.process(input1, input2, output1P, output1U, output2P, output2U, delim);
198-
179+
199180
}
200181
}

0 commit comments

Comments
 (0)