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