/** * Copyright Copyright 2010-17 Simon Andrews * * This file is part of FastQC. * * FastQC is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * FastQC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with FastQC; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ package uk.ac.babraham.FastQC.Sequence.Contaminant; public class Contaminant { private String name; private char [] forward; private char [] reverse; public Contaminant (String name, String sequence) { this.name = name; sequence = sequence.toUpperCase(); forward = sequence.toCharArray(); reverse = new char[forward.length]; for (int c=0;c=8) { if ((new String(forward)).contains(query)) { return new ContaminantHit(this, ContaminantHit.FORWARD, query.length(), 100); } if ((new String(reverse)).contains(query)) { return new ContaminantHit(this, ContaminantHit.REVERSE, query.length(), 100); } } char [] q = query.toCharArray(); ContaminantHit bestHit = null; // We're going to allow only one mismatch and will require // a match of at least 20bp to consider this a match at all for (int offset=0-(forward.length-20);offsetbestHit.length()) { bestHit = thisHit; } } for (int offset=0-(forward.length-20);offsetbestHit.length()) { bestHit = thisHit; } } return bestHit; } private ContaminantHit findMatch (char [] ca, char [] cb, int offset, int direction) { ContaminantHit bestHit = null; int mismatchCount = 0; int start = 0; int end = 0; for (int i=0;i= cb.length) break; if (ca[i] == cb[i+offset]) { end = i; } else { ++mismatchCount; if (mismatchCount>1) { // That's the end of this match, see if it's worth recording if (1+(end-start) > 20) { int id = (((1+(end-start))-(mismatchCount-1))*100)/(1+(end-start)); if (bestHit == null || bestHit.length()< 1+(end-start) || (bestHit.length() == 1+(end-start) && bestHit.percentID() 20) { int id = (((1+(end-start))-mismatchCount)*100)/(1+(end-start)); if (bestHit == null || bestHit.length()< 1+(end-start) || (bestHit.length() == 1+(end-start) && bestHit.percentID()