2
* To change this template, choose Tools | Templates
3
* and open the template in the editor.
5
package org.usadellab.trimmomatic.fastq.trim;
8
import java.io.IOException;
9
import java.util.HashMap;
10
import org.usadellab.trimmomatic.fastq.FastqRecord;
16
public class BarcodeSplitter extends AbstractSingleRecordTrimmer {
18
private HashMap<String, String> barcodes;
19
private int maxMisMatch = 0;
20
private boolean clipOffBarcodes = true;
22
public BarcodeSplitter(HashMap<String, String> barcodes, int mism, boolean clip) {
23
this.barcodes = barcodes;
24
this.maxMisMatch = mism;
25
this.clipOffBarcodes = clip;
28
public HashMap<String, String> getBarcodeMap() {
33
public FastqRecord processRecord(FastqRecord entry) {
35
String seq = entry.getSequence();
37
for (String label : barcodes.keySet()) {
38
int codeLength = barcodes.get(label).length();
39
if (maxMisMatch == 0) {
40
if (entry.getSequence().startsWith(barcodes.get(label))) {
42
if (clipOffBarcodes) {
43
FastqRecord outentry = new FastqRecord(entry, codeLength, seq.length() - codeLength);
44
outentry.setBarcodeLabel(label);
47
entry.setBarcodeLabel(label);
52
if (getMisMatches(barcodes.get(label), entry.getSequence(), barcodes.get(label).length()) <= maxMisMatch) {
54
if (clipOffBarcodes) {
55
FastqRecord outentry = new FastqRecord(entry, codeLength, seq.length() - codeLength);
56
outentry.setBarcodeLabel(label);
59
entry.setBarcodeLabel(label);
65
// entry did not match any barcodes - write to UNKNOWN
66
entry.setBarcodeLabel("UNKNOWN");
70
private int getMisMatches(String a, String b, int range) {
72
for (int i = 0; i < range; i++) {
73
mismatch += (a.charAt(i) == b.charAt(i)) ? 0 : 1;