residues = executeCommand(cmd, true);
boolean featureAdded = createFeaturesForAttributes(attName, residues);
if (featureAdded)
{
alignmentPanel.getFeatureRenderer().featuresAdded();
}
}
/**
* Create features in Jalview for the given attribute name and structure
* residues.
*
*
* The residue list should be 0, 1 or more reply lines of the format:
* residue id #0:5.A isHelix -155.000836316 index 5
* or
* residue id #0:6.A isHelix None
*
*
* @param attName
* @param residues
* @return
*/
protected boolean createFeaturesForAttributes(String attName,
List residues)
{
boolean featureAdded = false;
String featureGroup = getViewerFeatureGroup();
boolean chimeraX = chimeraManager.isChimeraX();
for (String residue : residues)
{
AtomSpec spec = null;
String[] tokens = residue.split(" ");
if (tokens.length < 5)
{
continue;
}
String atomSpec = tokens[2];
String attValue = tokens[4];
/*
* ignore 'None' (e.g. for phi) or 'False' (e.g. for isHelix)
*/
if ("None".equalsIgnoreCase(attValue)
|| "False".equalsIgnoreCase(attValue))
{
continue;
}
try
{
spec = AtomSpec.fromChimeraAtomspec(atomSpec, chimeraX);
} catch (IllegalArgumentException e)
{
System.err.println("Problem parsing atomspec " + atomSpec);
continue;
}
String chainId = spec.getChain();
String description = attValue;
float score = Float.NaN;
try
{
score = Float.valueOf(attValue);
description = chainId;
} catch (NumberFormatException e)
{
// was not a float value
}
String pdbFile = getPdbFileForModel(spec.getModelNumber());
spec.setPdbFile(pdbFile);
List atoms = Collections.singletonList(spec);
/*
* locate the mapped position in the alignment (if any)
*/
SearchResultsI sr = getSsm()
.findAlignmentPositionsForStructurePositions(atoms);
/*
* expect one matched alignment position, or none
* (if the structure position is not mapped)
*/
for (SearchResultMatchI m : sr.getResults())
{
SequenceI seq = m.getSequence();
int start = m.getStart();
int end = m.getEnd();
SequenceFeature sf = new SequenceFeature(attName, description,
start, end, score, featureGroup);
// todo: should SequenceFeature have an explicit property for chain?
// note: repeating the action shouldn't duplicate features
featureAdded |= seq.addSequenceFeature(sf);
}
}
return featureAdded;
}
/**
* Answers the feature group name to apply to features created in Jalview from
* Chimera attributes
*
* @return
*/
protected String getViewerFeatureGroup()
{
// todo pull up to interface
return CHIMERA_FEATURE_GROUP;
}
@Override
public int getModelNoForFile(String pdbFile)
{
List foundModels = chimeraMaps.get(pdbFile);
if (foundModels != null && !foundModels.isEmpty())
{
return foundModels.get(0).getModelNumber();
}
return -1;
}
/**
* Answers a (possibly empty) list of attribute names in Chimera[X], excluding
* any which were added from Jalview
*
* @return
*/
public List getChimeraAttributes()
{
List atts = chimeraManager.getAttrList();
Iterator it = atts.iterator();
while (it.hasNext())
{
if (it.next().startsWith(ChimeraCommands.NAMESPACE_PREFIX))
{
/*
* attribute added from Jalview - exclude it
*/
it.remove();
}
}
return atts;
}
public boolean isChimeraX()
{
return chimeraManager.isChimeraX();
}
}