b235bcc5e80ec25680427b9906e5d5125cc361a0
[jalview.git] / src / jalview / io / AppletFormatAdapter.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  *
5  * This file is part of Jalview.
6  *
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * Jalview is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE.  See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.io;
22
23 import jalview.api.AlignExportSettingI;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.datamodel.Alignment;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.AlignmentView;
29 import jalview.gui.AlignmentPanel;
30 import jalview.util.MessageManager;
31
32 import java.io.File;
33 import java.io.InputStream;
34 import java.util.List;
35
36 /**
37  * A low level class for alignment and feature IO with alignment formatting
38  * methods used by both applet and application for generating flat alignment
39  * files. It also holds the lists of magic format names that the applet and
40  * application will allow the user to read or write files with.
41  *
42  * @author $author$
43  * @version $Revision$
44  */
45 public class AppletFormatAdapter
46 {
47   private AlignmentViewPanel viewpanel;
48
49   public static String FILE = "File";
50
51   public static String URL = "URL";
52
53   public static String PASTE = "Paste";
54
55   public static String CLASSLOADER = "ClassLoader";
56
57   /**
58    * add jalview-derived non-secondary structure annotation from PDB structure
59    */
60   boolean annotFromStructure = false;
61
62   /**
63    * add secondary structure from PDB data with built-in algorithms
64    */
65   boolean localSecondaryStruct = false;
66
67   /**
68    * process PDB data with web services
69    */
70   boolean serviceSecondaryStruct = false;
71
72   private AlignFile alignFile = null;
73
74   String inFile;
75
76   /**
77    * character used to write newlines
78    */
79   protected String newline = System.getProperty("line.separator");
80
81   private AlignExportSettingI exportSettings;
82
83   /**
84    * List of valid format strings used in the isValidFormat method
85    */
86   public static final String[] READABLE_FORMATS = new String[]
87   { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "STH",
88       "PDB", "JnetFile", "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, IdentifyFile.GFF3File,
89       "HTML" };
90
91   /**
92    * List of readable format file extensions by application in order
93    * corresponding to READABLE_FNAMES
94    */
95   public static final String[] READABLE_EXTENSIONS = new String[]
96   { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa",
97       "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT, JSONFile.FILE_EXT,
98       ".gff2,gff3",
99       "jar,jvp", HtmlFile.FILE_EXT };
100
101   /**
102    * List of readable formats by application in order corresponding to
103    * READABLE_EXTENSIONS
104    */
105   public static final String[] READABLE_FNAMES = new String[]
106   { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Stockholm",
107       "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, IdentifyFile.GFF3File, "Jalview",
108       HtmlFile.FILE_DESC };
109
110   /**
111    * List of valid format strings for use by callers of the formatSequences
112    * method
113    */
114   public static final String[] WRITEABLE_FORMATS = new String[]
115           { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "AMSA",
116     "STH", PhylipFile.FILE_DESC, JSONFile.FILE_DESC };
117
118   /**
119    * List of extensions corresponding to file format types in WRITABLE_FNAMES
120    * that are writable by the application.
121    */
122   public static final String[] WRITABLE_EXTENSIONS = new String[]
123   { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa",
124       "sto,stk", PhylipFile.FILE_EXT, JSONFile.FILE_EXT, "jvp" };
125
126   /**
127    * List of writable formats by the application. Order must correspond with the
128    * WRITABLE_EXTENSIONS list of formats.
129    */
130   public static final String[] WRITABLE_FNAMES = new String[]
131   { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "STH",
132       PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview" };
133
134   public static String INVALID_CHARACTERS = "Contains invalid characters";
135
136   // TODO: make these messages dynamic
137   public static String SUPPORTED_FORMATS = "Formats currently supported are\n"
138           + prettyPrint(READABLE_FORMATS);
139
140   public AppletFormatAdapter()
141   {
142   }
143
144   public AppletFormatAdapter(AlignmentViewPanel viewpanel)
145   {
146     this.viewpanel = viewpanel;
147   }
148
149   public AppletFormatAdapter(AlignmentPanel alignPanel,
150           AlignExportSettingI settings)
151   {
152     viewpanel = alignPanel;
153     exportSettings = settings;
154   }
155
156   /**
157    *
158    * @param els
159    * @return grammatically correct(ish) list consisting of els elements.
160    */
161   public static String prettyPrint(String[] els)
162   {
163     StringBuffer list = new StringBuffer();
164     for (int i = 0, iSize = els.length - 1; i < iSize; i++)
165     {
166       list.append(els[i]);
167       list.append(", ");
168     }
169     list.append(" and " + els[els.length - 1] + ".");
170     return list.toString();
171   }
172
173
174   public void setNewlineString(String nl)
175   {
176     newline = nl;
177   }
178
179   public String getNewlineString()
180   {
181     return newline;
182   }
183
184   /**
185    * check that this format is valid for reading
186    *
187    * @param format
188    *          a format string to be compared with READABLE_FORMATS
189    * @return true if format is readable
190    */
191   public static final boolean isValidFormat(String format)
192   {
193     return isValidFormat(format, false);
194   }
195
196   /**
197    * validate format is valid for IO
198    *
199    * @param format
200    *          a format string to be compared with either READABLE_FORMATS or
201    *          WRITEABLE_FORMATS
202    * @param forwriting
203    *          when true, format is checked for containment in WRITEABLE_FORMATS
204    * @return true if format is valid
205    */
206   public static final boolean isValidFormat(String format,
207           boolean forwriting)
208   {
209     boolean valid = false;
210     String[] format_list = (forwriting) ? WRITEABLE_FORMATS
211             : READABLE_FORMATS;
212     for (String element : format_list)
213     {
214       if (element.equalsIgnoreCase(format))
215       {
216         return true;
217       }
218     }
219
220     return valid;
221   }
222
223   /**
224    * Constructs the correct filetype parser for a characterised datasource
225    *
226    * @param inFile
227    *          data/data location
228    * @param type
229    *          type of datasource
230    * @param format
231    *          File format of data provided by datasource
232    *
233    * @return DOCUMENT ME!
234    */
235   public AlignmentI readFile(String inFile, String type, String format)
236           throws java.io.IOException
237   {
238     // TODO: generalise mapping between format string and io. class instances
239     // using Constructor.invoke reflection
240     this.inFile = inFile;
241     try
242     {
243       if (format.equals("FASTA"))
244       {
245         alignFile = new FastaFile(inFile, type);
246       }
247       else if (format.equals("MSF"))
248       {
249         alignFile = new MSFfile(inFile, type);
250       }
251       else if (format.equals("PileUp"))
252       {
253         alignFile = new PileUpfile(inFile, type);
254       }
255       else if (format.equals("CLUSTAL"))
256       {
257         alignFile = new ClustalFile(inFile, type);
258       }
259       else if (format.equals("BLC"))
260       {
261         alignFile = new BLCFile(inFile, type);
262       }
263       else if (format.equals("PIR"))
264       {
265         alignFile = new PIRFile(inFile, type);
266       }
267       else if (format.equals("PFAM"))
268       {
269         alignFile = new PfamFile(inFile, type);
270       }
271       else if (format.equals("JnetFile"))
272       {
273         alignFile = new JPredFile(inFile, type);
274         ((JPredFile) alignFile).removeNonSequences();
275       }
276       else if (format.equals("PDB"))
277       {
278         alignFile = new MCview.PDBfile(annotFromStructure,
279                 localSecondaryStruct, serviceSecondaryStruct, inFile, type);
280         // Uncomment to test Jmol data based PDB processing: JAL-1213
281         // afile = new jalview.ext.jmol.PDBFileWithJmol(inFile, type);
282       }
283       else if (format.equals("STH"))
284       {
285         alignFile = new StockholmFile(inFile, type);
286       }
287       else if (format.equals("SimpleBLAST"))
288       {
289         alignFile = new SimpleBlastFile(inFile, type);
290       }
291       else if (format.equals(PhylipFile.FILE_DESC))
292       {
293         alignFile = new PhylipFile(inFile, type);
294       }
295       else if (format.equals(JSONFile.FILE_DESC))
296       {
297         alignFile = new JSONFile(inFile, type);
298       }
299       else if (format.equals(HtmlFile.FILE_DESC))
300       {
301         alignFile = new HtmlFile(inFile, type);
302       }
303       else if (format.equals("RNAML"))
304       {
305         alignFile = new RnamlFile(inFile, type);
306       }
307       else if (format.equals(IdentifyFile.GFF3File))
308       {
309         alignFile = new Gff3File(inFile, type);
310       }
311       return buildAlignmentFrom(alignFile);
312     } catch (Exception e)
313     {
314       e.printStackTrace();
315       System.err.println("Failed to read alignment using the '" + format
316               + "' reader.\n" + e);
317
318       if (e.getMessage() != null
319               && e.getMessage().startsWith(INVALID_CHARACTERS))
320       {
321         throw new java.io.IOException(e.getMessage());
322       }
323
324       // Finally test if the user has pasted just the sequence, no id
325       if (type.equalsIgnoreCase("Paste"))
326       {
327         try
328         {
329           // Possible sequence is just residues with no label
330           alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
331           return buildAlignmentFrom(alignFile);
332
333         } catch (Exception ex)
334         {
335           if (ex.toString().startsWith(INVALID_CHARACTERS))
336           {
337             throw new java.io.IOException(e.getMessage());
338           }
339
340           ex.printStackTrace();
341         }
342       }
343
344       // If we get to this stage, the format was not supported
345       throw new java.io.IOException(SUPPORTED_FORMATS);
346     }
347   }
348
349   /**
350    * Constructs the correct filetype parser for an already open datasource
351    *
352    * @param source
353    *          an existing datasource
354    * @param format
355    *          File format of data that will be provided by datasource
356    *
357    * @return DOCUMENT ME!
358    */
359   public AlignmentI readFromFile(FileParse source, String format)
360           throws java.io.IOException
361   {
362     // TODO: generalise mapping between format string and io. class instances
363     // using Constructor.invoke reflection
364     // This is exactly the same as the readFile method except we substitute
365     // 'inFile, type' with 'source'
366     this.inFile = source.getInFile();
367     String type = source.type;
368     try
369     {
370       if (format.equals("FASTA"))
371       {
372         alignFile = new FastaFile(source);
373       }
374       else if (format.equals("MSF"))
375       {
376         alignFile = new MSFfile(source);
377       }
378       else if (format.equals("PileUp"))
379       {
380         alignFile = new PileUpfile(source);
381       }
382       else if (format.equals("CLUSTAL"))
383       {
384         alignFile = new ClustalFile(source);
385       }
386       else if (format.equals("BLC"))
387       {
388         alignFile = new BLCFile(source);
389       }
390       else if (format.equals("PIR"))
391       {
392         alignFile = new PIRFile(source);
393       }
394       else if (format.equals("PFAM"))
395       {
396         alignFile = new PfamFile(source);
397       }
398       else if (format.equals("JnetFile"))
399       {
400         alignFile = new JPredFile(source);
401         ((JPredFile) alignFile).removeNonSequences();
402       }
403       else if (format.equals("PDB"))
404       {
405         alignFile = new MCview.PDBfile(annotFromStructure,
406                 localSecondaryStruct, serviceSecondaryStruct, source);
407       }
408       else if (format.equals("STH"))
409       {
410         alignFile = new StockholmFile(source);
411       }
412       else if (format.equals("RNAML"))
413       {
414         alignFile = new RnamlFile(source);
415       }
416       else if (format.equals("SimpleBLAST"))
417       {
418         alignFile = new SimpleBlastFile(source);
419       }
420       else if (format.equals(PhylipFile.FILE_DESC))
421       {
422         alignFile = new PhylipFile(source);
423       }
424       else if (format.equals(IdentifyFile.GFF3File))
425       {
426         alignFile = new Gff3File(inFile, type);
427       }
428       else if (format.equals(JSONFile.FILE_DESC))
429       {
430         alignFile = new JSONFile(source);
431       }
432       else if (format.equals(HtmlFile.FILE_DESC))
433       {
434         alignFile = new HtmlFile(source);
435       }
436
437       return buildAlignmentFrom(alignFile);
438
439     } catch (Exception e)
440     {
441       e.printStackTrace();
442       System.err.println("Failed to read alignment using the '" + format
443               + "' reader.\n" + e);
444
445       if (e.getMessage() != null
446               && e.getMessage().startsWith(INVALID_CHARACTERS))
447       {
448         throw new java.io.IOException(e.getMessage());
449       }
450
451       // Finally test if the user has pasted just the sequence, no id
452       if (type.equalsIgnoreCase("Paste"))
453       {
454         try
455         {
456           // Possible sequence is just residues with no label
457           alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
458           return buildAlignmentFrom(alignFile);
459
460         } catch (Exception ex)
461         {
462           if (ex.toString().startsWith(INVALID_CHARACTERS))
463           {
464             throw new java.io.IOException(e.getMessage());
465           }
466
467           ex.printStackTrace();
468         }
469       }
470
471       // If we get to this stage, the format was not supported
472       throw new java.io.IOException(SUPPORTED_FORMATS);
473     }
474   }
475
476
477   /**
478    * boilerplate method to handle data from an AlignFile and construct a new
479    * alignment or import to an existing alignment
480    * 
481    * @param alignFile2
482    * @return AlignmentI instance ready to pass to a UI constructor
483    */
484   private AlignmentI buildAlignmentFrom(AlignFile alignFile2)
485   {
486     // Standard boilerplate for creating alignment from parser
487     alignFile.configureForView(viewpanel);
488
489     AlignmentI al = new Alignment(alignFile.getSeqsAsArray());
490
491     alignFile.addAnnotations(al);
492
493     alignFile.addGroups(al);
494
495     return al;
496   }
497
498   /**
499    * create an alignment flatfile from a Jalview alignment view
500    * @param format
501    * @param jvsuffix
502    * @param av
503    * @param selectedOnly
504    * @return flatfile in a string
505    */
506   public String formatSequences(String format, boolean jvsuffix,
507           AlignmentViewPanel ap, boolean selectedOnly)
508   {
509
510     AlignmentView selvew = ap.getAlignViewport().getAlignmentView(
511             selectedOnly, false);
512     AlignmentI aselview = selvew.getVisibleAlignment(ap.getAlignViewport()
513             .getGapCharacter());
514     List<AlignmentAnnotation> ala = (ap.getAlignViewport()
515             .getVisibleAlignmentAnnotation(selectedOnly));
516     if (ala != null)
517     {
518       for (AlignmentAnnotation aa : ala)
519       {
520         aselview.addAnnotation(aa);
521       }
522     }
523
524     return formatSequences(format, aselview, jvsuffix);
525   }
526
527   /**
528    * Construct an output class for an alignment in a particular filetype TODO:
529    * allow caller to detect errors and warnings encountered when generating
530    * output
531    *
532    * @param format
533    *          string name of alignment format
534    * @param alignment
535    *          the alignment to be written out
536    * @param jvsuffix
537    *          passed to AlnFile class controls whether /START-END is added to
538    *          sequence names
539    *
540    * @return alignment flat file contents
541    */
542   public String formatSequences(String format, AlignmentI alignment,
543           boolean jvsuffix)
544   {
545     try
546     {
547       AlignFile afile = null;
548       if (format.equalsIgnoreCase("FASTA"))
549       {
550         afile = new FastaFile();
551       }
552       else if (format.equalsIgnoreCase("MSF"))
553       {
554         afile = new MSFfile();
555       }
556       else if (format.equalsIgnoreCase("PileUp"))
557       {
558         afile = new PileUpfile();
559       }
560       else if (format.equalsIgnoreCase("CLUSTAL"))
561       {
562         afile = new ClustalFile();
563       }
564       else if (format.equalsIgnoreCase("BLC"))
565       {
566         afile = new BLCFile();
567       }
568       else if (format.equalsIgnoreCase("PIR"))
569       {
570         afile = new PIRFile();
571       }
572       else if (format.equalsIgnoreCase("PFAM"))
573       {
574         afile = new PfamFile();
575       }
576       else if (format.equalsIgnoreCase("STH"))
577       {
578         afile = new StockholmFile(alignment);
579       }
580       else if (format.equalsIgnoreCase("AMSA"))
581       {
582         afile = new AMSAFile(alignment);
583       }
584       else if (format.equalsIgnoreCase(PhylipFile.FILE_DESC))
585       {
586         afile = new PhylipFile();
587       }
588        else if (format.equalsIgnoreCase(JSONFile.FILE_DESC))
589        {
590         afile = new JSONFile();
591        }
592       else if (format.equalsIgnoreCase("RNAML"))
593       {
594         afile = new RnamlFile();
595       }
596
597       else
598       {
599         throw new Exception(MessageManager.getString("error.implementation_error_unknown_file_format_string"));
600       }
601       afile.setNewlineString(newline);
602       afile.addJVSuffix(jvsuffix);
603
604       afile.setExportSettings(exportSettings);
605
606       afile.configureForView(viewpanel);
607
608       // check whether we were given a specific alignment to export, rather than
609       // the one in the viewpanel
610       if (viewpanel == null || viewpanel.getAlignment() == null
611               || viewpanel.getAlignment() != alignment)
612       {
613         afile.setSeqs(alignment.getSequencesArray());
614       }
615       else
616       {
617         afile.setSeqs(viewpanel.getAlignment().getSequencesArray());
618       }
619
620       String afileresp = afile.print();
621       if (afile.hasWarningMessage())
622       {
623         System.err.println("Warning raised when writing as " + format
624                 + " : " + afile.getWarningMessage());
625       }
626       return afileresp;
627     } catch (Exception e)
628     {
629       System.err.println("Failed to write alignment as a '" + format
630               + "' file\n");
631       e.printStackTrace();
632     }
633
634     return null;
635   }
636
637   public static String checkProtocol(String file)
638   {
639     String protocol = FILE;
640     String ft = file.toLowerCase().trim();
641     if (ft.indexOf("http:") == 0 || ft.indexOf("https:") == 0
642             || ft.indexOf("file:") == 0)
643     {
644       protocol = URL;
645     }
646     return protocol;
647   }
648
649   public static void main(String[] args)
650   {
651     int i = 0;
652     while (i < args.length)
653     {
654       File f = new File(args[i]);
655       if (f.exists())
656       {
657         try
658         {
659           System.out.println("Reading file: " + f);
660           AppletFormatAdapter afa = new AppletFormatAdapter();
661           Runtime r = Runtime.getRuntime();
662           System.gc();
663           long memf = -r.totalMemory() + r.freeMemory();
664           long t1 = -System.currentTimeMillis();
665           AlignmentI al = afa.readFile(args[i], FILE,
666                   new IdentifyFile().Identify(args[i], FILE));
667           t1 += System.currentTimeMillis();
668           System.gc();
669           memf += r.totalMemory() - r.freeMemory();
670           if (al != null)
671           {
672             System.out.println("Alignment contains " + al.getHeight()
673                     + " sequences and " + al.getWidth() + " columns.");
674             try
675             {
676               System.out.println(new AppletFormatAdapter().formatSequences(
677                       "FASTA", al, true));
678             } catch (Exception e)
679             {
680               System.err
681               .println("Couln't format the alignment for output as a FASTA file.");
682               e.printStackTrace(System.err);
683             }
684           }
685           else
686           {
687             System.out.println("Couldn't read alignment");
688           }
689           System.out.println("Read took " + (t1 / 1000.0) + " seconds.");
690           System.out
691           .println("Difference between free memory now and before is "
692                   + (memf / (1024.0 * 1024.0) * 1.0) + " MB");
693         } catch (Exception e)
694         {
695           System.err.println("Exception when dealing with " + i
696                   + "'th argument: " + args[i] + "\n" + e);
697         }
698       }
699       else
700       {
701         System.err.println("Ignoring argument '" + args[i] + "' (" + i
702                 + "'th)- not a readable file.");
703       }
704       i++;
705     }
706   }
707
708   /**
709    * try to discover how to access the given file as a valid datasource that
710    * will be identified as the given type.
711    *
712    * @param file
713    * @param format
714    * @return protocol that yields the data parsable as the given type
715    */
716   public static String resolveProtocol(String file, String format)
717   {
718     return resolveProtocol(file, format, false);
719   }
720
721   public static String resolveProtocol(String file, String format,
722           boolean debug)
723   {
724     // TODO: test thoroughly!
725     String protocol = null;
726     if (debug)
727     {
728       System.out.println("resolving datasource started with:\n>>file\n"
729               + file + ">>endfile");
730     }
731
732     // This might throw a security exception in certain browsers
733     // Netscape Communicator for instance.
734     try
735     {
736       boolean rtn = false;
737       InputStream is = System.getSecurityManager().getClass()
738               .getResourceAsStream("/" + file);
739       if (is != null)
740       {
741         rtn = true;
742         is.close();
743       }
744       if (debug)
745       {
746         System.err.println("Resource '" + file + "' was "
747                 + (rtn ? "" : "not") + " located by classloader.");
748       }
749       ;
750       if (rtn)
751       {
752         protocol = AppletFormatAdapter.CLASSLOADER;
753       }
754
755     } catch (Exception ex)
756     {
757       System.err
758       .println("Exception checking resources: " + file + " " + ex);
759     }
760
761     if (file.indexOf("://") > -1)
762     {
763       protocol = AppletFormatAdapter.URL;
764     }
765     else
766     {
767       // skipping codebase prepend check.
768       protocol = AppletFormatAdapter.FILE;
769     }
770     FileParse fp = null;
771     try
772     {
773       if (debug)
774       {
775         System.out.println("Trying to get contents of resource as "
776                 + protocol + ":");
777       }
778       fp = new FileParse(file, protocol);
779       if (!fp.isValid())
780       {
781         fp = null;
782       }
783       else
784       {
785         if (debug)
786         {
787           System.out.println("Successful.");
788         }
789       }
790     } catch (Exception e)
791     {
792       if (debug)
793       {
794         System.err.println("Exception when accessing content: " + e);
795       }
796       fp = null;
797     }
798     if (fp == null)
799     {
800       if (debug)
801       {
802         System.out.println("Accessing as paste.");
803       }
804       protocol = AppletFormatAdapter.PASTE;
805       fp = null;
806       try
807       {
808         fp = new FileParse(file, protocol);
809         if (!fp.isValid())
810         {
811           fp = null;
812         }
813       } catch (Exception e)
814       {
815         System.err.println("Failed to access content as paste!");
816         e.printStackTrace();
817         fp = null;
818       }
819     }
820     if (fp == null)
821     {
822       return null;
823     }
824     if (format == null || format.length() == 0)
825     {
826       return protocol;
827     }
828     else
829     {
830       try
831       {
832         String idformat = new jalview.io.IdentifyFile().Identify(file,
833                 protocol);
834         if (idformat == null)
835         {
836           if (debug)
837           {
838             System.out.println("Format not identified. Inaccessible file.");
839           }
840           return null;
841         }
842         if (debug)
843         {
844           System.out.println("Format identified as " + idformat
845                   + "and expected as " + format);
846         }
847         if (idformat.equals(format))
848         {
849           if (debug)
850           {
851             System.out.println("Protocol identified as " + protocol);
852           }
853           return protocol;
854         }
855         else
856         {
857           if (debug)
858           {
859             System.out
860             .println("File deemed not accessible via " + protocol);
861           }
862           fp.close();
863           return null;
864         }
865       } catch (Exception e)
866       {
867         if (debug)
868         {
869           System.err.println("File deemed not accessible via " + protocol);
870           e.printStackTrace();
871         }
872         ;
873
874       }
875     }
876     return null;
877   }
878
879   public AlignFile getAlignFile()
880   {
881     return alignFile;
882   }
883
884   public void setAlignFile(AlignFile alignFile)
885   {
886     this.alignFile = alignFile;
887   }
888 }