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