package jalview.io;
+import jalview.datamodel.PDBEntry;
import jalview.ext.jmol.JmolParser;
import jalview.structure.StructureImportSettings;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public enum FileFormat implements FileFormatI
{
- Fasta
+ Fasta("Fasta", "fa, fasta, mfa, fastq", true, true)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
return new FastaFile();
}
},
- Pfam
+ Pfam("PFAM", "pfam", true, true)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
return new PfamFile();
}
},
- Stockholm
+ Stockholm("Stockholm", "sto,stk", true, true)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
}
},
- SimpleBlast
+
+ PIR("PIR", "pir", true, true)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
DataSourceType sourceType) throws IOException
{
- return new SimpleBlastFile(inFile, sourceType);
+ return new PIRFile(inFile, sourceType);
}
-
@Override
public AlignmentFileI getAlignmentFile(FileParse source)
throws IOException
{
- return new SimpleBlastFile(source);
+ return new PIRFile(source);
}
@Override
public AlignmentFileI getAlignmentFile()
{
- return new SimpleBlastFile();
+ return new PIRFile();
}
},
-
- PIR
+ BLC("BLC", "BLC", true, true)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
DataSourceType sourceType) throws IOException
{
- return new PIRFile(inFile, sourceType);
- }
- @Override
+ return new BLCFile(inFile, sourceType);
+ } @Override
public AlignmentFileI getAlignmentFile(FileParse source)
throws IOException
{
- return new PIRFile(source);
+ return new BLCFile(source);
}
@Override
public AlignmentFileI getAlignmentFile()
{
- return new PIRFile();
+ return new BLCFile();
}
},
- BLC
+ AMSA("AMSA", "amsa", true, true)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
DataSourceType sourceType) throws IOException
{
- return new BLCFile(inFile, sourceType);
- } @Override
+ return new AMSAFile(inFile, sourceType);
+ }
+
+ @Override
public AlignmentFileI getAlignmentFile(FileParse source)
throws IOException
{
- return new BLCFile(source);
+ return new AMSAFile(source);
}
@Override
{
return new BLCFile();
}
-
},
- Html
+ Html("HTML", "html", true, false)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
}
},
- Rnaml
+ Rnaml("RNAML", "xml,rnaml", true, false)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
}
},
- Json
+ Json("JSON","json", true, true)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
}
},
- Pileup
+ Pileup("PileUp", "pileup", false, true)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
}
},
- MSF
+ MSF("MSF", "msf", true, true)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
}
},
- Clustal
+ Clustal("Clustal", "aln", true, true)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
{
return new ClustalFile();
}
-
},
- Phylip
+ Phylip("PHYLIP", "phy", true, true)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
{
return new PhylipFile();
}
-
},
- Jnet
+ Jnet("JnetFile", "", false, false)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
}
},
- Features
+ Features("GFF or Jalview features", "gff2,gff3", false, false)
{
@Override
public AlignmentFileI getAlignmentFile(String inFile,
return new FeaturesFile();
}
},
- PDB
+ PDB("PDB", "", false, false)
{
@Override
{
// TODO obtain config value from preference settings.
// Set value to 'true' to test PDB processing with Jmol: JAL-1213
- boolean isParseWithJMOL = !StructureImportSettings
- .getCurrentDefaultFormat().equalsIgnoreCase("PDB");
+ boolean isParseWithJMOL = StructureImportSettings
+ .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
if (isParseWithJMOL)
{
return new JmolParser(
StructureImportSettings.isVisibleChainAnnotation(),
- StructureImportSettings.isPredictSecondaryStructure(),
+ StructureImportSettings.isProcessSecondaryStructure(),
StructureImportSettings.isExternalSecondaryStructure(),
inFile,
sourceType);
StructureImportSettings.setShowSeqFeatures(true);
return new MCview.PDBfile(
StructureImportSettings.isVisibleChainAnnotation(),
- StructureImportSettings.isPredictSecondaryStructure(),
+ StructureImportSettings.isProcessSecondaryStructure(),
StructureImportSettings.isExternalSecondaryStructure(),
inFile,
sourceType);
public AlignmentFileI getAlignmentFile(FileParse source)
throws IOException
{
- boolean isParseWithJMOL = !StructureImportSettings
- .getCurrentDefaultFormat().equalsIgnoreCase("PDB");
+ boolean isParseWithJMOL = StructureImportSettings
+ .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
if (isParseWithJMOL)
{
return new JmolParser(
StructureImportSettings.isVisibleChainAnnotation(),
- StructureImportSettings.isPredictSecondaryStructure(),
+ StructureImportSettings.isProcessSecondaryStructure(),
StructureImportSettings.isExternalSecondaryStructure(),
source);
}
StructureImportSettings.setShowSeqFeatures(true);
return new MCview.PDBfile(
StructureImportSettings.isVisibleChainAnnotation(),
- StructureImportSettings.isPredictSecondaryStructure(),
+ StructureImportSettings.isProcessSecondaryStructure(),
StructureImportSettings.isExternalSecondaryStructure(),
source);
}
{
return new JmolParser(); // todo or null?
}
-
},
- MMCif
+ MMCif("mmCIF", "cif", false, false)
{
@Override
{
return new JmolParser(
StructureImportSettings.isVisibleChainAnnotation(),
- StructureImportSettings.isPredictSecondaryStructure(),
+ StructureImportSettings.isProcessSecondaryStructure(),
StructureImportSettings.isExternalSecondaryStructure(),
inFile, sourceType);
}
{
return new JmolParser(
StructureImportSettings.isVisibleChainAnnotation(),
- StructureImportSettings.isPredictSecondaryStructure(),
+ StructureImportSettings.isProcessSecondaryStructure(),
StructureImportSettings.isExternalSecondaryStructure(),
source);
}
return new JmolParser(); // todo or null?
}
},
- Jalview
+ Jalview("Jalview", "jar,jvp", true, false)
{
@Override
}
};
+ /**
+ * A lookup map of enums by upper-cased name
+ */
+ private static Map<String, FileFormat> names;
+ static
+ {
+ names = new HashMap<String, FileFormat>();
+ for (FileFormat format : FileFormat.values())
+ {
+ names.put(format.toString().toUpperCase(), format);
+ }
+ }
+
+ private boolean writable;
+
+ private boolean readable;
+
+ private String extensions;
+
+ private String name;
+
+ /**
+ * Answers a list of writeable file formats (as string, corresponding to the
+ * toString() and forName() methods)
+ *
+ * @return
+ */
+ public static List<String> getWritableFormats()
+ {
+ List<String> l = new ArrayList<String>();
+ for (FileFormatI ff : values())
+ {
+ if (ff.isWritable())
+ {
+ l.add(ff.toString());
+ }
+ }
+ return l;
+ }
+
+ /**
+ * Answers a list of readable file formats (as string, corresponding to the
+ * toString() and forName() methods)
+ *
+ * @return
+ */
+ public static List<String> getReadableFormats()
+ {
+ List<String> l = new ArrayList<String>();
+ for (FileFormatI ff : values())
+ {
+ if (ff.isReadable())
+ {
+ l.add(ff.toString());
+ }
+ }
+ return l;
+ }
+
@Override
public boolean isComplexAlignFile()
{
{
return toString();
}
+
+ /**
+ * Returns the file format with the given name, or null if format is null or
+ * invalid. Unlike valueOf(), this is not case-sensitive, to be kind to
+ * writers of javascript.
+ *
+ * @param format
+ * @return
+ */
+ public static FileFormatI forName(String format)
+ {
+ // or could store format.getShortDescription().toUpperCase()
+ // in order to decouple 'given name' from enum name
+ return format == null ? null : names.get(format.toUpperCase());
+ }
+
+ @Override
+ public boolean isReadable()
+ {
+ return readable;
+ }
+
+ @Override
+ public boolean isWritable()
+ {
+ return writable;
+ }
+
+ /**
+ * Constructor
+ *
+ * @param shortName
+ * @param extensions
+ * comma-separated list of file extensions associated with the format
+ * @param isReadable
+ * @param isWritable
+ */
+ private FileFormat(String shortName, String extensions,
+ boolean isReadable, boolean isWritable)
+ {
+ this.name = shortName;
+ this.extensions = extensions;
+ this.readable = isReadable;
+ this.writable = isWritable;
+ }
+
+ @Override
+ public String getExtensions()
+ {
+ return extensions;
+ }
+
+ @Override
+ public String toString()
+ {
+ return name;
+ }
}