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