return (vals == null || vals.size() == 0) ? null : vals.get(0);
}
+ public static boolean hasValue(Map<Arg, ArgValues> m, Arg a)
+ {
+ if (!m.containsKey(a))
+ return false;
+ return getValue(m, a) != null;
+ }
+
public static boolean getBoolean(Map<Arg, ArgValues> m, Arg a)
{
ArgValues av = getArgValues(m, a);
package jalview.bin;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
{
for (String id : argParser.linkedIds())
{
- Console.debug("##### id=" + id);
Commands cmds = new Commands();
if (id == null)
{
af.getCurrentView().setWrapAlignment(true);
}
+ // colour aligment?
+ if (ArgParser.hasValue(m, Arg.COLOUR))
+ {
+ af.changeColour_actionPerformed(
+ ArgParser.getValue(m, Arg.COLOUR));
+ }
+
// change alignment frame title
if (ArgParser.getValue(m, Arg.TITLE) != null)
af.setTitle(ArgParser.getValue(m, Arg.TITLE));
af.getCurrentView().addFile(new File(openFile), format);
}
- System.out
- .println("Command " + Arg.OPEN + " executed successfully!");
+ Console.debug("Command " + Arg.OPEN + " executed successfully!");
}
if (first) // first=true means nothing opened
}
- // load a pAE file if given
- if (ArgParser.getValues(m, Arg.PAEMATRIX) != null)
- {
- AlignFrame af = afMap.get(id);
- if (af != null)
- {
- for (String val : ArgParser.getValues(m, Arg.PAEMATRIX))
- {
- SubVal subVal = ArgParser.getSubVal(val);
- File paeFile = new File(subVal.content);
- String structId = "structid".equals(subVal.keyName)
- ? subVal.keyValue
- : null;
- if (subVal.notSet())
- {
- // take structid from pdbfilename
- }
- if ("structfile".equals(subVal.keyName))
- {
- EBIAlfaFold.addAlphaFoldPAEToStructure(
- af.getCurrentView().getAlignment(), paeFile,
- subVal.index, subVal.keyValue, false);
- }
- else if ("structid".equals(subVal.keyName))
- {
- EBIAlfaFold.addAlphaFoldPAEToStructure(
- af.getCurrentView().getAlignment(), paeFile,
- subVal.index, subVal.keyValue, true);
- }
- else
- {
- EBIAlfaFold.addAlphaFoldPAEToSequence(
- af.getCurrentView().getAlignment(), paeFile,
- subVal.index,
- "seqid".equals(subVal.keyName) ? subVal.keyValue
- : null);
- // required to readjust the height and position of the pAE
- // annotation
- }
- for (AlignmentViewPanel ap : af.getAlignPanels())
- {
- ap.adjustAnnotationHeight();
- }
- }
- }
- }
-
// open the structure (from same PDB file or given PDBfile)
if (!ArgParser.getBoolean(m, Arg.NOSTRUCTURE))
{
}
}
+ // load a pAE file if given
+ if (ArgParser.getValues(m, Arg.PAEMATRIX) != null)
+ {
+ AlignFrame af = afMap.get(id);
+ if (af != null)
+ {
+ for (String val : ArgParser.getValues(m, Arg.PAEMATRIX))
+ {
+ SubVal subVal = ArgParser.getSubVal(val);
+ File paeFile = new File(subVal.content);
+ String paePath = null;
+ try
+ {
+ paePath = paeFile.getCanonicalPath();
+ } catch (IOException e)
+ {
+ paePath = paeFile.getAbsolutePath();
+ Console.warn(
+ "Problem with the PAE file path: '" + paePath + "'");
+ }
+ String structId = "structid".equals(subVal.keyName)
+ ? subVal.keyValue
+ : null;
+ if (subVal.notSet())
+ {
+ // take structid from pdbfilename
+ }
+ if ("structfile".equals(subVal.keyName))
+ {
+ Console.info("***** Attaching paeFile '" + paePath + "' to "
+ + subVal.keyName + "=" + subVal.keyValue);
+ EBIAlfaFold.addAlphaFoldPAEToStructure(
+ af.getCurrentView().getAlignment(), paeFile,
+ subVal.index, subVal.keyValue, false);
+ }
+ else if ("structid".equals(subVal.keyName))
+ {
+ Console.info("***** Attaching paeFile '" + paePath + "' to "
+ + subVal.keyName + "=" + subVal.keyValue);
+ EBIAlfaFold.addAlphaFoldPAEToStructure(
+ af.getCurrentView().getAlignment(), paeFile,
+ subVal.index, subVal.keyValue, true);
+ }
+ else
+ {
+ Console.debug("***** Attaching paeFile '" + paePath
+ + "' to sequence index " + subVal.index);
+ EBIAlfaFold.addAlphaFoldPAEToSequence(
+ af.getCurrentView().getAlignment(), paeFile,
+ subVal.index, null);
+ // required to readjust the height and position of the pAE
+ // annotation
+ }
+ for (AlignmentViewPanel ap : af.getAlignPanels())
+ {
+ ap.adjustAnnotationHeight();
+ }
+ }
+ }
+ }
+
boolean doShading = ArgParser.getBoolean(m, Arg.TEMPFAC_SHADING);
if (doShading)
{
*/
package jalview.bin;
+import java.util.Locale;
+
import jalview.log.JLogger;
+import jalview.log.JLoggerI;
import jalview.log.JLoggerI.LogLevel;
import jalview.log.JLoggerLog4j;
import jalview.util.ChannelProperties;
// Test message
if (log != null)
{
- // Logging test message should got through the logger object
+ // Logging test message should go through the logger object
if (log.loggerExists())
log.debug(Console.LOGGING_TEST_MESSAGE);
// Tell the user that debug is enabled
}
}
+ public static void setLogLevel(String logLevelString)
+ {
+ for (LogLevel logLevel : JLoggerI.LogLevel.values())
+ {
+ if (logLevel.toString().toLowerCase(Locale.ROOT)
+ .equals(logLevelString.toLowerCase(Locale.ROOT)))
+ {
+ log.setLevel(logLevel);
+ if (!Platform.isJS())
+ {
+ Log4j.init(logLevel);
+ }
+ JLoggerLog4j.getLogger("org.apache.axis", logLevel);
+ break;
+ }
+ }
+ }
+
public final static String LOGGING_TEST_MESSAGE = "Logging to STDERR";
}
// old ArgsParser
ArgsParser aparser = new ArgsParser(args);
- // new ArgParser
- ArgParser argparser = new ArgParser(args);
boolean headless = false;
+ try
+ {
+ Console.initLogger();
+ } catch (NoClassDefFoundError error)
+ {
+ error.printStackTrace();
+ System.out.println("\nEssential logging libraries not found."
+ + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
+ System.exit(0);
+ }
+
String usrPropsFile = aparser.getValue("props");
Cache.loadProperties(usrPropsFile); // must do this before
if (usrPropsFile != null)
"CMD [-props " + usrPropsFile + "] executed successfully!");
}
+ // set log level from cache properties
+ Console.setLogLevel(Cache.getDefault(Cache.JALVIEWLOGLEVEL, "INFO"));
+
+ // new ArgParser
+ ArgParser argparser = new ArgParser(args); // do this after
+ // Console.initLogger, but TODO
+ // want --props before then
+ // CATCH22
+
+ if (argparser.isSet(Arg.HEADLESS))
+ headless = argparser.getBool(Arg.HEADLESS);
+ boolean commandsSuccess = Commands.processArgs(argparser, headless);
+ if (commandsSuccess)
+ {
+ Console.info("Successfully completed commands");
+ if (headless)
+ System.exit(0);
+ }
+ else
+ {
+ Console.warn("Error when running commands");
+ if (headless)
+ System.exit(1);
+ }
+
if (!Platform.isJS())
/**
* Java only
System.setProperty("http.agent",
"Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
- try
- {
- Console.initLogger();
- } catch (NoClassDefFoundError error)
- {
- error.printStackTrace();
- System.out.println("\nEssential logging libraries not found."
- + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
- System.exit(0);
- }
-
desktop = null;
setLookAndFeel();
}.start();
}
- if (argparser.isSet(Arg.HEADLESS))
- headless = argparser.getBool(Arg.HEADLESS);
- if (Commands.processArgs(argparser, headless))
- {
- System.exit(1);
- }
-
String file = null, data = null;
FileFormatI format = null;
DataSourceType protocol = null;
@Override
public void setProgressBar(String message, long id)
{
- progressBar.setProgressBar(message, id);
+ if (!Platform.isHeadless())
+ progressBar.setProgressBar(message, id);
}
@Override
import jalview.structure.StructureMapping;
import jalview.structure.StructureSelectionManager;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import jalview.ws.DBRefFetcher;
import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
import jalview.ws.seqfetcher.DbSourceProxy;
@Override
public void setProgressBar(String message, long id)
{
- progressBar.setProgressBar(message, id);
+ if (!Platform.isHeadless())
+ progressBar.setProgressBar(message, id);
}
@Override
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.util.MessageManager;
+import jalview.util.StringUtils;
/**
* DOCUMENT ME!
{
Sequence seq = null;
id = id.trim();
- int space = id.indexOf(" ");
+ int space = StringUtils.indexOfFirstWhitespace(id);
if (space > -1)
{
seq = new Sequence(id.substring(0, space), "");
public static JLogger getLogger(Class c)
{
- return getLogger(c);
+ return getLogger(c, LogLevel.INFO);
}
public static JLogger getLogger(Class c, LogLevel loglevel)
--- /dev/null
+package jalview.util;
+
+import java.util.Map;
+
+public class MapUtils
+{
+ /*
+ * Return the value of the first key that exists in the map
+ */
+ public static <K, V> V getFirst(Map<K, V> map, K... keys)
+ {
+ return getFirst(false, map, keys);
+ }
+
+ public static <K, V> V getFirst(boolean nonNull, Map<K, V> map, K... keys)
+ {
+ for (K key : keys)
+ {
+ if (map.containsKey(key))
+ {
+ if (!(nonNull && (map.get(key) == null)))
+ {
+ return map.get(key);
+ }
+ else if (!nonNull)
+ {
+ return map.get(key);
+ }
+ }
+ }
+ return null;
+ }
+
+ public static <K> boolean containsAKey(Map<K, ?> map, K... keys)
+ {
+ for (K key : keys)
+ {
+ if (map.containsKey(key))
+ return true;
+ }
+ return false;
+ }
+}
import java.util.ResourceBundle.Control;
import java.util.Set;
-import jalview.log.JLoggerLog4j;
+import jalview.bin.Console;
/**
*
{
private static ResourceBundle rb;
- private static JLoggerLog4j log = JLoggerLog4j
- .getLogger(MessageManager.class.getCanonicalName());
-
private static Locale loc;
private static Set<String> reportedMissing = new HashSet<>();
loc = Locale.getDefault();
// Locale.setDefault(loc);
/* Getting messages for GV */
- log.info("Getting messages for lang: " + loc);
+ Console.info("Getting messages for lang: " + loc);
Control control = Control.getControl(Control.FORMAT_PROPERTIES);
rb = ResourceBundle.getBundle("lang.Messages", loc, control);
// if (log.isLoggable(Level.FINEST))
// }
} catch (Exception q)
{
- log.warn("Exception when initting Locale for i18n messages\n"
+ Console.warn("Exception when initting Locale for i18n messages\n"
+ q.getMessage());
q.printStackTrace();
} catch (Error v)
{
- log.warn("Error when initting Locale for i18n messages\n"
+ Console.warn("Error when initting Locale for i18n messages\n"
+ v.getMessage());
v.printStackTrace();
}
return MessageFormat.format(rb.getString(key), params);
} catch (Exception e)
{
- log.warn("I18N missing: " + loc + "\t" + key);
+ Console.warn("I18N missing: " + loc + "\t" + key);
}
String value = "[missing key] " + key + "";
for (Object p : params)
if (!reportedMissing.contains(key))
{
reportedMissing.add(key);
- log.info(msg);
+ Console.info(msg);
}
}
}
*/
package jalview.util;
-import java.util.Locale;
-
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringUtils
}
return min < text.length() + 1 ? min : -1;
}
+
+ public static int indexOfFirstWhitespace(String text)
+ {
+ int index = -1;
+ Pattern pat = Pattern.compile("\\s");
+ Matcher m = pat.matcher(text);
+ if (m.find())
+ {
+ index = m.start();
+ }
+ return index;
+ }
}
import jalview.datamodel.ContactListProviderI;
import jalview.datamodel.ContactMatrixI;
import jalview.datamodel.SequenceI;
+import jalview.util.MapUtils;
public class PAEContactMatrix implements ContactMatrixI
{
// convert the lists to primitive arrays and store
length = _refSeq.getEnd() - _refSeq.getStart() + 1;
- if (!pae_obj.containsKey("predicted_aligned_error"))
+ if (!MapUtils.containsAKey(pae_obj, "predicted_aligned_error", "pae"))
{
parse_version_1_pAE(pae_obj);
return;
{
elements = new float[length][length];
// this is never going to be reached by the integer rounding.. or is it ?
- maxscore = ((Double) pae_obj.get("max_predicted_aligned_error"))
- .floatValue();
- Iterator<List<Long>> scoreRows = ((List<List<Long>>) pae_obj
- .get("predicted_aligned_error")).iterator();
+ maxscore = ((Double) MapUtils.getFirst(pae_obj,
+ "max_predicted_aligned_error", "max_pae")).floatValue();
+ Iterator<List<Long>> scoreRows = ((List<List<Long>>) MapUtils
+ .getFirst(pae_obj, "predicted_aligned_error", "pae"))
+ .iterator();
int row = 0, col = 0;
while (scoreRows.hasNext())
{
elements[row - 1][col - 1] = escore;
}
- maxscore = ((Double) pae_obj.get("max_predicted_aligned_error"))
- .floatValue();
+ maxscore = ((Double) MapUtils.getFirst(pae_obj,
+ "max_predicted_aligned_error", "max_pae")).floatValue();
}
@Override
import java.util.List;
import java.util.Map;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
import com.stevesoft.pat.Regex;
for (int i = 0; i < seqs.length; i++)
{
SequenceI s = seqs[i];
- Console.debug("******* sequences[" + i + "]='" + s.getName() + "'");
}
}
/* end debug */
}
if (sequence == null)
{
- Console.debug("***** Looking for sequence with id '" + seqId + "'");
-
SequenceI[] sequences = pdbAlignment.findSequenceMatch(seqId);
if (sequences == null || sequences.length < 1)
{
}
}
- List<Object> pae_obj = (List<Object>) Platform.parseJSON(pae_input);
- if (pae_obj == null)
+ Object paeJson = Platform.parseJSON(pae_input);
+ JSONObject paeDict = null;
+ if (paeJson instanceof JSONObject)
+ {
+ Console.debug("***** paeJson is a JSONObject");
+ paeDict = (JSONObject) paeJson;
+ }
+ else if (paeJson instanceof JSONArray)
+ {
+ JSONArray jsonArray = (JSONArray) paeJson;
+ if (jsonArray.size() > 0)
+ paeDict = (JSONObject) jsonArray.get(0);
+ }
+
+ if (paeDict == null)
{
Console.debug("JSON file did not parse properly.");
return false;
}
ContactMatrixI matrix = new PAEContactMatrix(sequence,
- (Map<String, Object>) pae_obj.get(0));
+ (Map<String, Object>) paeDict);
AlignmentAnnotation cmannot = sequence.addContactList(matrix);
pdbAlignment.addAnnotation(cmannot);
+
return true;
}