File Parsing returns Alignments, not Sequence[]
[jalview.git] / src / jalview / gui / SequenceFetcher.java
index f4e289b..cb41e6e 100755 (executable)
@@ -286,7 +286,7 @@ public class SequenceFetcher
       }
 
       //Then read in the features and apply them to the dataset
-      SequenceI[] sequence = parseResult(result.toString(), null);
+      Alignment al = parseResult(result.toString(), null);
       for (int i = 0; i < entries.size(); i++)
       {
         UniprotEntry entry = (UniprotEntry) entries.elementAt(i);
@@ -304,7 +304,7 @@ public class SequenceFetcher
         Enumeration en2 = entry.getAccession().elements();
         while (en2.hasMoreElements())
         {
-          sequence[i].getDatasetSequence().addDBRef(new DBRefEntry(DBRefSource.UNIPROT,
+          al.getSequenceAt(i).getDatasetSequence().addDBRef(new DBRefEntry(DBRefSource.UNIPROT,
                     "0",
                     en2.nextElement().toString()));
         }
@@ -312,7 +312,7 @@ public class SequenceFetcher
 
 
 
-        sequence[i].getDatasetSequence().setPDBId(onlyPdbEntries);
+        al.getSequenceAt(i).getDatasetSequence().setPDBId(onlyPdbEntries);
         if (entry.getFeature() != null)
         {
           e = entry.getFeature().elements();
@@ -320,7 +320,7 @@ public class SequenceFetcher
           {
             SequenceFeature sf = (SequenceFeature) e.nextElement();
             sf.setFeatureGroup("Uniprot");
-            sequence[i].getDatasetSequence().addSequenceFeature( sf );
+            al.getSequenceAt(i).getDatasetSequence().addSequenceFeature( sf );
           }
         }
       }
@@ -370,23 +370,23 @@ public class SequenceFetcher
     return result;
   }
 
-  SequenceI[] parseResult(String result, String title)
+  Alignment parseResult(String result, String title)
   {
     String format = new IdentifyFile().Identify(result, "Paste");
-    SequenceI[] sequences = null;
+    Alignment al = null;
 
     if (FormatAdapter.isValidFormat(format))
     {
-      sequences = null;
-      try{ sequences = new FormatAdapter().readFile(result.toString(), "Paste",
+
+      try{ al = new FormatAdapter().readFile(result.toString(), "Paste",
                                                format);}
       catch(Exception ex){}
 
-      if (sequences != null && sequences.length > 0)
+      if (al != null && al.getHeight() > 0)
       {
         if (alignFrame == null)
         {
-          AlignFrame af = new AlignFrame(new Alignment(sequences),
+          AlignFrame af = new AlignFrame(al,
                                            AlignFrame.DEFAULT_WIDTH,
                                            AlignFrame.DEFAULT_HEIGHT
 );
@@ -408,19 +408,19 @@ public class SequenceFetcher
         }
         else
         {
-          for (int i = 0; i < sequences.length; i++)
+          for (int i = 0; i < al.getHeight(); i++)
           {
-            alignFrame.viewport.alignment.addSequence(sequences[i]);
+            alignFrame.viewport.alignment.addSequence(al.getSequenceAt(i));
 
             ////////////////////////////
             //Dataset needs extension;
             /////////////////////////////
-            Sequence ds = new Sequence(sequences[i].getName(),
+            Sequence ds = new Sequence(al.getSequenceAt(i).getName(),
                                        AlignSeq.extractGaps("-. ",
-                sequences[i].getSequenceAsString()),
-                                       sequences[i].getStart(),
-                                       sequences[i].getEnd());
-            sequences[i].setDatasetSequence(ds);
+                al.getSequenceAt(i).getSequenceAsString()),
+                                       al.getSequenceAt(i).getStart(),
+                                       al.getSequenceAt(i).getEnd());
+            al.getSequenceAt(i).setDatasetSequence(ds);
             alignFrame.viewport.alignment.getDataset().addSequence(ds);
           }
           alignFrame.viewport.setEndSeq(alignFrame.viewport.alignment.
@@ -436,12 +436,12 @@ public class SequenceFetcher
         {
           // Parse out the ids from the structured names
           boolean errors = false;
-          for (int i = 0; i < sequences.length; i++)
+          for (int i = 0; i < al.getHeight(); i++)
           {
             PDBEntry entry = new PDBEntry();
             com.stevesoft.pat.Regex idbits = new com.stevesoft.pat.Regex(
                 "PDB\\|([0-9A-z]{4})\\|(.)");
-            if (idbits.search(sequences[i].getName()))
+            if (idbits.search(al.getSequenceAt(i).getName()))
             {
               String pdbid = idbits.substring(1);
               String pdbccode = idbits.substring(2);
@@ -451,14 +451,14 @@ public class SequenceFetcher
                 entry.setProperty(new Hashtable());
               entry.getProperty().put("chains",
                                       pdbccode
-                                      + "=" + sequences[i].getStart()
-                                      + "-" + sequences[i].getEnd());
-              sequences[i].getDatasetSequence().addPDBId(entry);
+                                      + "=" + al.getSequenceAt(i).getStart()
+                                      + "-" + al.getSequenceAt(i).getEnd());
+              al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
 
               // We make a DBRefEtntry because we have obtained the PDB file from a verifiable source
               // JBPNote - PDB DBRefEntry should also carry the chain and mapping information
               DBRefEntry dbentry = new DBRefEntry(jalview.datamodel.DBRefSource.PDB,"0",pdbid);
-              sequences[i].getDatasetSequence().addDBRef(dbentry);
+              al.getSequenceAt(i).getDatasetSequence().addDBRef(dbentry);
             }
             else
             {
@@ -466,7 +466,7 @@ public class SequenceFetcher
               // that the user should know about.
               jalview.bin.Cache.log.warn(
                   "No PDBEntry constructed for sequence " + i + " : " +
-                  sequences[i].getName());
+                  al.getSequenceAt(i).getName());
               errors = true;
             }
           }
@@ -482,7 +482,7 @@ public class SequenceFetcher
                          + " from " + database.getSelectedItem());
     }
 
-    return sequences;
+    return al;
 
   }