~ubuntu-branches/ubuntu/saucy/trimmomatic/saucy-proposed

« back to all changes in this revision

Viewing changes to src/org/usadellab/trimmomatic/fastq/trim/BarcodeSplitter.java

  • Committer: Package Import Robot
  • Author(s): Andreas Tille, Olivier Sallou
  • Date: 2013-08-07 12:14:33 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130807121433-qxchmfrrodridtvz
Tags: 0.30+dfsg-1
* New upstream version
* debian/copyright:
   - DEP5
   - Add Files-Excluded to document what was removed from original source
* debian/watch: handle +dfsg suffix
* debian/get-orig-source: use new uscan if available
* debian/control:
   - cme fix dpkg-control
   - debhelper 9
   - use anonscm in Vcs fields
   - Build-Depends: default-jdk | ...
     Closes: #718850
[ Olivier Sallou]
    * Manage java libs with javahelper
    * Provide upstream missing MANIFEST.MF

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * To change this template, choose Tools | Templates
3
 
 * and open the template in the editor.
4
 
 */
5
 
package org.usadellab.trimmomatic.fastq.trim;
6
 
 
7
 
import java.io.File;
8
 
import java.io.IOException;
9
 
import java.util.HashMap;
10
 
import org.usadellab.trimmomatic.fastq.FastqRecord;
11
 
 
12
 
/**
13
 
 *
14
 
 * @author marc
15
 
 */
16
 
public class BarcodeSplitter extends AbstractSingleRecordTrimmer {
17
 
 
18
 
    private HashMap<String, String> barcodes;
19
 
    private int maxMisMatch = 0;
20
 
    private boolean clipOffBarcodes = true;    
21
 
 
22
 
    public BarcodeSplitter(HashMap<String, String> barcodes, int mism, boolean clip) {
23
 
        this.barcodes = barcodes;
24
 
        this.maxMisMatch = mism;
25
 
        this.clipOffBarcodes = clip;
26
 
    }
27
 
    
28
 
    public HashMap<String, String> getBarcodeMap() {
29
 
        return barcodes;
30
 
    }
31
 
 
32
 
    @Override
33
 
    public FastqRecord processRecord(FastqRecord entry) {
34
 
        
35
 
        String seq = entry.getSequence();
36
 
        
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))) {
41
 
                    
42
 
                    if (clipOffBarcodes) {
43
 
                    FastqRecord outentry = new FastqRecord(entry, codeLength, seq.length() - codeLength);
44
 
                        outentry.setBarcodeLabel(label);                    
45
 
                        return outentry;
46
 
                    } else {
47
 
                        entry.setBarcodeLabel(label);                    
48
 
                        return entry;
49
 
                    }
50
 
                }
51
 
            } else {
52
 
                if (getMisMatches(barcodes.get(label), entry.getSequence(), barcodes.get(label).length()) <= maxMisMatch) {
53
 
                    
54
 
                    if (clipOffBarcodes) {
55
 
                    FastqRecord outentry = new FastqRecord(entry, codeLength, seq.length() - codeLength);
56
 
                        outentry.setBarcodeLabel(label);                    
57
 
                        return outentry;
58
 
                    } else {
59
 
                        entry.setBarcodeLabel(label);                    
60
 
                        return entry;
61
 
                    }
62
 
                }
63
 
            }
64
 
        }        
65
 
        // entry did not match any barcodes - write to UNKNOWN
66
 
        entry.setBarcodeLabel("UNKNOWN");
67
 
        return entry;
68
 
    }
69
 
 
70
 
    private int getMisMatches(String a, String b, int range) {
71
 
        int mismatch = 0;
72
 
        for (int i = 0; i < range; i++) {
73
 
            mismatch += (a.charAt(i) == b.charAt(i)) ? 0 : 1;
74
 
        }
75
 
        return mismatch;
76
 
    }
77
 
}