JAL-1835 made BioJSON embedding to html exports configurable, and trapped import...
[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.IOException;
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(AlignmentViewPanel 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     if (format == null)
210     {
211       return false;
212     }
213     boolean valid = false;
214     String[] format_list = (forwriting) ? WRITEABLE_FORMATS
215             : READABLE_FORMATS;
216     for (String element : format_list)
217     {
218       if (element.equalsIgnoreCase(format))
219       {
220         return true;
221       }
222     }
223
224     return valid;
225   }
226
227   /**
228    * Constructs the correct filetype parser for a characterised datasource
229    *
230    * @param inFile
231    *          data/data location
232    * @param type
233    *          type of datasource
234    * @param format
235    *          File format of data provided by datasource
236    *
237    * @return DOCUMENT ME!
238    */
239   public AlignmentI readFile(String inFile, String type, String format)
240           throws java.io.IOException
241   {
242     // TODO: generalise mapping between format string and io. class instances
243     // using Constructor.invoke reflection
244     this.inFile = inFile;
245     try
246     {
247       if (format.equals("FASTA"))
248       {
249         alignFile = new FastaFile(inFile, type);
250       }
251       else if (format.equals("MSF"))
252       {
253         alignFile = new MSFfile(inFile, type);
254       }
255       else if (format.equals("PileUp"))
256       {
257         alignFile = new PileUpfile(inFile, type);
258       }
259       else if (format.equals("CLUSTAL"))
260       {
261         alignFile = new ClustalFile(inFile, type);
262       }
263       else if (format.equals("BLC"))
264       {
265         alignFile = new BLCFile(inFile, type);
266       }
267       else if (format.equals("PIR"))
268       {
269         alignFile = new PIRFile(inFile, type);
270       }
271       else if (format.equals("PFAM"))
272       {
273         alignFile = new PfamFile(inFile, type);
274       }
275       else if (format.equals("JnetFile"))
276       {
277         alignFile = new JPredFile(inFile, type);
278         ((JPredFile) alignFile).removeNonSequences();
279       }
280       else if (format.equals("PDB"))
281       {
282         alignFile = new MCview.PDBfile(annotFromStructure,
283                 localSecondaryStruct, serviceSecondaryStruct, inFile, type);
284         // Uncomment to test Jmol data based PDB processing: JAL-1213
285         // afile = new jalview.ext.jmol.PDBFileWithJmol(inFile, type);
286       }
287       else if (format.equals("STH"))
288       {
289         alignFile = new StockholmFile(inFile, type);
290       }
291       else if (format.equals("SimpleBLAST"))
292       {
293         alignFile = new SimpleBlastFile(inFile, type);
294       }
295       else if (format.equals(PhylipFile.FILE_DESC))
296       {
297         alignFile = new PhylipFile(inFile, type);
298       }
299       else if (format.equals(JSONFile.FILE_DESC))
300       {
301         alignFile = new JSONFile(inFile, type);
302       }
303       else if (format.equals(HtmlFile.FILE_DESC))
304       {
305         alignFile = new HtmlFile(inFile, type);
306       }
307       else if (format.equals("RNAML"))
308       {
309         alignFile = new RnamlFile(inFile, type);
310       }
311       else if (format.equals(IdentifyFile.GFF3File))
312       {
313         alignFile = new Gff3File(inFile, type);
314       }
315       return buildAlignmentFrom(alignFile);
316     } catch (Exception e)
317     {
318       e.printStackTrace();
319       System.err.println("Failed to read alignment using the '" + format
320               + "' reader.\n" + e);
321
322       if (e.getMessage() != null
323               && e.getMessage().startsWith(INVALID_CHARACTERS))
324       {
325         throw new java.io.IOException(e.getMessage());
326       }
327
328       // Finally test if the user has pasted just the sequence, no id
329       if (type.equalsIgnoreCase("Paste"))
330       {
331         try
332         {
333           // Possible sequence is just residues with no label
334           alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
335           return buildAlignmentFrom(alignFile);
336
337         } catch (Exception ex)
338         {
339           if (ex.toString().startsWith(INVALID_CHARACTERS))
340           {
341             throw new java.io.IOException(e.getMessage());
342           }
343
344           ex.printStackTrace();
345         }
346       }
347       if (format.equalsIgnoreCase("HTML"))
348       {
349         throw new IOException(e.getMessage());
350       }
351       // If we get to this stage, the format was not supported
352       throw new java.io.IOException(SUPPORTED_FORMATS);
353     }
354   }
355
356   /**
357    * Constructs the correct filetype parser for an already open datasource
358    *
359    * @param source
360    *          an existing datasource
361    * @param format
362    *          File format of data that will be provided by datasource
363    *
364    * @return DOCUMENT ME!
365    */
366   public AlignmentI readFromFile(FileParse source, String format)
367           throws java.io.IOException
368   {
369     // TODO: generalise mapping between format string and io. class instances
370     // using Constructor.invoke reflection
371     // This is exactly the same as the readFile method except we substitute
372     // 'inFile, type' with 'source'
373     this.inFile = source.getInFile();
374     String type = source.type;
375     try
376     {
377       if (format.equals("FASTA"))
378       {
379         alignFile = new FastaFile(source);
380       }
381       else if (format.equals("MSF"))
382       {
383         alignFile = new MSFfile(source);
384       }
385       else if (format.equals("PileUp"))
386       {
387         alignFile = new PileUpfile(source);
388       }
389       else if (format.equals("CLUSTAL"))
390       {
391         alignFile = new ClustalFile(source);
392       }
393       else if (format.equals("BLC"))
394       {
395         alignFile = new BLCFile(source);
396       }
397       else if (format.equals("PIR"))
398       {
399         alignFile = new PIRFile(source);
400       }
401       else if (format.equals("PFAM"))
402       {
403         alignFile = new PfamFile(source);
404       }
405       else if (format.equals("JnetFile"))
406       {
407         alignFile = new JPredFile(source);
408         ((JPredFile) alignFile).removeNonSequences();
409       }
410       else if (format.equals("PDB"))
411       {
412         alignFile = new MCview.PDBfile(annotFromStructure,
413                 localSecondaryStruct, serviceSecondaryStruct, source);
414       }
415       else if (format.equals("STH"))
416       {
417         alignFile = new StockholmFile(source);
418       }
419       else if (format.equals("RNAML"))
420       {
421         alignFile = new RnamlFile(source);
422       }
423       else if (format.equals("SimpleBLAST"))
424       {
425         alignFile = new SimpleBlastFile(source);
426       }
427       else if (format.equals(PhylipFile.FILE_DESC))
428       {
429         alignFile = new PhylipFile(source);
430       }
431       else if (format.equals(IdentifyFile.GFF3File))
432       {
433         alignFile = new Gff3File(inFile, type);
434       }
435       else if (format.equals(JSONFile.FILE_DESC))
436       {
437         alignFile = new JSONFile(source);
438       }
439       else if (format.equals(HtmlFile.FILE_DESC))
440       {
441         alignFile = new HtmlFile(source);
442       }
443
444       return buildAlignmentFrom(alignFile);
445
446     } catch (Exception e)
447     {
448       e.printStackTrace();
449       System.err.println("Failed to read alignment using the '" + format
450               + "' reader.\n" + e);
451
452       if (e.getMessage() != null
453               && e.getMessage().startsWith(INVALID_CHARACTERS))
454       {
455         throw new java.io.IOException(e.getMessage());
456       }
457
458       // Finally test if the user has pasted just the sequence, no id
459       if (type.equalsIgnoreCase("Paste"))
460       {
461         try
462         {
463           // Possible sequence is just residues with no label
464           alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
465           return buildAlignmentFrom(alignFile);
466
467         } catch (Exception ex)
468         {
469           if (ex.toString().startsWith(INVALID_CHARACTERS))
470           {
471             throw new java.io.IOException(e.getMessage());
472           }
473
474           ex.printStackTrace();
475         }
476       }
477
478       // If we get to this stage, the format was not supported
479       throw new java.io.IOException(SUPPORTED_FORMATS);
480     }
481   }
482
483
484   /**
485    * boilerplate method to handle data from an AlignFile and construct a new
486    * alignment or import to an existing alignment
487    * 
488    * @param alignFile2
489    * @return AlignmentI instance ready to pass to a UI constructor
490    */
491   private AlignmentI buildAlignmentFrom(AlignFile alignFile2)
492   {
493     // Standard boilerplate for creating alignment from parser
494     // alignFile.configureForView(viewpanel);
495
496     AlignmentI al = new Alignment(alignFile.getSeqsAsArray());
497
498     alignFile.addAnnotations(al);
499
500     alignFile.addGroups(al);
501
502     return al;
503   }
504
505   /**
506    * create an alignment flatfile from a Jalview alignment view
507    * @param format
508    * @param jvsuffix
509    * @param av
510    * @param selectedOnly
511    * @return flatfile in a string
512    */
513   public String formatSequences(String format, boolean jvsuffix,
514           AlignmentViewPanel ap, boolean selectedOnly)
515   {
516
517     AlignmentView selvew = ap.getAlignViewport().getAlignmentView(
518             selectedOnly, false);
519     AlignmentI aselview = selvew.getVisibleAlignment(ap.getAlignViewport()
520             .getGapCharacter());
521     List<AlignmentAnnotation> ala = (ap.getAlignViewport()
522             .getVisibleAlignmentAnnotation(selectedOnly));
523     if (ala != null)
524     {
525       for (AlignmentAnnotation aa : ala)
526       {
527         aselview.addAnnotation(aa);
528       }
529     }
530     viewpanel = ap;
531     return formatSequences(format, aselview, jvsuffix);
532   }
533
534   /**
535    * Construct an output class for an alignment in a particular filetype TODO:
536    * allow caller to detect errors and warnings encountered when generating
537    * output
538    *
539    * @param format
540    *          string name of alignment format
541    * @param alignment
542    *          the alignment to be written out
543    * @param jvsuffix
544    *          passed to AlnFile class controls whether /START-END is added to
545    *          sequence names
546    *
547    * @return alignment flat file contents
548    */
549   public String formatSequences(String format, AlignmentI alignment,
550           boolean jvsuffix)
551   {
552     try
553     {
554       AlignFile afile = null;
555       if (format.equalsIgnoreCase("FASTA"))
556       {
557         afile = new FastaFile();
558       }
559       else if (format.equalsIgnoreCase("MSF"))
560       {
561         afile = new MSFfile();
562       }
563       else if (format.equalsIgnoreCase("PileUp"))
564       {
565         afile = new PileUpfile();
566       }
567       else if (format.equalsIgnoreCase("CLUSTAL"))
568       {
569         afile = new ClustalFile();
570       }
571       else if (format.equalsIgnoreCase("BLC"))
572       {
573         afile = new BLCFile();
574       }
575       else if (format.equalsIgnoreCase("PIR"))
576       {
577         afile = new PIRFile();
578       }
579       else if (format.equalsIgnoreCase("PFAM"))
580       {
581         afile = new PfamFile();
582       }
583       else if (format.equalsIgnoreCase("STH"))
584       {
585         afile = new StockholmFile(alignment);
586       }
587       else if (format.equalsIgnoreCase("AMSA"))
588       {
589         afile = new AMSAFile(alignment);
590       }
591       else if (format.equalsIgnoreCase(PhylipFile.FILE_DESC))
592       {
593         afile = new PhylipFile();
594       }
595        else if (format.equalsIgnoreCase(JSONFile.FILE_DESC))
596        {
597         afile = new JSONFile();
598        }
599       else if (format.equalsIgnoreCase("RNAML"))
600       {
601         afile = new RnamlFile();
602       }
603
604       else
605       {
606         throw new Exception(MessageManager.getString("error.implementation_error_unknown_file_format_string"));
607       }
608
609       afile.setNewlineString(newline);
610       afile.addJVSuffix(jvsuffix);
611       afile.setExportSettings(exportSettings);
612       afile.configureForView(viewpanel);
613
614       // check whether we were given a specific alignment to export, rather than
615       // the one in the viewpanel
616       if (viewpanel == null || viewpanel.getAlignment() == null
617               || viewpanel.getAlignment() != alignment)
618       {
619         afile.setSeqs(alignment.getSequencesArray());
620       }
621       else
622       {
623         afile.setSeqs(viewpanel.getAlignment().getSequencesArray());
624       }
625
626       String afileresp = afile.print();
627       if (afile.hasWarningMessage())
628       {
629         System.err.println("Warning raised when writing as " + format
630                 + " : " + afile.getWarningMessage());
631       }
632       return afileresp;
633     } catch (Exception e)
634     {
635       System.err.println("Failed to write alignment as a '" + format
636               + "' file\n");
637       e.printStackTrace();
638     }
639
640     return null;
641   }
642
643   public static String checkProtocol(String file)
644   {
645     String protocol = FILE;
646     String ft = file.toLowerCase().trim();
647     if (ft.indexOf("http:") == 0 || ft.indexOf("https:") == 0
648             || ft.indexOf("file:") == 0)
649     {
650       protocol = URL;
651     }
652     return protocol;
653   }
654
655   public static void main(String[] args)
656   {
657     int i = 0;
658     while (i < args.length)
659     {
660       File f = new File(args[i]);
661       if (f.exists())
662       {
663         try
664         {
665           System.out.println("Reading file: " + f);
666           AppletFormatAdapter afa = new AppletFormatAdapter();
667           Runtime r = Runtime.getRuntime();
668           System.gc();
669           long memf = -r.totalMemory() + r.freeMemory();
670           long t1 = -System.currentTimeMillis();
671           AlignmentI al = afa.readFile(args[i], FILE,
672                   new IdentifyFile().Identify(args[i], FILE));
673           t1 += System.currentTimeMillis();
674           System.gc();
675           memf += r.totalMemory() - r.freeMemory();
676           if (al != null)
677           {
678             System.out.println("Alignment contains " + al.getHeight()
679                     + " sequences and " + al.getWidth() + " columns.");
680             try
681             {
682               System.out.println(new AppletFormatAdapter().formatSequences(
683                       "FASTA", al, true));
684             } catch (Exception e)
685             {
686               System.err
687               .println("Couln't format the alignment for output as a FASTA file.");
688               e.printStackTrace(System.err);
689             }
690           }
691           else
692           {
693             System.out.println("Couldn't read alignment");
694           }
695           System.out.println("Read took " + (t1 / 1000.0) + " seconds.");
696           System.out
697           .println("Difference between free memory now and before is "
698                   + (memf / (1024.0 * 1024.0) * 1.0) + " MB");
699         } catch (Exception e)
700         {
701           System.err.println("Exception when dealing with " + i
702                   + "'th argument: " + args[i] + "\n" + e);
703         }
704       }
705       else
706       {
707         System.err.println("Ignoring argument '" + args[i] + "' (" + i
708                 + "'th)- not a readable file.");
709       }
710       i++;
711     }
712   }
713
714   /**
715    * try to discover how to access the given file as a valid datasource that
716    * will be identified as the given type.
717    *
718    * @param file
719    * @param format
720    * @return protocol that yields the data parsable as the given type
721    */
722   public static String resolveProtocol(String file, String format)
723   {
724     return resolveProtocol(file, format, false);
725   }
726
727   public static String resolveProtocol(String file, String format,
728           boolean debug)
729   {
730     // TODO: test thoroughly!
731     String protocol = null;
732     if (debug)
733     {
734       System.out.println("resolving datasource started with:\n>>file\n"
735               + file + ">>endfile");
736     }
737
738     // This might throw a security exception in certain browsers
739     // Netscape Communicator for instance.
740     try
741     {
742       boolean rtn = false;
743       InputStream is = System.getSecurityManager().getClass()
744               .getResourceAsStream("/" + file);
745       if (is != null)
746       {
747         rtn = true;
748         is.close();
749       }
750       if (debug)
751       {
752         System.err.println("Resource '" + file + "' was "
753                 + (rtn ? "" : "not") + " located by classloader.");
754       }
755       ;
756       if (rtn)
757       {
758         protocol = AppletFormatAdapter.CLASSLOADER;
759       }
760
761     } catch (Exception ex)
762     {
763       System.err
764       .println("Exception checking resources: " + file + " " + ex);
765     }
766
767     if (file.indexOf("://") > -1)
768     {
769       protocol = AppletFormatAdapter.URL;
770     }
771     else
772     {
773       // skipping codebase prepend check.
774       protocol = AppletFormatAdapter.FILE;
775     }
776     FileParse fp = null;
777     try
778     {
779       if (debug)
780       {
781         System.out.println("Trying to get contents of resource as "
782                 + protocol + ":");
783       }
784       fp = new FileParse(file, protocol);
785       if (!fp.isValid())
786       {
787         fp = null;
788       }
789       else
790       {
791         if (debug)
792         {
793           System.out.println("Successful.");
794         }
795       }
796     } catch (Exception e)
797     {
798       if (debug)
799       {
800         System.err.println("Exception when accessing content: " + e);
801       }
802       fp = null;
803     }
804     if (fp == null)
805     {
806       if (debug)
807       {
808         System.out.println("Accessing as paste.");
809       }
810       protocol = AppletFormatAdapter.PASTE;
811       fp = null;
812       try
813       {
814         fp = new FileParse(file, protocol);
815         if (!fp.isValid())
816         {
817           fp = null;
818         }
819       } catch (Exception e)
820       {
821         System.err.println("Failed to access content as paste!");
822         e.printStackTrace();
823         fp = null;
824       }
825     }
826     if (fp == null)
827     {
828       return null;
829     }
830     if (format == null || format.length() == 0)
831     {
832       return protocol;
833     }
834     else
835     {
836       try
837       {
838         String idformat = new jalview.io.IdentifyFile().Identify(file,
839                 protocol);
840         if (idformat == null)
841         {
842           if (debug)
843           {
844             System.out.println("Format not identified. Inaccessible file.");
845           }
846           return null;
847         }
848         if (debug)
849         {
850           System.out.println("Format identified as " + idformat
851                   + "and expected as " + format);
852         }
853         if (idformat.equals(format))
854         {
855           if (debug)
856           {
857             System.out.println("Protocol identified as " + protocol);
858           }
859           return protocol;
860         }
861         else
862         {
863           if (debug)
864           {
865             System.out
866             .println("File deemed not accessible via " + protocol);
867           }
868           fp.close();
869           return null;
870         }
871       } catch (Exception e)
872       {
873         if (debug)
874         {
875           System.err.println("File deemed not accessible via " + protocol);
876           e.printStackTrace();
877         }
878         ;
879
880       }
881     }
882     return null;
883   }
884
885   public AlignFile getAlignFile()
886   {
887     return alignFile;
888   }
889
890   public void setAlignFile(AlignFile alignFile)
891   {
892     this.alignFile = alignFile;
893   }
894 }