package uk.ac.ebi.quickgo.annotation.converter;

import uk.ac.ebi.quickgo.annotation.model.Annotation;

import java.util.StringJoiner;
import java.util.function.Function;

/**
 * Convert an Annotation to the GPAD format.
 *
 * See the format here: http://geneontology.org/page/gene-product-association-data-gpad-format}
 *
 * An except from a GPAD file is below:
 * UniProtKB	A0A000	enables	GO:0003824	GO_REF:0000002	ECO:0000256	InterPro:IPR015421|InterPro:IPR015422		20170107	InterPro		go_evidence=IEA
 * UniProtKB	A0A000	enables	GO:0003870	GO_REF:0000002	ECO:0000256	InterPro:IPR010961		20170107	InterPro		go_evidence=IEA
 * UniProtKB	A0A000	involved_in	GO:0009058	GO_REF:0000002	ECO:0000256	InterPro:IPR004839		20170107	InterPro		go_evidence=IEA
 * UniProtKB	A0A000	enables	GO:0030170	GO_REF:0000002	ECO:0000256	InterPro:IPR004839|InterPro:IPR010961		20170107	InterPro		go_evidence=IEA
 * UniProtKB	A0A000	involved_in	GO:0033014	GO_REF:0000002	ECO:0000256	InterPro:IPR010961		20170107	InterPro		go_evidence=IEA
 *
 * @author Tony Wardell
 * Date: 17/01/2017
 * Time: 11:24
 * Created with IntelliJ IDEA.
 */
public class AnnotationToGPAD extends AnnotationTo implements Function<Annotation, String> {

    static final String OUTPUT_DELIMITER = "\t";

    @Override
    public String apply(Annotation annotation) {
        StringJoiner tsvJoiner = new StringJoiner(OUTPUT_DELIMITER);
        String[] idElements = idToComponents(annotation);
        return tsvJoiner.add(idElements[0])
                        .add(idElements[1])
                        .add(annotation.qualifier)
                        .add(idOrSlimmedId(annotation))
                        .add(annotation.reference)
                        .add(annotation.evidenceCode)
                        .add(withFromAsString(annotation.withFrom))
                        .add(annotation.interactingTaxonId)
                        .add(toYMD(annotation.date))
                        .add(annotation.assignedBy)
                        .add(extensionsAsString(annotation.extensions))
                        .add("goEvidence=" + annotation.goEvidence).toString();

    }
}

@@ -118,56 +118,186 @@
 til.
-StringJoiner;%0Aimport java.util.function.Function
+Collections;%0Aimport java.util.List;%0Aimport java.util.Objects;%0Aimport java.util.StringJoiner;%0Aimport java.util.function.Function;%0A%0Aimport static java.util.stream.Collectors.toList
 ;%0A%0A/
@@ -1321,15 +1321,21 @@
 on, 
+List%3C
 String%3E
+%3E
  %7B%0A%0A
@@ -1409,22 +1409,28 @@
  public 
+List%3C
 String
+%3E
  apply(A
@@ -1453,16 +1453,499 @@
 tion) %7B%0A
+        if (Objects.isNull(annotation.slimmedIds) %7C%7C annotation.slimmedIds.isEmpty()) %7B%0A            return Collections.singletonList(toOutputRecord(annotation, annotation.id));%0A        %7D else %7B%0A            return annotation.slimmedIds.stream()%0A                                        .map(goId -%3E this.toOutputRecord(annotation, goId))%0A                                        .collect(toList());%0A        %7D%0A    %7D%0A%0A    private String toOutputRecord(Annotation annotation, String id) %7B%0A
         
@@ -2237,31 +2237,8 @@
 d(id
-OrSlimmedId(annotation)
 )%0A  
@@ -2725,17 +2725,16 @@
 ring();%0A
-%0A
     %7D%0A%7D%0A

Deal with slimmed requests - which means deriving an annotation record for each slimmed to id.