Skip to content

Commit

Permalink
improve test in UniParcProteomeFastaParser.java
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardoGonzales committed Nov 28, 2024
1 parent 97d68a9 commit a13cefc
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 227 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.uniprot.core.parser.fasta;
package org.uniprot.core.parser.fasta.uniparc;

import org.uniprot.core.Sequence;
import org.uniprot.core.uniparc.UniParcCrossReference;
import org.uniprot.core.uniparc.UniParcEntry;
import org.uniprot.core.uniparc.UniParcEntryLight;

import static org.uniprot.core.uniparc.impl.UniParcEntryLightBuilder.HAS_ACTIVE_CROSS_REF;
Expand All @@ -11,19 +9,8 @@
* @author jluo
* @date: 24 Jun 2019
*/
public class UniParcFastaParser {
private UniParcFastaParser(){}

public static String toFasta(UniParcEntry entry) {
String status = "active";
boolean isActive = entry.getUniParcCrossReferences()
.stream()
.anyMatch(UniParcCrossReference::isActive);
if (!isActive) {
status = "inactive";
}
return getFastaString(entry.getUniParcId().getValue(), status, entry.getSequence());
}
public class UniParcEntryLightFastaParser {
private UniParcEntryLightFastaParser(){}

public static String toFasta(UniParcEntryLight entry) {
String status = "active";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static StringBuilder getFastaHeader(List<UniParcCrossReference> xrefs, b
if(!sourceIds.isEmpty()){
sb.append(" SS=").append(String.join("|", sourceIds));
}
sb.append(" UP=").append(proteomeId);
sb.append(" PC=").append(proteomeId);
if(!component.isEmpty()){
sb.append(":").append(String.join("|", component));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.uniprot.core.parser.fasta.uniparc;

import static org.junit.jupiter.api.Assertions.*;
import static org.uniprot.core.parser.fasta.uniparc.UniParcFastaParserTestUtils.*;
import static org.uniprot.core.uniparc.impl.UniParcEntryLightBuilder.HAS_ACTIVE_CROSS_REF;

import org.junit.jupiter.api.Test;
import org.uniprot.core.uniparc.*;
import org.uniprot.core.uniparc.impl.UniParcEntryLightBuilder;

/**
* @author jluo
* @date: 24 Jun 2019
*/
class UniParcEntryLightFastaParserTest {

public static final String EXPECTED_FASTA_RESULT = """
>UPI0000083A08 status=active
MSMAMARALATLGRLRYRVSGQLPLLDETAIEVMAGGQFLDGRKAREELGFFSTTALDDT
LLRAIDWFRDNGYFNA""";
public static final String EXPECTED_FASTA_RESULT_INACTIVE = """
>UPI0000083A08 status=inactive
MSMAMARALATLGRLRYRVSGQLPLLDETAIEVMAGGQFLDGRKAREELGFFSTTALDDT
LLRAIDWFRDNGYFNA""";


@Test
void testUniParcEntryLightToFasta() {
UniParcEntryLight entry = createEntryLight();
String fasta = UniParcEntryLightFastaParser.toFasta(entry);
assertEquals(EXPECTED_FASTA_RESULT, fasta);
}

@Test
void testUniParcEntryLightToFastaInactive() {
UniParcEntryLight entry = createEntryLight();
entry = UniParcEntryLightBuilder.from(entry).extraAttributesAdd(HAS_ACTIVE_CROSS_REF, false).build();
String fasta = UniParcEntryLightFastaParser.toFasta(entry);
assertEquals(EXPECTED_FASTA_RESULT_INACTIVE, fasta);
}

private UniParcEntryLight createEntryLight() {
return new UniParcEntryLightBuilder()
.uniParcId("UPI0000083A08")
.sequence(getSequence())
.build();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.uniprot.core.parser.fasta.uniparc;

import org.uniprot.core.Property;
import org.uniprot.core.Sequence;
import org.uniprot.core.impl.SequenceBuilder;
import org.uniprot.core.uniparc.*;
Expand Down Expand Up @@ -33,7 +34,7 @@ static List<UniParcCrossReference> getUniProtXrefs(boolean active) {
List<UniParcCrossReference> result = new ArrayList<>();
Organism human = getOrganism(9606, "Homo sapiens");

result.add(getXref(UniParcDatabase.SWISSPROT, "P12345", active, human, null, null, "Protein Name One", "Gene Name One"));
result.add(getXref(UniParcDatabase.SWISSPROT, "P12345", active, human, null, null, "Protein Name One", "Gene Name One", new Property(UniParcCrossReference.PROPERTY_SOURCES, "ABC01415:UP000005640:Chromosome 1")));

return result;
}
Expand All @@ -47,10 +48,14 @@ static UniParcCrossReference getXref(UniParcDatabase database, String id, boolea
}

static UniParcCrossReference getXref(UniParcDatabase database, String id, boolean active, Organism organism, String proteomeId, String component) {
return getXref(database,id, active, organism, proteomeId, component, null, null);
return getXref(database,id, active, organism, proteomeId, component, null, null,null);
}

static UniParcCrossReference getXref(UniParcDatabase database, String id, boolean active, Organism organism, String proteomeId, String component, String proteinName, String geneName) {
static UniParcCrossReference getXref(UniParcDatabase database, String id, boolean active, Organism organism, String geneName, String proteinName, Property property) {
return getXref(database,id, active, organism, null, null, proteinName, geneName, property);
}

static UniParcCrossReference getXref(UniParcDatabase database, String id, boolean active, Organism organism, String proteomeId, String component, String proteinName, String geneName, Property property) {
return new UniParcCrossReferenceBuilder()
.database(database)
.id(id)
Expand All @@ -60,6 +65,7 @@ static UniParcCrossReference getXref(UniParcDatabase database, String id, boolea
.geneName(geneName)
.proteomeId(proteomeId)
.component(component)
.propertiesAdd(property)
.build();
}
}
Loading

0 comments on commit a13cefc

Please sign in to comment.