Merge branch 'develop' into features/JAL-653_gffalignments
[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 java.io.File;
24 import java.io.InputStream;
25 import java.util.List;
26
27 import jalview.api.AlignViewportI;
28 import jalview.datamodel.Alignment;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.AlignmentView;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.util.MessageManager;
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 AlignViewportI viewport;
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   /**
81    * List of valid format strings used in the isValidFormat method
82    */
83   public static final String[] READABLE_FORMATS = new String[]
84   { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "STH",
85       "PDB", "JnetFile", "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, IdentifyFile.GFF3File,
86       "HTML" };
87
88   /**
89    * List of readable format file extensions by application in order
90    * corresponding to READABLE_FNAMES
91    */
92   public static final String[] READABLE_EXTENSIONS = new String[]
93   { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa",
94       "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT, JSONFile.FILE_EXT,
95       ".gff2,gff3",
96       "jar,jvp", HtmlFile.FILE_EXT };
97
98   /**
99    * List of readable formats by application in order corresponding to
100    * READABLE_EXTENSIONS
101    */
102   public static final String[] READABLE_FNAMES = new String[]
103   { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Stockholm",
104       "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, IdentifyFile.GFF3File, "Jalview",
105       HtmlFile.FILE_DESC };
106
107   /**
108    * List of valid format strings for use by callers of the formatSequences
109    * method
110    */
111   public static final String[] WRITEABLE_FORMATS = new String[]
112           { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "AMSA",
113     "STH", PhylipFile.FILE_DESC, JSONFile.FILE_DESC };
114
115   /**
116    * List of extensions corresponding to file format types in WRITABLE_FNAMES
117    * that are writable by the application.
118    */
119   public static final String[] WRITABLE_EXTENSIONS = new String[]
120   { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa",
121       "sto,stk", PhylipFile.FILE_EXT, JSONFile.FILE_EXT, "jvp" };
122
123   /**
124    * List of writable formats by the application. Order must correspond with the
125    * WRITABLE_EXTENSIONS list of formats.
126    */
127   public static final String[] WRITABLE_FNAMES = new String[]
128   { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "STH",
129       PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview" };
130
131   public static String INVALID_CHARACTERS = "Contains invalid characters";
132
133   // TODO: make these messages dynamic
134   public static String SUPPORTED_FORMATS = "Formats currently supported are\n"
135           + prettyPrint(READABLE_FORMATS);
136
137   public AppletFormatAdapter()
138   {
139   }
140
141   public AppletFormatAdapter(AlignViewportI viewport)
142   {
143     this.viewport = viewport;
144   }
145
146   /**
147    *
148    * @param els
149    * @return grammatically correct(ish) list consisting of els elements.
150    */
151   public static String prettyPrint(String[] els)
152   {
153     StringBuffer list = new StringBuffer();
154     for (int i = 0, iSize = els.length - 1; i < iSize; i++)
155     {
156       list.append(els[i]);
157       list.append(", ");
158     }
159     list.append(" and " + els[els.length - 1] + ".");
160     return list.toString();
161   }
162
163
164   public void setNewlineString(String nl)
165   {
166     newline = nl;
167   }
168
169   public String getNewlineString()
170   {
171     return newline;
172   }
173
174   /**
175    * check that this format is valid for reading
176    *
177    * @param format
178    *          a format string to be compared with READABLE_FORMATS
179    * @return true if format is readable
180    */
181   public static final boolean isValidFormat(String format)
182   {
183     return isValidFormat(format, false);
184   }
185
186   /**
187    * validate format is valid for IO
188    *
189    * @param format
190    *          a format string to be compared with either READABLE_FORMATS or
191    *          WRITEABLE_FORMATS
192    * @param forwriting
193    *          when true, format is checked for containment in WRITEABLE_FORMATS
194    * @return true if format is valid
195    */
196   public static final boolean isValidFormat(String format,
197           boolean forwriting)
198   {
199     boolean valid = false;
200     String[] format_list = (forwriting) ? WRITEABLE_FORMATS
201             : READABLE_FORMATS;
202     for (String element : format_list)
203     {
204       if (element.equalsIgnoreCase(format))
205       {
206         return true;
207       }
208     }
209
210     return valid;
211   }
212
213   /**
214    * Constructs the correct filetype parser for a characterised datasource
215    *
216    * @param inFile
217    *          data/data location
218    * @param type
219    *          type of datasource
220    * @param format
221    *          File format of data provided by datasource
222    *
223    * @return DOCUMENT ME!
224    */
225   public Alignment readFile(String inFile, String type, String format)
226           throws java.io.IOException
227   {
228     // TODO: generalise mapping between format string and io. class instances
229     // using Constructor.invoke reflection
230     this.inFile = inFile;
231     try
232     {
233       Alignment al;
234       if (format.equals("FASTA"))
235       {
236         alignFile = new FastaFile(inFile, type);
237       }
238       else if (format.equals("MSF"))
239       {
240         alignFile = new MSFfile(inFile, type);
241       }
242       else if (format.equals("PileUp"))
243       {
244         alignFile = new PileUpfile(inFile, type);
245       }
246       else if (format.equals("CLUSTAL"))
247       {
248         alignFile = new ClustalFile(inFile, type);
249       }
250       else if (format.equals("BLC"))
251       {
252         alignFile = new BLCFile(inFile, type);
253       }
254       else if (format.equals("PIR"))
255       {
256         alignFile = new PIRFile(inFile, type);
257       }
258       else if (format.equals("PFAM"))
259       {
260         alignFile = new PfamFile(inFile, type);
261       }
262       else if (format.equals("JnetFile"))
263       {
264         alignFile = new JPredFile(inFile, type);
265         ((JPredFile) alignFile).removeNonSequences();
266       }
267       else if (format.equals("PDB"))
268       {
269         alignFile = new MCview.PDBfile(annotFromStructure,
270                 localSecondaryStruct, serviceSecondaryStruct, inFile, type);
271         // Uncomment to test Jmol data based PDB processing: JAL-1213
272         // afile = new jalview.ext.jmol.PDBFileWithJmol(inFile, type);
273       }
274       else if (format.equals("STH"))
275       {
276         alignFile = new StockholmFile(inFile, type);
277       }
278       else if (format.equals("SimpleBLAST"))
279       {
280         alignFile = new SimpleBlastFile(inFile, type);
281       }
282       else if (format.equals(PhylipFile.FILE_DESC))
283       {
284         alignFile = new PhylipFile(inFile, type);
285       }
286       else if (format.equals(JSONFile.FILE_DESC))
287       {
288         alignFile = new JSONFile(inFile, type);
289         al = new Alignment(alignFile.getSeqsAsArray());
290         alignFile.addAnnotations(al);
291         ((JSONFile) alignFile).setViewport(viewport);
292         for (SequenceGroup sg : alignFile.getSeqGroups())
293         {
294           al.addGroup(sg);
295         }
296
297         return al;
298       }
299       else if (format.equals(HtmlFile.FILE_DESC))
300       {
301         alignFile = new HtmlFile(inFile, type);
302         al = new Alignment(alignFile.getSeqsAsArray());
303         alignFile.addAnnotations(al);
304         for (SequenceGroup sg : alignFile.getSeqGroups())
305         {
306           al.addGroup(sg);
307         }
308         return al;
309       }
310       else if (format.equals("RNAML"))
311       {
312         alignFile = new RnamlFile(inFile, type);
313       }
314       else if (format.equals(IdentifyFile.GFF3File))
315       {
316         alignFile = new Gff3File(inFile, type);
317       }
318
319       al = new Alignment(alignFile.getSeqsAsArray());
320
321       alignFile.addAnnotations(al);
322
323       return al;
324     } catch (Exception e)
325     {
326       e.printStackTrace();
327       System.err.println("Failed to read alignment using the '" + format
328               + "' reader.\n" + e);
329
330       if (e.getMessage() != null
331               && e.getMessage().startsWith(INVALID_CHARACTERS))
332       {
333         throw new java.io.IOException(e.getMessage());
334       }
335
336       // Finally test if the user has pasted just the sequence, no id
337       if (type.equalsIgnoreCase("Paste"))
338       {
339         try
340         {
341           // Possible sequence is just residues with no label
342           alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
343           Alignment al = new Alignment(alignFile.getSeqsAsArray());
344
345           alignFile.addSeqGroups(al);
346           alignFile.addAnnotations(al);
347           return al;
348
349         } catch (Exception ex)
350         {
351           if (ex.toString().startsWith(INVALID_CHARACTERS))
352           {
353             throw new java.io.IOException(e.getMessage());
354           }
355
356           ex.printStackTrace();
357         }
358       }
359
360       // If we get to this stage, the format was not supported
361       throw new java.io.IOException(SUPPORTED_FORMATS);
362     }
363   }
364
365   /**
366    * Constructs the correct filetype parser for an already open datasource
367    *
368    * @param source
369    *          an existing datasource
370    * @param format
371    *          File format of data that will be provided by datasource
372    *
373    * @return DOCUMENT ME!
374    */
375   public AlignmentI readFromFile(FileParse source, String format)
376           throws java.io.IOException
377   {
378     // TODO: generalise mapping between format string and io. class instances
379     // using Constructor.invoke reflection
380     // This is exactly the same as the readFile method except we substitute
381     // 'inFile, type' with 'source'
382     this.inFile = source.getInFile();
383     String type = source.type;
384     try
385     {
386       Alignment al;
387       if (format.equals("FASTA"))
388       {
389         alignFile = new FastaFile(source);
390       }
391       else if (format.equals("MSF"))
392       {
393         alignFile = new MSFfile(source);
394       }
395       else if (format.equals("PileUp"))
396       {
397         alignFile = new PileUpfile(source);
398       }
399       else if (format.equals("CLUSTAL"))
400       {
401         alignFile = new ClustalFile(source);
402       }
403       else if (format.equals("BLC"))
404       {
405         alignFile = new BLCFile(source);
406       }
407       else if (format.equals("PIR"))
408       {
409         alignFile = new PIRFile(source);
410       }
411       else if (format.equals("PFAM"))
412       {
413         alignFile = new PfamFile(source);
414       }
415       else if (format.equals("JnetFile"))
416       {
417         alignFile = new JPredFile(source);
418         ((JPredFile) alignFile).removeNonSequences();
419       }
420       else if (format.equals("PDB"))
421       {
422         alignFile = new MCview.PDBfile(annotFromStructure,
423                 localSecondaryStruct, serviceSecondaryStruct, source);
424       }
425       else if (format.equals("STH"))
426       {
427         alignFile = new StockholmFile(source);
428       }
429       else if (format.equals("RNAML"))
430       {
431         alignFile = new RnamlFile(source);
432       }
433       else if (format.equals("SimpleBLAST"))
434       {
435         alignFile = new SimpleBlastFile(source);
436       }
437       else if (format.equals(PhylipFile.FILE_DESC))
438       {
439         alignFile = new PhylipFile(source);
440       }
441       else if (format.equals(IdentifyFile.GFF3File))
442       {
443         alignFile = new Gff3File(inFile, type);
444       }
445       else if (format.equals(JSONFile.FILE_DESC))
446       {
447         alignFile = new JSONFile(source);
448         al = new Alignment(alignFile.getSeqsAsArray());
449         alignFile.addAnnotations(al);
450         alignFile.addSeqGroups(al);
451         return al;
452       }
453       else if (format.equals(HtmlFile.FILE_DESC))
454       {
455         alignFile = new HtmlFile(source);
456       }
457       al = new Alignment(alignFile.getSeqsAsArray());
458       alignFile.addAnnotations(al);
459
460       return al;
461     } catch (Exception e)
462     {
463       e.printStackTrace();
464       System.err.println("Failed to read alignment using the '" + format
465               + "' reader.\n" + e);
466
467       if (e.getMessage() != null
468               && e.getMessage().startsWith(INVALID_CHARACTERS))
469       {
470         throw new java.io.IOException(e.getMessage());
471       }
472
473       // Finally test if the user has pasted just the sequence, no id
474       if (type.equalsIgnoreCase("Paste"))
475       {
476         try
477         {
478           // Possible sequence is just residues with no label
479           alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
480           Alignment al = new Alignment(alignFile.getSeqsAsArray());
481           alignFile.addAnnotations(al);
482           alignFile.addSeqGroups(al);
483           return al;
484
485         } catch (Exception ex)
486         {
487           if (ex.toString().startsWith(INVALID_CHARACTERS))
488           {
489             throw new java.io.IOException(e.getMessage());
490           }
491
492           ex.printStackTrace();
493         }
494       }
495
496       // If we get to this stage, the format was not supported
497       throw new java.io.IOException(SUPPORTED_FORMATS);
498     }
499   }
500
501
502   /**
503    * create an alignment flatfile from a Jalview alignment view
504    * @param format
505    * @param jvsuffix
506    * @param av
507    * @param selectedOnly
508    * @return flatfile in a string
509    */
510   public String formatSequences(String format, boolean jvsuffix,
511           AlignViewportI av, boolean selectedOnly)
512   {
513
514     AlignmentView selvew = av.getAlignmentView(selectedOnly, false);
515     AlignmentI aselview = selvew.getVisibleAlignment(av
516             .getGapCharacter());
517     List<AlignmentAnnotation> ala = (av
518             .getVisibleAlignmentAnnotation(selectedOnly));
519     if (ala != null)
520     {
521       for (AlignmentAnnotation aa : ala)
522       {
523         aselview.addAnnotation(aa);
524       }
525     }
526
527     return formatSequences(format, aselview, jvsuffix);
528   }
529
530   /**
531    * Construct an output class for an alignment in a particular filetype TODO:
532    * allow caller to detect errors and warnings encountered when generating
533    * output
534    *
535    * @param format
536    *          string name of alignment format
537    * @param alignment
538    *          the alignment to be written out
539    * @param jvsuffix
540    *          passed to AlnFile class controls whether /START-END is added to
541    *          sequence names
542    *
543    * @return alignment flat file contents
544    */
545   public String formatSequences(String format, AlignmentI alignment,
546           boolean jvsuffix)
547   {
548     try
549     {
550       AlignFile afile = null;
551       if (format.equalsIgnoreCase("FASTA"))
552       {
553         afile = new FastaFile();
554       }
555       else if (format.equalsIgnoreCase("MSF"))
556       {
557         afile = new MSFfile();
558       }
559       else if (format.equalsIgnoreCase("PileUp"))
560       {
561         afile = new PileUpfile();
562       }
563       else if (format.equalsIgnoreCase("CLUSTAL"))
564       {
565         afile = new ClustalFile();
566       }
567       else if (format.equalsIgnoreCase("BLC"))
568       {
569         afile = new BLCFile();
570       }
571       else if (format.equalsIgnoreCase("PIR"))
572       {
573         afile = new PIRFile();
574       }
575       else if (format.equalsIgnoreCase("PFAM"))
576       {
577         afile = new PfamFile();
578       }
579       else if (format.equalsIgnoreCase("STH"))
580       {
581         afile = new StockholmFile(alignment);
582       }
583       else if (format.equalsIgnoreCase("AMSA"))
584       {
585         afile = new AMSAFile(alignment);
586       }
587       else if (format.equalsIgnoreCase(PhylipFile.FILE_DESC))
588       {
589         afile = new PhylipFile();
590       }
591        else if (format.equalsIgnoreCase(JSONFile.FILE_DESC))
592        {
593         afile = new JSONFile();
594         afile.setViewport(viewport);
595         // Add groups to AlignFile
596         afile.seqGroups = alignment.getGroups();
597
598         // Add non auto calculated annotation to AlignFile
599         for (AlignmentAnnotation annot : alignment.getAlignmentAnnotation())
600         {
601           if (annot != null && !annot.autoCalculated)
602           {
603             if (annot.label.equals("PDB.CATempFactor"))
604             {
605               continue;
606             }
607             afile.annotations.add(annot);
608           }
609         }
610        }
611       else if (format.equalsIgnoreCase("RNAML"))
612       {
613         afile = new RnamlFile();
614       }
615
616       else
617       {
618         throw new Exception(MessageManager.getString("error.implementation_error_unknown_file_format_string"));
619       }
620       afile.setNewlineString(newline);
621       afile.addJVSuffix(jvsuffix);
622
623       afile.setSeqs(alignment.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           Alignment 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 }