Search in sources :

Example 16 with Annotation

use of org.dishevelled.bio.annotation.Annotation in project dishevelled-bio by heuermh.

the class ContainmentTest method setUp.

@Before
public void setUp() {
    container = Reference.valueOf("source+");
    contained = Reference.valueOf("target+");
    position = 42;
    overlap = "10M";
    annotations = ImmutableMap.<String, Annotation>builder().put("aa", new Annotation("aa", "i", "42")).build();
}
Also used : Annotation(org.dishevelled.bio.annotation.Annotation) Before(org.junit.Before)

Example 17 with Annotation

use of org.dishevelled.bio.annotation.Annotation in project dishevelled-bio by heuermh.

the class PafReaderTest method testRoundTrip.

@Test
public void testRoundTrip() throws Exception {
    Map<String, Annotation> annotations = new HashMap<String, Annotation>();
    annotations.put("NM", Annotation.valueOf("NM:i:0"));
    annotations.put("MD", Annotation.valueOf("MD:Z:101"));
    annotations.put("AS", Annotation.valueOf("AS:i:101"));
    annotations.put("XS", Annotation.valueOf("XS:i:55"));
    annotations.put("RG", Annotation.valueOf("RG:Z:NA12878-1"));
    annotations.put("MQ", Annotation.valueOf("MQ:i:60"));
    annotations.put("ms", Annotation.valueOf("ms:i:3614"));
    annotations.put("mc", Annotation.valueOf("mc:i:60612"));
    annotations.put("MC", Annotation.valueOf("MC:Z:101M"));
    annotations.put("ZB", Annotation.valueOf("ZB:B:i1,2"));
    annotations.put("ZT", Annotation.valueOf("ZT:B:f3.4,4.5"));
    PafRecord expected = new PafRecord("query", 100L, 10L, 20L, '-', "target", 200L, 20L, 30L, 42L, 10L, 32, annotations);
    File tmp = File.createTempFile("pafReaderTest", ".paf");
    tmp.deleteOnExit();
    try (PrintWriter writer = new PrintWriter(new FileWriter(tmp))) {
        PafWriter.write(expected, writer);
    }
    PafRecord observed = read(tmp).iterator().next();
    assertEquals(expected.getQueryName(), observed.getQueryName());
}
Also used : HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) File(java.io.File) Annotation(org.dishevelled.bio.annotation.Annotation) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 18 with Annotation

use of org.dishevelled.bio.annotation.Annotation in project dishevelled-bio by heuermh.

the class PafWriterTest method setUp.

@Before
public void setUp() {
    Map<String, Annotation> annotations = new HashMap<String, Annotation>();
    annotations.put("NM", Annotation.valueOf("NM:i:0"));
    annotations.put("MD", Annotation.valueOf("MD:Z:101"));
    annotations.put("AS", Annotation.valueOf("AS:i:101"));
    annotations.put("XS", Annotation.valueOf("XS:i:55"));
    annotations.put("RG", Annotation.valueOf("RG:Z:NA12878-1"));
    annotations.put("MQ", Annotation.valueOf("MQ:i:60"));
    annotations.put("ms", Annotation.valueOf("ms:i:3614"));
    annotations.put("mc", Annotation.valueOf("mc:i:60612"));
    annotations.put("MC", Annotation.valueOf("MC:Z:101M"));
    annotations.put("ZB", Annotation.valueOf("ZB:B:i,1,2"));
    annotations.put("ZT", Annotation.valueOf("ZT:B:f,3.4,4.5"));
    record = new PafRecord("query", 100L, 10L, 20L, '-', "target", 200L, 20L, 30L, 42L, 10L, 32, annotations);
    records = ImmutableList.of(record);
    outputStream = new ByteArrayOutputStream();
    writer = new PrintWriter(outputStream);
}
Also used : HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Annotation(org.dishevelled.bio.annotation.Annotation) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 19 with Annotation

use of org.dishevelled.bio.annotation.Annotation in project dishevelled-bio by heuermh.

the class Link method valueOf.

/**
 * Parse a link GFA 1.0 record from the specified value.
 *
 * @param value value, must not be null
 * @return a link GFA 1.0 record parsed from the specified value
 */
public static Link valueOf(final String value) {
    checkNotNull(value);
    checkArgument(value.startsWith("L"), "link value must start with L");
    List<String> tokens = Splitter.on("\t").splitToList(value);
    if (tokens.size() < 6) {
        throw new IllegalArgumentException("link value must have at least six tokens, was " + tokens.size());
    }
    Reference source = Reference.splitValueOf(tokens.get(1), tokens.get(2));
    Reference target = Reference.splitValueOf(tokens.get(3), tokens.get(4));
    String overlap = "*".equals(tokens.get(5)) ? null : tokens.get(5);
    ImmutableMap.Builder<String, Annotation> annotations = ImmutableMap.builder();
    for (int i = 6; i < tokens.size(); i++) {
        String token = tokens.get(i);
        if (!token.isEmpty()) {
            Annotation annotation = Annotation.valueOf(token);
            annotations.put(annotation.getName(), annotation);
        }
    }
    return new Link(source, target, overlap, annotations.build());
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Annotation(org.dishevelled.bio.annotation.Annotation)

Example 20 with Annotation

use of org.dishevelled.bio.annotation.Annotation in project dishevelled-bio by heuermh.

the class Segment method valueOf.

/**
 * Parse a segment GFA 1.0 record from the specified value.
 *
 * @param value value, must not be null
 * @return a segment GFA 1.0 record parsed from the specified value
 */
public static Segment valueOf(final String value) {
    checkNotNull(value);
    checkArgument(value.startsWith("S"), "segment value must start with S");
    List<String> tokens = Splitter.on("\t").splitToList(value);
    if (tokens.size() < 3) {
        throw new IllegalArgumentException("segment value must have at least three tokens, was " + tokens.size());
    }
    String id = tokens.get(1);
    String sequence = "*".equals(tokens.get(2)) ? null : tokens.get(2);
    ImmutableMap.Builder<String, Annotation> annotations = ImmutableMap.builder();
    for (int i = 3; i < tokens.size(); i++) {
        String token = tokens.get(i);
        if (!token.isEmpty()) {
            Annotation annotation = Annotation.valueOf(token);
            annotations.put(annotation.getName(), annotation);
        }
    }
    return new Segment(id, sequence, annotations.build());
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Annotation(org.dishevelled.bio.annotation.Annotation)

Aggregations

Annotation (org.dishevelled.bio.annotation.Annotation)34 ImmutableMap (com.google.common.collect.ImmutableMap)17 Before (org.junit.Before)13 PrintWriter (java.io.PrintWriter)6 HashMap (java.util.HashMap)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 Test (org.junit.Test)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 GafRecord (org.dishevelled.bio.alignment.gaf.GafRecord)1 Containment (org.dishevelled.bio.assembly.gfa1.Containment)1 Gfa1Adapter (org.dishevelled.bio.assembly.gfa1.Gfa1Adapter)1 Header (org.dishevelled.bio.assembly.gfa1.Header)1 Link (org.dishevelled.bio.assembly.gfa1.Link)1 Path (org.dishevelled.bio.assembly.gfa1.Path)1 Reference (org.dishevelled.bio.assembly.gfa1.Reference)1 Segment (org.dishevelled.bio.assembly.gfa1.Segment)1