-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastaRecord.java
More file actions
81 lines (62 loc) · 1.71 KB
/
FastaRecord.java
File metadata and controls
81 lines (62 loc) · 1.71 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
package dna;
public class FastaRecord implements DNARecord
{
//
// Add a precondition check: throw RecordGFormatException 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;
FastaRecord(String defline, String sequence) throws RecordFormatException
{
String first = defline.substring(0,1);
if(first.equals(">") == false) {
throw new RecordFormatException("The file does not start with the character >");
}
else {
this.defline = defline;
this.sequence = sequence;
}
}
// Initialize defline and sequence from the input record. The defline should be the
// defline of the fastq record, but with a '>' in the first position rather than a '@'.
// uses the replaceFirst() method of String API
public FastaRecord(FastqRecord q) {
defline = q.getDefline().replaceFirst("@",">");
sequence = q.getSequence();
}
//
// Provide the 2 methods that satisfy the interface.
//
public String getDefline() {
return this.defline;
}
public String getSequence() {
return this.sequence;
}
//
// Provide an equals() method.
//
public boolean equals(Object y) {
FastaRecord that = (FastaRecord)y;
if(this.defline.equals(that.getDefline()) == false) {
return false;
}
else {
if(this.sequence.equals(that.getSequence()) == false) {
return false;
}
else {
return true;
}
}
}
//
// Provide a hashCode() method that returns the sum of the hashcodes of
// defline and sequence.
//
public int hashCode() {
return defline.hashCode()+ sequence.hashCode();
}
}