use of org.nextprot.api.core.domain.Family in project nextprot-api by calipho-sib.
the class NXVelocityUtilsTest method testGetFamilyHierarchyFromRoot.
@Test
public void testGetFamilyHierarchyFromRoot() throws Exception {
Family superfamily = new Family();
superfamily.setName("ba superfamily");
Family family = new Family();
family.setName("be family");
Family subfamily = new Family();
subfamily.setName("bi subfamily");
subfamily.setParent(family);
family.setParent(superfamily);
Assert.assertEquals(Arrays.asList(superfamily, family, subfamily), NXVelocityUtils.getFamilyHierarchyFromRoot(subfamily));
}
use of org.nextprot.api.core.domain.Family in project nextprot-api by calipho-sib.
the class CVFieldBuilder method init.
@Override
protected void init(Entry entry) {
Set<String> cv_acs = new HashSet<String>();
Set<String> cv_ancestors_acs = new HashSet<String>();
Set<String> cv_synonyms = new HashSet<String>();
// top level ancestors (Annotation, feature, and ROI)
Set<String> top_acs = new HashSet<>(Arrays.asList("CVAN_0001", "CVAN_0002", "CVAN_0011"));
// CV accessions
List<Annotation> annots = entry.getAnnotations();
boolean allnegative;
for (Annotation currannot : annots) {
String category = currannot.getCategory();
if (!category.equals("tissue specificity")) {
// tissue-specific CVs are indexed under 'expression'
String cvac = currannot.getCvTermAccessionCode();
if (cvac == null)
continue;
if (cvac.isEmpty())
logger.warn("CVterm accession empty in " + category + " for " + entry.getUniqueName());
else {
if (category.startsWith("go ")) {
allnegative = true;
List<AnnotationEvidence> evlist = currannot.getEvidences();
// We don't index negative annotations
for (AnnotationEvidence ev : evlist) allnegative = allnegative & ev.isNegativeEvidence();
if (allnegative == true)
continue;
}
if (!this.isGold() || currannot.getQualityQualifier().equals("GOLD")) {
addField(Fields.CV_ACS, cvac);
// No duplicates: this is a Set, will be used for synonyms and ancestors
cv_acs.add(cvac);
addField(Fields.CV_NAMES, currannot.getCvTermName());
}
}
}
}
// Families (why not part of Annotations ?)
for (Family family : entry.getOverview().getFamilies()) {
addField(Fields.CV_ACS, family.getAccession());
addField(Fields.CV_NAMES, family.getName() + " family");
cv_acs.add(family.getAccession());
}
// Final CV acs, ancestors and synonyms
for (String cvac : cv_acs) {
CvTerm term = this.terminologyservice.findCvTermByAccession(cvac);
if (null == term) {
logger.error(entry.getUniqueName() + " - term with accession |" + cvac + "| not found with findCvTermByAccession()");
continue;
}
List<String> ancestors = terminologyservice.getAllAncestorsAccession(term.getAccession());
if (ancestors != null) {
for (String ancestor : ancestors) cv_ancestors_acs.add(ancestor);
}
List<String> synonyms = term.getSynonyms();
if (synonyms != null) {
// No duplicate: this is a Set
for (String synonym : synonyms) cv_synonyms.add(synonym.trim());
}
}
// Remove uninformative top level ancestors (Annotation, feature, and ROI)
cv_ancestors_acs.removeAll(top_acs);
// Index generated sets
for (String ancestorac : cv_ancestors_acs) {
addField(Fields.CV_ANCESTORS_ACS, ancestorac);
addField(Fields.CV_ANCESTORS, this.terminologyservice.findCvTermByAccession(ancestorac).getName());
}
for (String synonym : cv_synonyms) {
addField(Fields.CV_SYNONYMS, synonym);
}
List<CvTerm> enzymes = entry.getEnzymes();
String ec_names = "";
for (CvTerm currenzyme : enzymes) {
cv_acs.add(currenzyme.getAccession());
addField(Fields.CV_NAMES, currenzyme.getName());
if (ec_names != "")
ec_names += ", ";
ec_names += "EC " + currenzyme.getAccession();
List<String> synonyms = currenzyme.getSynonyms();
if (synonyms != null)
for (String synonym : synonyms) {
addField(Fields.CV_SYNONYMS, synonym.trim());
}
}
addField(Fields.EC_NAME, ec_names);
}
use of org.nextprot.api.core.domain.Family in project nextprot-api by calipho-sib.
the class FamilyServiceImpl method findFamilies.
@Override
@Cacheable("families")
public List<Family> findFamilies(String uniqueName) {
List<Family> families = familyDao.findFamilies(uniqueName);
for (Family child : families) {
while (true) {
Long childId = child.getFamilyId();
// TODO can this be done with one query???
Family parent = familyDao.findParentOfFamilyId(childId);
if (parent == null)
break;
child.setParent(parent);
// TODO setting a reference inside a for loop????
child = parent;
}
}
Collections.sort(families, FAMILY_COMPARATOR);
// returns a immutable list when the result is cacheable (this prevents modifying the cache, since the cache returns a reference) copy on read and copy on write is too much time consuming
return new ImmutableList.Builder<Family>().addAll(families).build();
}
use of org.nextprot.api.core.domain.Family in project nextprot-api by calipho-sib.
the class FamilyDaoIntegrationTest method shouldReturn_1_Parent_Family.
@Test
public void shouldReturn_1_Parent_Family() {
List<Family> families = familyDao.findFamilies("NX_Q3SY69");
Long familyId = families.get(0).getFamilyId();
Family fam = familyDao.findParentOfFamilyId(64506L);
assertTrue(fam.getAccession() != null);
// always null (region comes from annotation)
assertTrue(fam.getDescription() == null);
assertTrue(fam.getName() != null);
// always null (region comes from annotation)
assertTrue(fam.getRegion() == null);
assertTrue(fam.getFamilyId() > 0);
// the parent (if any) is set later in the family service
assertTrue(fam.getParent() == null);
}
use of org.nextprot.api.core.domain.Family in project nextprot-api by calipho-sib.
the class FamilyDaoIntegrationTest method shouldReturn_No_Parent_Family.
@Test
public void shouldReturn_No_Parent_Family() {
// random id
Long familyId = 872345298725L;
Family fam = familyDao.findParentOfFamilyId(familyId);
assertTrue(fam == null);
}
Aggregations