Skip to content

Commit

Permalink
A fix - refs #294.
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorRodchenkov committed Apr 23, 2018
1 parent 7de37f7 commit 8b80461
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions cpath-cli/src/main/java/cpath/analysis/LandingAndLinkout.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
Expand All @@ -24,37 +25,42 @@ public class LandingAndLinkout implements Analysis<Model> {
// public static final String JAVA_OPTION_IDTYPE = "cpath.analysis.linkout.type";
private static final CPathSettings cpath = CPathSettings.getInstance();

@Autowired
CPathService service;

@Override
public void execute(Model model) {
//export the list of unique UniProt primary accession numbers
LOG.info("creating the list of primary uniprot IDs...");
Set<String> acs = new TreeSet<>();
//exclude publication xrefs
Set<Xref> xrefs = new HashSet<>(model.getObjects(UnificationXref.class));
xrefs.addAll(model.getObjects(RelationshipXref.class));
long left = xrefs.size();
for(Xref x : xrefs) {
String id = x.getId();
if (CPathUtils.startsWithAnyIgnoreCase(x.getDb(),"uniprot")
&& id != null && !acs.contains(id))
acs.addAll(service.map(id, "UNIPROT"));
if(--left % 10000 == 0)
LOG.info(left + " xrefs to map...");
}

PrintWriter writer;
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "classpath:META-INF/spring/applicationContext-jpa.xml" });
try {
writer = new PrintWriter("uniprot.txt");
} catch (FileNotFoundException e) {
throw new RuntimeException("", e);
final CPathService service = context.getBean(CPathService.class);
//export the list of unique UniProt primary accession numbers
LOG.info("creating the list of primary uniprot IDs...");
Set<String> acs = new TreeSet<>();
//exclude publication xrefs
Set<Xref> xrefs = new HashSet<>(model.getObjects(UnificationXref.class));
xrefs.addAll(model.getObjects(RelationshipXref.class));
long left = xrefs.size();
for (Xref x : xrefs) {
String id = x.getId();
if (CPathUtils.startsWithAnyIgnoreCase(x.getDb(), "uniprot")
&& id != null && !acs.contains(id))
acs.addAll(service.map(id, "UNIPROT"));
if (--left % 10000 == 0)
LOG.info(left + " xrefs to map...");
}

PrintWriter writer;
try {
writer = new PrintWriter("uniprot.txt");
} catch (FileNotFoundException e) {
throw new RuntimeException("", e);
}
writer.println(String.format("#PathwayCommons v%s - primary UniProt accession numbers:", cpath.getVersion()));
for (String ac : acs)
writer.println(ac);
writer.close();

} finally {
context.close();
}
writer.println(String.format("#PathwayCommons v%s - primary UniProt accession numbers:", cpath.getVersion()));
for(String ac : acs)
writer.println(ac);
writer.close();

LOG.info("generated uniprot.txt");
}
Expand Down

0 comments on commit 8b80461

Please sign in to comment.