git://source.jalview.org
/
jalview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Set startRes 0 for switch to wrap view
[jalview.git]
/
src
/
jalview
/
datamodel
/
Sequence.java
diff --git
a/src/jalview/datamodel/Sequence.java
b/src/jalview/datamodel/Sequence.java
index
b1a1be2
..
4687116
100755
(executable)
--- a/
src/jalview/datamodel/Sequence.java
+++ b/
src/jalview/datamodel/Sequence.java
@@
-18,7
+18,6
@@
*/
package jalview.datamodel;
*/
package jalview.datamodel;
-import java.awt.*;
import java.util.*;
import java.util.*;
@@
-33,11
+32,10
@@
public class Sequence implements SequenceI
{
SequenceI datasetSequence;
String name;
{
SequenceI datasetSequence;
String name;
- private String sequence;
+ private char [] sequence;
String description;
int start;
int end;
String description;
int start;
int end;
- Color color = Color.white;
Vector pdbIds;
String vamsasId;
DBRefEntry[] dbrefs;
Vector pdbIds;
String vamsasId;
DBRefEntry[] dbrefs;
@@
-65,12
+63,20
@@
public class Sequence implements SequenceI
public Sequence(String name, String sequence, int start, int end)
{
this.name = name;
public Sequence(String name, String sequence, int start, int end)
{
this.name = name;
- this.sequence = sequence;
+ this.sequence = sequence.toCharArray();
this.start = start;
this.end = end;
this.start = start;
this.end = end;
-
parseId();
parseId();
+ checkValidRange();
+ }
+ public Sequence(String name, char [] sequence, int start, int end)
+ {
+ this.name = name;
+ this.sequence = sequence;
+ this.start = start;
+ this.end = end;
+ parseId();
checkValidRange();
}
checkValidRange();
}
@@
-97,11
+103,9
@@
public class Sequence implements SequenceI
if (end < 1)
{
int endRes = 0;
if (end < 1)
{
int endRes = 0;
- char ch;
- for (int j = 0; j < sequence.length(); j++)
+ for (int j = 0; j < sequence.length; j++)
{
{
- ch = sequence.charAt(j);
- if (!jalview.util.Comparison.isGap( (ch)))
+ if (!jalview.util.Comparison.isGap( sequence[j] ))
{
endRes++;
}
{
endRes++;
}
@@
-329,7
+333,7
@@
public class Sequence implements SequenceI
*/
public int getLength()
{
*/
public int getLength()
{
- return this.sequence.length();
+ return this.sequence.length;
}
/**
}
/**
@@
-339,18
+343,25
@@
public class Sequence implements SequenceI
*/
public void setSequence(String seq)
{
*/
public void setSequence(String seq)
{
- this.sequence = seq;
+ this.sequence = seq.toCharArray();
checkValidRange();
}
checkValidRange();
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getSequence()
+
+ public String getSequenceAsString()
+ {
+ return new String(sequence);
+ }
+
+ public String getSequenceAsString(int start, int end)
+ {
+ return new String(getSequence(start, end));
+ }
+
+
+ public char [] getSequence()
{
{
- return this.sequence;
+ return sequence;
}
/**
}
/**
@@
-361,22
+372,26
@@
public class Sequence implements SequenceI
*
* @return DOCUMENT ME!
*/
*
* @return DOCUMENT ME!
*/
- public String getSequence(int start, int end)
+ public char [] getSequence(int start, int end)
{
// JBPNote - left to user to pad the result here (TODO:Decide on this policy)
{
// JBPNote - left to user to pad the result here (TODO:Decide on this policy)
- if (start >= sequence.length())
+ if (start >= sequence.length)
{
{
- return "";
+ System.out.println("DOES THIS GET CALLED???");
}
}
- if (end >= sequence.length())
+ if (end >= sequence.length)
{
{
- end = sequence.length();
+ end = sequence.length;
}
}
- return this.sequence.substring(start, end);
+ char [] reply = new char[end-start];
+ System.arraycopy(sequence, start, reply, 0, end-start);
+
+ return reply;
}
}
+
/**
* make a new Sequence object from start to end (including gaps) over this seqeunce
* @param start int
/**
* make a new Sequence object from start to end (including gaps) over this seqeunce
* @param start int
@@
-387,13
+402,14
@@
public class Sequence implements SequenceI
{
if (start < 0)
start = 0;
{
if (start < 0)
start = 0;
- String seq = getSequence(start, end);
- if (seq == "")
+ char [] seq = getSequence(start, end);
+ if (seq.length == 0)
return null;
int nstart = findPosition(start);
int nend = findPosition(end) - 1;
// JBPNote - this is an incomplete copy.
SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
return null;
int nstart = findPosition(start);
int nend = findPosition(end) - 1;
// JBPNote - this is an incomplete copy.
SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
+ nseq.setDescription(description);
nseq.setDatasetSequence(getDatasetSequence());
return nseq;
}
nseq.setDatasetSequence(getDatasetSequence());
return nseq;
}
@@
-407,9
+423,9
@@
public class Sequence implements SequenceI
*/
public char getCharAt(int i)
{
*/
public char getCharAt(int i)
{
- if (i < sequence.length())
+ if (i < sequence.length)
{
{
- return sequence.charAt(i);
+ return sequence[i];
}
else
{
}
else
{
@@
-450,9
+466,9
@@
public class Sequence implements SequenceI
int j = start;
int i = 0;
int j = start;
int i = 0;
- while ( (i < sequence.length()) && (j <= end) && (j <= pos))
+ while ( (i < sequence.length) && (j <= end) && (j <= pos))
{
{
- if (!jalview.util.Comparison.isGap(sequence.charAt(i)))
+ if (!jalview.util.Comparison.isGap(sequence[i]))
{
j++;
}
{
j++;
}
@@
-481,10
+497,10
@@
public class Sequence implements SequenceI
{
int j = 0;
int pos = start;
{
int j = 0;
int pos = start;
- int seqlen = sequence.length();
+ int seqlen = sequence.length;
while ( (j < i) && (j < seqlen))
{
while ( (j < i) && (j < seqlen))
{
- if (!jalview.util.Comparison.isGap( (sequence.charAt(j))))
+ if (!jalview.util.Comparison.isGap( sequence[j] ))
{
pos++;
}
{
pos++;
}
@@
-503,14
+519,14
@@
public class Sequence implements SequenceI
public int[] gapMap()
{
String seq = jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.
public int[] gapMap()
{
String seq = jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.
- GapChars, sequence);
+ GapChars, new String(sequence));
int[] map = new int[seq.length()];
int j = 0;
int p = 0;
int[] map = new int[seq.length()];
int j = 0;
int p = 0;
- while (j < sequence.length())
+ while (j < sequence.length)
{
{
- if (!jalview.util.Comparison.isGap(sequence.charAt(j)))
+ if (!jalview.util.Comparison.isGap(sequence[j]))
{
map[p++] = j;
}
{
map[p++] = j;
}
@@
-525,38
+541,30
@@
public class Sequence implements SequenceI
* DOCUMENT ME!
*
* @param i DOCUMENT ME!
* DOCUMENT ME!
*
* @param i DOCUMENT ME!
- */
- public void deleteCharAt(int i)
- {
- if (i >= sequence.length())
- {
- return;
- }
-
- sequence = sequence.substring(0, i) + sequence.substring(i + 1);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
* @param j DOCUMENT ME!
*/
public void deleteChars(int i, int j)
{
* @param j DOCUMENT ME!
*/
public void deleteChars(int i, int j)
{
- if (i >= sequence.length())
+ if (i >= sequence.length)
{
return;
}
{
return;
}
- if (j >= sequence.length())
+ char [] tmp;
+
+ if (j >= sequence.length)
{
{
- sequence = sequence.substring(0, i);
+ tmp = new char[i];
+ System.arraycopy(sequence,0,tmp,0,i);
}
else
{
}
else
{
- sequence = sequence.substring(0, i) + sequence.substring(j);
+ tmp = new char[sequence.length-j+i];
+ System.arraycopy(sequence,0,tmp,0,i);
+ System.arraycopy(sequence,j,tmp,i,sequence.length-j);
}
}
+
+ sequence = tmp;
}
/**
}
/**
@@
-568,27
+576,32
@@
public class Sequence implements SequenceI
*/
public void insertCharAt(int i, int length, char c)
{
*/
public void insertCharAt(int i, int length, char c)
{
- StringBuffer tmp;
+ char [] tmp = new char[sequence.length+length];
- if (i >= sequence.length())
+ if (i >= sequence.length)
{
{
- tmp = new StringBuffer(sequence);
+ System.arraycopy(sequence, 0, tmp, 0, sequence.length);
+ i = sequence.length;
}
else
}
else
- tmp = new StringBuffer(sequence.substring(0, i));
+ {
+ System.arraycopy(sequence, 0, tmp, 0, i);
+ }
+
+ int index = i;
while (length > 0)
{
while (length > 0)
{
- tmp.append(c);
+ tmp[ index++ ] = c;
length--;
}
length--;
}
- if (i < sequence.length())
+ if (i < sequence.length)
{
{
- tmp.append(sequence.substring(i));
+ System.arraycopy(sequence, i, tmp, index, sequence.length-i );
}
}
- sequence = tmp.toString();
+ sequence = tmp;
}
public void insertCharAt(int i, char c)
}
public void insertCharAt(int i, char c)
@@
-596,26
+609,6
@@
public class Sequence implements SequenceI
insertCharAt(i, 1, c);
}
insertCharAt(i, 1, c);
}
- /**
- * DOCUMENT ME!
- *
- * @param c DOCUMENT ME!
- */
- public void setColor(Color c)
- {
- this.color = c;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Color getColor()
- {
- return color;
- }
-
public String getVamsasId()
{
return vamsasId;
public String getVamsasId()
{
return vamsasId;
@@
-641,9
+634,18
@@
public class Sequence implements SequenceI
if (dbrefs == null)
dbrefs = new DBRefEntry[0];
if (dbrefs == null)
dbrefs = new DBRefEntry[0];
- DBRefEntry[] temp = new DBRefEntry[dbrefs.length + 1];
- System.arraycopy(dbrefs, 0, temp, 0, dbrefs.length);
+ int i, iSize = dbrefs.length;
+
+ for(i=0; i<iSize; i++)
+ if(dbrefs[i].getAccessionId().equals(entry.getAccessionId())
+ && dbrefs[i].getSource().equals(entry.getSource())
+ && dbrefs[i].getVersion().equals(entry.getVersion()))
+ {
+ return;
+ }
+ DBRefEntry[] temp = new DBRefEntry[iSize + 1];
+ System.arraycopy(dbrefs, 0, temp, 0, iSize);
temp[temp.length - 1] = entry;
dbrefs = temp;
temp[temp.length - 1] = entry;
dbrefs = temp;