Skip to content

Commit

Permalink
Refs #294
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorRodchenkov committed Apr 22, 2018
1 parent 44efed5 commit 7de37f7
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions cpath-cli/src/main/java/cpath/analysis/LandingAndLinkout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cpath.analysis;

import cpath.config.CPathSettings;
import cpath.service.Analysis;
import cpath.service.CPathService;
import cpath.service.CPathUtils;
import org.biopax.paxtools.model.Model;
import org.biopax.paxtools.model.level3.RelationshipXref;
import org.biopax.paxtools.model.level3.UnificationXref;
import org.biopax.paxtools.model.level3.Xref;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class LandingAndLinkout implements Analysis<Model> {

private static final Logger LOG = LoggerFactory.getLogger(LandingAndLinkout.class);
// 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;
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();

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

0 comments on commit 7de37f7

Please sign in to comment.