sequence.getStart() in findTrueIndex
[jalview.git] / src / MCview / PDBChain.java
index a9d2d3a..1b65c48 100755 (executable)
@@ -33,6 +33,7 @@ public class PDBChain {
      * SequenceFeature group for PDB File features added to sequences
      */
     private static final String PDBFILEFEATURE = "PDBFile";
+    private static final String IEASTATUS = "IEA:jalview";
     public String id;
     public Vector bonds = new Vector();
     public Vector atoms = new Vector();
@@ -44,8 +45,9 @@ public class PDBChain {
     public int pdbend = 0;
     public int seqstart = 0;
     public int seqend = 0;
-
-    public PDBChain(String id) {
+    public String pdbid="";
+    public PDBChain(String pdbid, String id) {
+        this.pdbid=pdbid.toLowerCase();
         this.id = id;
     }
 
@@ -93,29 +95,36 @@ public class PDBChain {
     /**
      * copy over the RESNUM seqfeatures from the internal chain sequence to the mapped sequence
      * @param seq
+     * @param status The Status of the transferred annotation
+     * @return the features added to sq (or its dataset)
      */
-    public void transferRESNUMFeatures(SequenceI seq, String status) {
-        if (seq != sequence) {
-            /** SequenceFeature[] seqsfeatures=seq.getSequenceFeatures();
+    public SequenceFeature[] transferRESNUMFeatures(SequenceI seq, String status) {
+        SequenceI sq = seq;
+        while (sq!=null) {
+            if (sq==sequence)
+                return null;
+            sq = sq.getDatasetSequence();
+        }
+        /** 
+         * Remove any existing features for this chain if they exist ?
+         * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures();
             int totfeat=seqsfeatures.length;
             // Remove any features for this exact chain ?
             for (int i=0; i<seqsfeatures.length; i++) {
-                
             } */
-            if (status==null)
-                status = "IEA:jalview";
-            SequenceFeature[] features = sequence.getSequenceFeatures();
-            for (int i=0; i<features.length; i++) {
-                if (features[i].getFeatureGroup().equals(PDBChain.PDBFILEFEATURE)) {
-                    SequenceFeature tx = new SequenceFeature(features[i]);
-                    tx.setBegin(1+((Atom)((Residue)residues.elementAt(tx.getBegin()-offset)).atoms.elementAt(0)).alignmentMapping);
-                    tx.setEnd(1+((Atom)((Residue)residues.elementAt(tx.getEnd()-offset)).atoms.elementAt(0)).alignmentMapping);
-                    tx.setStatus(status+((tx.getStatus()==null || tx.getStatus().length()==0) ? "" : ":"+tx.getStatus()));
-                    seq.getDatasetSequence().addSequenceFeature(tx);
-                }
+        if (status==null)
+            status = PDBChain.IEASTATUS;
+        SequenceFeature[] features = sequence.getSequenceFeatures();
+        for (int i=0; i<features.length; i++) {
+            if (features[i].getFeatureGroup().equals(PDBChain.PDBFILEFEATURE)) {
+                SequenceFeature tx = new SequenceFeature(features[i]);
+                tx.setBegin(1+((Atom)((Residue)residues.elementAt(tx.getBegin()-offset)).atoms.elementAt(0)).alignmentMapping);
+                tx.setEnd(1+((Atom)((Residue)residues.elementAt(tx.getEnd()-offset)).atoms.elementAt(0)).alignmentMapping);
+                tx.setStatus(status+((tx.getStatus()==null || tx.getStatus().length()==0) ? "" : ":"+tx.getStatus()));
+                seq.addSequenceFeature(tx);
             }
-            
         }
+        return features;
     }
 
     public void makeCaBondList()
@@ -194,7 +203,7 @@ public class PDBChain {
             Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
             // Make A new SequenceFeature for the current residue numbering
             SequenceFeature sf = 
-                new SequenceFeature("RESNUM",tmpat.resName+":"+tmpat.resNumIns,
+                new SequenceFeature("RESNUM",tmpat.resName+":"+tmpat.resNumIns+" "+pdbid+id,
                         "",offset+count,offset+count,MCview.PDBChain.PDBFILEFEATURE);
             resFeatures.addElement(sf);
             // Keep totting up the sequence
@@ -214,7 +223,7 @@ public class PDBChain {
         if(id.length()<1 || id.equals(" "))
            id = "_";
         
-        sequence = new Sequence(id, seq.toString(), offset, resNumber); // resNumber-offset ~= seq.size() 
+        sequence = new Sequence(id, seq.toString(), offset, resNumber-1); // Note: resNumber-offset ~= seq.size() 
       //  System.out.println("PDB Sequence is :\nSequence = " + seq);
      //   System.out.println("No of residues = " + residues.size());
         for (i=0,iSize=resFeatures.size(); i<iSize; i++) {