Skip to content

Commit

Permalink
Write PANTHER2GO data to TSV file
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasblum committed Oct 9, 2023
1 parent a8f2249 commit 65d0364
Showing 1 changed file with 39 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.ac.ebi.interpro.scan.io.match.writer;

import org.springframework.core.io.Resource;
import uk.ac.ebi.interpro.scan.io.TSVWriter;
import uk.ac.ebi.interpro.scan.model.*;
import uk.ac.ebi.interpro.scan.util.Utilities;
Expand Down Expand Up @@ -75,14 +74,15 @@ public int write(Protein protein) throws IOException {
String status = "T";

Set<GoXref> goXrefs = new HashSet<>();
List<PathwayXref> pathwayXrefs = new ArrayList<>();

// To maintain compatibility, we output the same value for the score column as I4
// In some cases we have to take the value from the match
if (match instanceof SuperFamilyHmmer3Match) {
score = Double.toString(((SuperFamilyHmmer3Match) match).getEvalue());
} else if (match instanceof PantherMatch) {
score = Double.toString(((PantherMatch) match).getEvalue());
// goXrefs.addAll(((PantherMatch) match).getGoXRefs());
goXrefs.addAll(((PantherMatch) match).getGoXRefs());
} else if (match instanceof FingerPrintsMatch) {
score = Double.toString(((FingerPrintsMatch) match).getEvalue());
}
Expand Down Expand Up @@ -127,47 +127,48 @@ public int write(Protein protein) throws IOException {
if (interProEntry != null) {
mappingFields.add(interProEntry.getAccession());
mappingFields.add(interProEntry.getDescription());
goXrefs.addAll(interProEntry.getGoXRefs());
pathwayXrefs = new ArrayList<>(interProEntry.getPathwayXRefs());
} else {
mappingFields.add("-");
mappingFields.add("-");
}
} else {
mappingFields.add("-");
mappingFields.add("-");
}

if (mapToGO) {
goXrefs.addAll(interProEntry.getGoXRefs());
List<GoXref> goXRefsList = new ArrayList<>(goXrefs);
Collections.sort(goXRefsList, new GoXrefComparator());
if (goXRefsList.size() > 0) {
StringBuilder sb = new StringBuilder();
for (GoXref xref : goXRefsList) {
if (sb.length() > 0) {
sb.append(VALUE_SEPARATOR);
}
sb.append(xref.getIdentifier()); // Just writeComment the GO identifier to the output
}
mappingFields.add(sb.toString());
} else {
mappingFields.add("-");
}
if (mapToGO && !goXrefs.isEmpty()) {
List<GoXref> goXRefsList = new ArrayList<>(goXrefs);
goXRefsList.sort(new GoXrefComparator());
StringBuilder sb = new StringBuilder();
for (GoXref xref : goXRefsList) {
if (sb.length() > 0) {
sb.append(VALUE_SEPARATOR);
}
if (mapToPathway) {
List<PathwayXref> pathwayXRefs = new ArrayList<>(interProEntry.getPathwayXRefs());
Collections.sort(pathwayXRefs, new PathwayXrefComparator());
if (pathwayXRefs.size() > 0) {
StringBuilder sb = new StringBuilder();
for (PathwayXref xref : pathwayXRefs) {
if (sb.length() > 0) {
sb.append(VALUE_SEPARATOR);
}
sb.append(xref.getDatabaseName())
.append(": ")
.append(xref.getIdentifier());
}
mappingFields.add(sb.toString());
} else {
mappingFields.add("-");
}
sb.append(xref.getIdentifier()); // Just write the GO identifier
}
mappingFields.add(sb.toString());
} else {
mappingFields.add("-");
}

if (mapToPathway && !pathwayXrefs.isEmpty()) {
pathwayXrefs.sort(new PathwayXrefComparator());
StringBuilder sb = new StringBuilder();
for (PathwayXref xref : pathwayXrefs) {
if (sb.length() > 0) {
sb.append(VALUE_SEPARATOR);
}
} else {
mappingFields.add("-"); // for accession
mappingFields.add("-"); // for description
sb.append(xref.getDatabaseName())
.append(":")
.append(xref.getIdentifier());
}
mappingFields.add(sb.toString());
} else {
mappingFields.add("-");
}

this.tsvWriter.write(mappingFields);
}
}
Expand Down

0 comments on commit 65d0364

Please sign in to comment.