use of org.vcell.sybil.util.http.uniprot.box.imp.UniProtBoxImp in project vcell by virtualcell.
the class UniProtConstants method getNameFromID.
public static String getNameFromID(String urnStr) {
// extract id of entry from urnStr : urn string is of the form "urn:miriam:uniprot:XXXX" ; we need to extract 'XXXX'
if (!urnStr.toLowerCase().contains("uniprot")) {
throw new RuntimeException("Resource '" + urnStr + "' is not a UniProt entry");
}
String entryId = urnStr.substring(urnStr.lastIndexOf(":") + 1);
System.out.println("EntryId from urn : " + entryId);
UniProtBox box = new UniProtBoxImp();
getInfoForID(box, entryId);
String recommendedName = null;
for (UniProtBox.Entry entry : box.entries()) {
// System.out.println("UniProt ID : : " + entry.id() + (entry.isObsolete() ? " is obsolete" : ""));
if (entry.isObsolete()) {
UniProtBox box2 = new UniProtBoxImp();
for (UniProtBox.Entry entryReplacing : entry.replacingEntries()) {
// System.out.println(" replaced by " + entryReplacing.id());
getInfoForID(box2, entryReplacing.id());
for (UniProtBox.Entry entry1 : box2.entries()) {
if (!entry1.isObsolete() && recommendedName == null) {
recommendedName = entry1.recommendedName();
}
}
if (recommendedName != null) {
break;
}
}
if (recommendedName != null) {
break;
}
} else {
recommendedName = entry.recommendedName();
}
}
return recommendedName;
}
use of org.vcell.sybil.util.http.uniprot.box.imp.UniProtBoxImp in project vcell by virtualcell.
the class UniProtExtractor method extractBox.
public UniProtBox extractBox() {
UniProtBoxImp box = new UniProtBoxImp();
Iterator<Statement> stmtIter1 = model.match(null, UniProtConstants.replaces, null);
while (stmtIter1.hasNext()) {
Statement statement = stmtIter1.next();
Resource subject = statement.getSubject();
Value object = statement.getObject();
if (subject instanceof URI && object instanceof URI) {
String idSubject = id((URI) subject);
String idObject = id((URI) object);
if (StringUtil.notEmpty(idSubject) && StringUtil.notEmpty(idObject)) {
UniProtBox.Entry entrySubject = box.entry(idSubject);
UniProtBox.Entry entryObject = box.entry(idObject);
box.setReplaces(entrySubject, entryObject);
}
}
}
Iterator<Statement> stmtIter2 = model.match(null, UniProtConstants.replacedBy, null);
while (stmtIter2.hasNext()) {
Statement statement = stmtIter2.next();
Resource subject = statement.getSubject();
Value object = statement.getObject();
if (subject instanceof URI && object instanceof URI) {
String idSubject = id((URI) subject);
String idObject = id((URI) object);
if (StringUtil.notEmpty(idSubject) && StringUtil.notEmpty(idObject)) {
UniProtBox.Entry entrySubject = box.entry(idSubject);
UniProtBox.Entry entryObject = box.entry(idObject);
box.setReplaces(entryObject, entrySubject);
}
}
}
Iterator<Statement> stmtIter3 = model.match(null, UniProtConstants.recommendedName, null);
if (stmtIter3.hasNext()) {
while (stmtIter3.hasNext()) {
Statement statement = stmtIter3.next();
Resource entryNode = statement.getSubject();
Value nameNode = statement.getObject();
if (nameNode instanceof Resource) {
Resource nameResource = (Resource) nameNode;
Iterator<Statement> stmtIter4 = model.match(nameResource, UniProtConstants.fullName, null);
// System.out.println("hello world");
while (stmtIter4.hasNext()) {
Statement statement2 = stmtIter4.next();
Value objectNode = statement2.getObject();
// System.out.println("hello moon");
if (entryNode instanceof URI && objectNode instanceof Literal) {
String name = ((Literal) objectNode).stringValue();
UniProtBox.Entry entry = box.entry(UniProtConstants.idFromResource((URI) entryNode));
System.out.println("UniProtExtractor: name: " + name + "\tid: " + entry.id());
entry.setRecommendedName(name);
}
}
}
}
} else {
// sometimes, recommended name is not present for an uniprot id : check the full name
stmtIter3 = model.match(null, UniProtConstants.fullName, null);
while (stmtIter3.hasNext()) {
Statement statement2 = stmtIter3.next();
Resource entryNode = statement2.getSubject();
Value objectNode = statement2.getObject();
if (entryNode instanceof URI && objectNode instanceof Literal) {
String name = ((Literal) objectNode).stringValue();
UniProtBox.Entry entry = box.entry(UniProtConstants.idFromResource((URI) entryNode));
entry.setRecommendedName(name);
System.out.println("UniProtExtractor: name: " + name + "\tid: " + entry.id());
}
}
}
return box;
}
Aggregations