-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastqRecord.java
More file actions
117 lines (97 loc) · 2.46 KB
/
FastqRecord.java
File metadata and controls
117 lines (97 loc) · 2.46 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package dna;
//
// FastqRecord contains the defline, sequence, and quality string, not the + line
// from a record in a fastq file.
//
public class FastqRecord implements DNARecord
{
//
// throws RecordFormatException if the 1st char of the defline is
// not '@'. You will have to change the ctor declaration to say that it throws
// the exception. The exception should contain a useful informative message.
//
private String defline;
private String sequence;
private String quality;
public FastqRecord(String defline, String sequence, String quality) throws RecordFormatException
{
String firstchar = defline.substring(0, 1);
if(firstchar.equals("@") == false)
{
throw new RecordFormatException("The fastq file you are using starts with an invalid char");
}
else
{
this.defline = defline;
this.sequence = sequence;
this.quality = quality;
}
}
//
// Provide the 2 methods that satisfy the interface.
//getDefline() returns a defline
//getSequence() returns the sequence of the record
public String getDefline() {
return this.defline;
}
public String getSequence() {
return this.sequence;
}
//
// Provide an equals() method that checks for deep equality of all 3 instance variables.
// When checking string variables, be sure to do it like this:
// this.defline.equals(that.defline)
// and not like this:
// this.defline == that.defline
//
public boolean equals(Object x) {
FastqRecord q = (FastqRecord)x;
if(this.defline.equals(q.defline)==false) {
return false;
}
else {
if(this.sequence.equals(q.sequence) == false) {
return false;
}
else {
if(this.quality.equals(q.quality) == false) {
return false;
}
else {
return true;
}
}
}
}
//
// Checks the 4th line of every fastq file to see if it satsifies the minimum quality
//
public boolean qualityIsLow()
{
String test1 = "#";
String test2 ="$";
int count1 = 0;
int count2 = 0;
for(int i = 0; i < quality.length();i++) {
if(test1.contains(quality.substring(i, i+1))==true) {
count1++;
}
else if(test2.contains(quality.substring(i, i+1))==true) {
count2++;
}
}
if(count1 > 0 && count2 >0) {
return true;
}
else {
return false;
}
}
//
// Complete this. Return the sum of the hash codes of defline, sequence, and quality.
//
public int hashCode()
{
return defline.hashCode() + quality.hashCode() + sequence.hashCode();
}
}