use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class StatementTransformationUtil method mapVariationStatementToEntry.
/**
* @param variationStatement
* Can be a variant or mutagenesis
* @param result
* @return
*/
static Statement mapVariationStatementToEntry(Statement variationStatement, FeatureQuerySuccess result) {
String beginPositionOfCanonicalOrIsoSpec = null;
String endPositionOfCanonicalOrIsoSpec = null;
String masterBeginPosition = null;
String masterEndPosition = null;
String isoCanonical = null;
TargetIsoformSet targetIsoforms = new TargetIsoformSet();
for (IsoformFeatureResult isoformFeatureResult : result.getData().values()) {
if (isoformFeatureResult.isMapped()) {
targetIsoforms.add(new TargetIsoformStatementPosition(isoformFeatureResult.getIsoformAccession(), isoformFeatureResult.getBeginIsoformPosition(), // Target
isoformFeatureResult.getEndIsoformPosition(), // Target
IsoTargetSpecificity.UNKNOWN.name(), // propagated)
isoformFeatureResult.getIsoSpecificFeature()));
// canonical
if (beginPositionOfCanonicalOrIsoSpec == null) {
beginPositionOfCanonicalOrIsoSpec = String.valueOf(isoformFeatureResult.getBeginIsoformPosition());
}
if (endPositionOfCanonicalOrIsoSpec == null) {
endPositionOfCanonicalOrIsoSpec = String.valueOf(isoformFeatureResult.getEndIsoformPosition());
}
// If possible use canonical
if (isoformFeatureResult.isCanonical()) {
if (isoCanonical != null) {
throw new NextProtException("Canonical position set already");
}
isoCanonical = isoformFeatureResult.getIsoformAccession();
beginPositionOfCanonicalOrIsoSpec = String.valueOf(isoformFeatureResult.getBeginIsoformPosition());
endPositionOfCanonicalOrIsoSpec = String.valueOf(isoformFeatureResult.getEndIsoformPosition());
}
if (masterBeginPosition == null) {
masterBeginPosition = String.valueOf(isoformFeatureResult.getBeginMasterPosition());
}
if (masterEndPosition == null) {
masterEndPosition = String.valueOf(isoformFeatureResult.getEndMasterPosition());
}
if (masterBeginPosition != null) {
if (!masterBeginPosition.equals(String.valueOf(isoformFeatureResult.getBeginMasterPosition()))) {
throw new NextProtException("Begin master position " + masterBeginPosition + " does not match " + String.valueOf(isoformFeatureResult.getBeginMasterPosition() + " for different isoforms (" + result.getData().values().size() + ") for statement " + variationStatement.getStatementId()));
}
}
if (masterEndPosition != null) {
if (!masterEndPosition.equals(String.valueOf(isoformFeatureResult.getEndMasterPosition()))) {
throw new NextProtException("End master position does not match for different isoforms" + variationStatement.getStatementId());
}
}
}
}
Statement rs = // Keep
StatementBuilder.createNew().addMap(variationStatement).addField(StatementField.RAW_STATEMENT_ID, variationStatement.getStatementId()).addField(StatementField.LOCATION_BEGIN, beginPositionOfCanonicalOrIsoSpec).addField(StatementField.LOCATION_END, endPositionOfCanonicalOrIsoSpec).addField(StatementField.LOCATION_BEGIN_MASTER, masterBeginPosition).addField(StatementField.LOCATION_END_MASTER, masterEndPosition).addField(StatementField.ISOFORM_CANONICAL, isoCanonical).addField(StatementField.TARGET_ISOFORMS, targetIsoforms.serializeToJsonString()).buildWithAnnotationHash(AnnotationType.ENTRY);
return rs;
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class StatementTranformerServiceImpl method getIsoAccession.
private String getIsoAccession(String featureName, String entryAccession) {
SequenceVariant sv;
try {
sv = new SequenceVariant(featureName);
} catch (ParseException e) {
throw new NextProtException(e);
}
List<Isoform> isoforms = isoformService.findIsoformsByEntryName(entryAccession);
Isoform isoSpecific = IsoformUtils.getIsoformByName(isoforms, sv.getIsoformName());
return isoSpecific.getIsoformAccession();
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class BlastResultUpdaterServiceImpl method updateDescription.
@Override
public void updateDescription(Description description, String isoAccession, String entryAccession) {
MainNames entryNames = mainNamesService.findIsoformOrEntryMainName(entryAccession).orElseThrow(() -> new NextProtException("could not find informations for entry " + entryAccession));
MainNames isoNames = mainNamesService.findIsoformOrEntryMainName(isoAccession).orElseThrow(() -> new NextProtException("could not find informations for isoform " + isoAccession));
String geneName = (!entryNames.getGeneNameList().isEmpty()) ? entryNames.getGeneNameList().get(0) : null;
String proteinName = entryNames.getName();
String title = proteinName + ((geneName != null) ? " (" + geneName + ")" : "") + " [" + isoNames.getAccession() + "]";
description.setTitle(title);
description.setEntryAccession(entryNames.getAccession());
description.setIsoAccession(isoNames.getAccession());
description.setIsoName(isoNames.getName());
description.setProteinName(proteinName);
description.setGeneName(geneName);
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class BlastProgram method process.
private O process(List<String> commandLine) throws ExceptionWithReason {
SystemCommandExecutor commandExecutor = new SystemCommandExecutor(commandLine);
try {
commandExecutor.executeCommand();
String stderr = commandExecutor.getLastExecutionStandardError();
if (!stderr.isEmpty()) {
ExceptionWithReason ewr = new ExceptionWithReason();
ewr.getReason().addCause(name + " exception", stderr.replace("\n", " "));
ewr.getReason().setMessage("Error while executing " + name);
throw ewr;
}
return buildOutputFromStdout(commandExecutor.getLastExecutionStandardOutput());
} catch (InterruptedException | IOException e) {
throw new NextProtException("Internal error: cannot process " + name + " command line " + commandLine, e);
}
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class UserProteinListUtils method combine.
/**
* Apply the given operator to two user protein lists in a new instance of
* {@code UserProteinList}
*
* @param l1 first user protein list
* @param l2 second user protein list
* @param operator operator applied to operands
* @param username combined list user name
* @param name combined list name
* @param description combined list description
* @return a new user protein list combining l1 and l2
*/
public static UserProteinList combine(UserProteinList l1, UserProteinList l2, Operator operator, String username, String name, String description) {
NPreconditions.checkNotNull(l1, "The first user protein list should not be null");
NPreconditions.checkNotNull(l2, "The second user protein list should not be null");
NPreconditions.checkNotNull(operator, "The combine operator should not be null");
NPreconditions.checkNotNull(name, "The user protein list name should not be null");
NPreconditions.checkNotNull(username, "The user protein list user name should not be null");
NPreconditions.checkTrue(!l1.equals(l2), "Can't make combination with the same lists");
Set<String> combined = new HashSet<>();
if (operator.equals(Operator.AND)) {
combined.addAll(Sets.intersection(l1.getAccessionNumbers(), l2.getAccessionNumbers()));
} else if (operator.equals(Operator.OR)) {
combined = Sets.union(l1.getAccessionNumbers(), l2.getAccessionNumbers());
} else if (operator.equals(Operator.NOT_IN)) {
combined.addAll(Sets.difference(l1.getAccessionNumbers(), l2.getAccessionNumbers()));
}
if (combined.isEmpty())
throw new NextProtException("The combined list is empty. Only combinations resulting on non-empty lists are saved.");
UserProteinList combinedProteinList = new UserProteinList();
combinedProteinList.setName(name);
combinedProteinList.setOwner(username);
combinedProteinList.setDescription(description);
combinedProteinList.setAccessions(combined);
return combinedProteinList;
}
Aggregations