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