File: CheckSequence.java

package info (click to toggle)
proalign 0.603-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 492 kB
  • sloc: java: 8,673; sh: 27; makefile: 4
file content (81 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
 * Title:        ProAlign<p>
 * Description:  <p>
 * Copyright:    Copyright (c) Ari Loytynoja<p>
 * License:      GNU GENERAL PUBLIC LICENSE<p>
 * @see          http://www.gnu.org/copyleft/gpl.html
 * Company:      ULB<p>
 * @author Ari Loytynoja
 * @version 1.0
 */
package proalign;

import java.util.HashMap;
import java.util.Iterator;

public class CheckSequence {

    String error = new String("");
    String alphabet;
    CheckSequence() { 
	ProAlign.log("CheckSequence");
    }

    boolean isDna(HashMap seqs) {
	
	Iterator seqKeys = seqs.keySet().iterator();	
	String name, seq;
	int acgt = 0, total = 0;
	
	while(seqKeys.hasNext()) {
	    name = (String) seqKeys.next();
	    seq = (String) seqs.get(name);
	    
	    for(int i=0; i<seq.length(); i++) {
		if(seq.charAt(i)=='A') {
		    acgt++;
		} else if(seq.charAt(i)=='C') {
		    acgt++;
		} else if(seq.charAt(i)=='G') {
		    acgt++;
		} else if(seq.charAt(i)=='T') {
		    acgt++;
		} else if(seq.charAt(i)=='U') {
		    acgt++;
		}
		total++;
	    }
	}
	if(((double) acgt/(double) total)>0.9d) {
	    return true;
	}
	return false;
    }

    boolean isFromAlphabet(HashMap seqs,String alphabet) {

	boolean isFine = true;
	Iterator seqKeys = seqs.keySet().iterator();	
	String name, seq;

	while(seqKeys.hasNext()) {
	    name = (String) seqKeys.next();
	    seq = (String) seqs.get(name);
	    
	    for(int i=0; i<seq.length(); i++) {
		if(alphabet.indexOf(seq.charAt(i))<0) {
		    isFine = false;
		    error += "\n "+name+": '"+seq.charAt(i)+
			"' is not from alphabet '"+alphabet+"'!";
		    ProAlign.log.print("\n "+name+": '"+seq.charAt(i)+
				       "' is not from alphabet '"+alphabet+"'!");	
		} 
	    }
	}
	return isFine;
    }

    String getError() {
	return error;
    }
}