JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / io / Gff3File.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 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.AlignedCodonFrame;
25 import jalview.datamodel.Alignment;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.SequenceI;
28
29 import java.io.IOException;
30 import java.util.List;
31
32 /**
33  * A GFF3 File parsing wrapper for the tangled mess that is FeaturesFile.
34  * 
35  * This class implements the methods relied on by FileLoader/FormatAdapter in
36  * order to allow them to load alignments directly from GFF2 and GFF3 files that
37  * contain sequence data and alignment information.
38  * 
39  * Major issues:
40  * 
41  * 1. GFF3 files commonly include mappings between DNA, RNA and Protein - so
42  * this class needs a dataset AlignmentI context to create alignment codon
43  * mappings.
44  * 
45  * 2. A single GFF3 file can generate many distinct alignments. Support will be
46  * needed to allow several AlignmentI instances to be generated from a single
47  * file.
48  * 
49  * 
50  * @author jprocter
51  *
52  */
53 public class Gff3File extends FeaturesFile
54 {
55
56   /**
57    * 
58    */
59   public Gff3File()
60   {
61     super();
62   }
63
64   /**
65    * @param source
66    * @throws IOException
67    */
68   public Gff3File(FileParse source) throws IOException
69   {
70     super(source);
71   }
72
73   /**
74    * @param inFile
75    * @param type
76    * @throws IOException
77    */
78   public Gff3File(String inFile, String type) throws IOException
79   {
80     super(inFile, type);
81   }
82
83   /**
84    * @param parseImmediately
85    * @param source
86    * @throws IOException
87    */
88   public Gff3File(boolean parseImmediately, FileParse source)
89           throws IOException
90   {
91     super(parseImmediately, source);
92   }
93
94   /**
95    * @param parseImmediately
96    * @param inFile
97    * @param type
98    * @throws IOException
99    */
100   public Gff3File(boolean parseImmediately, String inFile, String type)
101           throws IOException
102   {
103     super(parseImmediately, inFile, type);
104   }
105
106   /*
107    * (non-Javadoc)
108    * 
109    * @see jalview.io.FeaturesFile#print()
110    */
111   @Override
112   public String print()
113   {
114     // TODO GFF3 writer with sensible defaults for writing alignment data
115
116     // return super.printGFFFormat(seqs, visible);
117     return ("Not yet implemented.");
118   }
119
120   AlignmentI dataset;
121
122   List<AlignmentI> alignments;
123
124   @Override
125   public void parse()
126   {
127     AlignViewportI av = getViewport();
128     if (av != null)
129     {
130       if (av.getAlignment() != null)
131       {
132         dataset = av.getAlignment().getDataset();
133       }
134       if (dataset == null)
135       {
136         // working in the applet context ?
137         dataset = av.getAlignment();
138       }
139     }
140     else
141     {
142       dataset = new Alignment(new SequenceI[] {});
143     }
144
145     boolean parseResult = parse(dataset, null, null, false, true);
146     if (!parseResult)
147     {
148       // pass error up somehow
149     }
150     if (av != null)
151     {
152       // update viewport with the dataset data ?
153     }
154     else
155     {
156       setSeqs(dataset.getSequencesArray());
157     }
158
159   }
160
161   @Override
162   public void addProperties(AlignmentI al)
163   {
164     super.addProperties(al);
165     if (dataset.getCodonFrames() != null)
166     {
167       AlignmentI ds = (al.getDataset() == null) ? al : al.getDataset();
168       for (AlignedCodonFrame codons : dataset.getCodonFrames())
169       {
170         ds.addCodonFrame(codons);
171       }
172     }
173   }
174 }