Skip to content

Commit

Permalink
Add source of GO term to TSV output
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasblum committed Oct 9, 2023
1 parent 65d0364 commit 42c4d47
Showing 1 changed file with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public int write(Protein protein) throws IOException {
String score = "-";
String status = "T";

Set<GoXref> goXrefs = new HashSet<>();
Map<GoXref,GoXrefSources> goXrefs = new HashMap<>();
List<PathwayXref> pathwayXrefs = new ArrayList<>();

// To maintain compatibility, we output the same value for the score column as I4
Expand All @@ -82,7 +82,10 @@ public int write(Protein protein) throws IOException {
score = Double.toString(((SuperFamilyHmmer3Match) match).getEvalue());
} else if (match instanceof PantherMatch) {
score = Double.toString(((PantherMatch) match).getEvalue());
goXrefs.addAll(((PantherMatch) match).getGoXRefs());

for (GoXref xref : ((PantherMatch) match).getGoXRefs()) {
goXrefs.put(xref, new GoXrefSources(false, true));
}
} else if (match instanceof FingerPrintsMatch) {
score = Double.toString(((FingerPrintsMatch) match).getEvalue());
}
Expand Down Expand Up @@ -127,7 +130,17 @@ public int write(Protein protein) throws IOException {
if (interProEntry != null) {
mappingFields.add(interProEntry.getAccession());
mappingFields.add(interProEntry.getDescription());
goXrefs.addAll(interProEntry.getGoXRefs());

for (GoXref xref : interProEntry.getGoXRefs()) {
GoXrefSources sourcedXref = goXrefs.get(xref);
if (sourcedXref != null) {
sourcedXref.setInInterPro(true);
} else {
sourcedXref = new GoXrefSources(true, false);
goXrefs.put(xref, sourcedXref);
}
}

pathwayXrefs = new ArrayList<>(interProEntry.getPathwayXRefs());
} else {
mappingFields.add("-");
Expand All @@ -139,14 +152,16 @@ public int write(Protein protein) throws IOException {
}

if (mapToGO && !goXrefs.isEmpty()) {
List<GoXref> goXRefsList = new ArrayList<>(goXrefs);
List<GoXref> goXRefsList = new ArrayList<>(goXrefs.keySet());
goXRefsList.sort(new GoXrefComparator());
StringBuilder sb = new StringBuilder();
for (GoXref xref : goXRefsList) {
if (sb.length() > 0) {
sb.append(VALUE_SEPARATOR);
}
sb.append(xref.getIdentifier()); // Just write the GO identifier
sb.append(xref.getIdentifier());
GoXrefSources sourcedXref = goXrefs.get(xref);
sb.append(sourcedXref.toString());
}
mappingFields.add(sb.toString());
} else {
Expand Down Expand Up @@ -182,4 +197,37 @@ public int write(Protein protein) throws IOException {
}
return locationCount;
}

private static class GoXrefSources {
private boolean inInterPro;
private boolean inPanther;

public GoXrefSources(boolean inInterPro, boolean inPanther) {
this.inInterPro = inInterPro;
this.inPanther = inPanther;
}

public void setInInterPro(boolean inInterPro) {
this.inInterPro = inInterPro;
}

public void setInPanther(boolean inPanther) {
this.inPanther = inPanther;
}

@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();

if (inInterPro && inPanther) {
stringBuilder.append("(InterPro,PANTHER)");
} else if (inInterPro) {
stringBuilder.append("(InterPro)");
} else if (inPanther) {
stringBuilder.append("(PANTHER)");
}

return stringBuilder.toString();
}
}
}

0 comments on commit 42c4d47

Please sign in to comment.