use of org.nextprot.api.web.domain.PepXResponse.PepXIsoformMatch in project nextprot-api by calipho-sib.
the class PepXServiceTest method shouldThrowAnExceptionWhenPepXGivesAVariantNotSpecificToTheIsoform.
@Test(expected = NextProtException.class)
public void shouldThrowAnExceptionWhenPepXGivesAVariantNotSpecificToTheIsoform() throws Exception {
try {
// Taking example NX_Q9H6T3
String peptide = "GANAP";
boolean modeIsoleucine = true;
String isoName = "NX_Q9H6T3-3";
Isoform iso1 = mock(Isoform.class);
when(iso1.getIsoformAccession()).thenReturn("another-iso-name");
when(iso1.getSequence()).thenReturn("MDADPYNPVLPTNRASAYFRLKKFAVAESDCNLAVALNRSYTKAYSRRGAARFALQKLEEAKKDYERVLELEPNNFEATNELRKISQALASKENSYPKEADIVIKSTEGERKQIEAQQNKQQAISEKDRGNGFFKEGKYERAIECYTRGIAADGANALLPANRAMAYLKIQKYEEAEKDCTQAILLDGSYSKAFARRGTARTFLGKLNEAKQDFETVLLLEPGNKQAVTELSKIKKELIEKGHWDDVFLDSTQRQNVVKPIDNPPHPGSTKPLKKVIIEETGNLIQTIDVPDSTTAAAPENNPINLANVIAATGTTSKKNSSQDDLFPTSDTPRAKVLKIEEVSDTSSLQPQASLKQDVCQSYSEKMPIEIEQKPAQFATTVLPPIPANSFQLESDFRQLKSSPDMLYQYLKQIEPSLYPKLFQKNLDPDVFNQIVKILHDFYIEKEKPLLIFEILQRLSELKRFDMAVMFMSETEKKIARALFNHIDKSGLKDSSVEELKKRYGG");
PepXIsoformMatch pepXIsoformMatch = new PepXIsoformMatch(isoName, 154);
List<Annotation> annots = Arrays.asList(getMockedAnnotation("L", "P", 158, isoName, true));
List<Isoform> isoforms = Arrays.asList(iso1);
// empty
PepXServiceImpl.buildEntryWithVirtualAnnotations(peptide, modeIsoleucine, Arrays.asList(pepXIsoformMatch), annots, isoforms);
// or
// null
// annotations
} catch (NextProtException e) {
if (e.getMessage().contains("is not specific for this isoform")) {
// success tests
throw e;
} else
fail();
}
}
use of org.nextprot.api.web.domain.PepXResponse.PepXIsoformMatch in project nextprot-api by calipho-sib.
the class PepXServiceImpl method buildEntryWithVirtualAnnotations.
static List<Annotation> buildEntryWithVirtualAnnotations(String peptide, boolean modeIsoleucine, List<PepXIsoformMatch> pepXisoforms, List<Annotation> varAnnotations, List<Isoform> isoforms) {
List<Annotation> finalAnnotations = new ArrayList<>();
for (PepXIsoformMatch isoNameAndOptionalPosition : pepXisoforms) {
String isoformAc = isoNameAndOptionalPosition.getIsoformAccession();
Annotation annotation = new Annotation();
annotation.setAnnotationCategory(AnnotationCategory.PEPX_VIRTUAL_ANNOTATION);
annotation.setCvTermName(peptide);
annotation.setDescription("This virtual annotation describes the peptide " + peptide + " found in " + isoformAc);
AnnotationIsoformSpecificity is = new AnnotationIsoformSpecificity();
is.setIsoformAccession(isoformAc);
if (isoNameAndOptionalPosition.getPosition() != null) {
// It means there is a variant!!!
int startPeptidePosition = isoNameAndOptionalPosition.getPosition();
int endPeptidePosition = startPeptidePosition + peptide.length();
List<Annotation> variantAnnotations = AnnotationUtils.filterAnnotationsBetweenPositions(startPeptidePosition, endPeptidePosition, varAnnotations, isoformAc);
Isoform iso = IsoformUtils.getIsoformByIsoName(isoforms, isoformAc);
if (iso == null) {
throw new NextProtException("The variant at " + startPeptidePosition + " is not specific for this isoform " + isoformAc);
}
List<Annotation> validAnnotations = filterValidVariantAnnotations(peptide, modeIsoleucine, variantAnnotations, isoformAc, iso.getSequence());
if ((validAnnotations == null) || validAnnotations.isEmpty()) {
LOGGER.warn("No valid variants found for isoform " + isoformAc + " at position " + startPeptidePosition + " for peptide " + peptide + " in mode IL:" + modeIsoleucine);
continue;
// We used to throw an exception, but now we just skip
// throw new NextProtException("No valid variants found for isoform " + isoformName + " at position" + startPeptidePosition + " for peptide " + peptide + " in mode IL:" + modeIsoleucine);
}
if (validAnnotations.size() > 1) {
LOGGER.warn("There is more than 1 valid variant (" + validAnnotations.size() + ") for isoform (returning the 1st) " + isoformAc + " between position " + startPeptidePosition + " and " + endPeptidePosition + " for peptide " + peptide + " in mode IL:" + modeIsoleucine);
// Takes only the first valid
int startPos = validAnnotations.get(0).getStartPositionForIsoform(isoformAc);
int endPos = validAnnotations.get(0).getEndPositionForIsoform(isoformAc);
is.setFirstPosition(startPos);
is.setLastPosition(endPos);
AnnotationVariant var = validAnnotations.get(0).getVariant();
annotation.setVariant(var);
} else {
// one variant on that position
int startPos = validAnnotations.get(0).getStartPositionForIsoform(isoformAc);
int endPos = validAnnotations.get(0).getEndPositionForIsoform(isoformAc);
is.setFirstPosition(startPos);
is.setLastPosition(endPos);
AnnotationVariant var = validAnnotations.get(0).getVariant();
annotation.setVariant(var);
}
} else {
// No variant
Isoform iso = IsoformUtils.getIsoformByIsoName(isoforms, isoformAc);
String sequence = (iso != null) ? iso.getSequence() : null;
boolean isPeptideContained = PeptideUtils.isPeptideContainedInTheSequence(peptide, sequence, modeIsoleucine);
if (!isPeptideContained) {
LOGGER.warn("PepX returned a peptide (" + peptide + ") for an isoform (" + isoformAc + ") that is not in the current isoform in neXtProt");
continue;
}
// We used to throw an exception, but this would break the program (the algorithm could be improved to detect the specific case where pepx return a peptide of length 6 and generate a real error on other cases)
// NPreconditions.checkTrue(isPeptideContained, "PepX returned a peptide (" + peptide + ") for an isoform (" + isoformName + ") that is not in the current isoform in neXtProt");
}
annotation.addTargetingIsoforms(Arrays.asList(is));
finalAnnotations.add(annotation);
}
return finalAnnotations;
}
Aggregations