Search in sources :

Example 11 with Annotation

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

the class PathTest method setUp.

@Before
public void setUp() {
    id = "id";
    references = ImmutableList.of(Reference.valueOf("source+"), Reference.valueOf("target+"));
    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 12 with Annotation

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

the class SamReaderTest method testRoundTrip.

@Test
public void testRoundTrip() throws Exception {
    Map<String, Annotation> annotations = ImmutableMap.<String, Annotation>builder().put("NM", Annotation.valueOf("NM:i:0")).put("MD", Annotation.valueOf("MD:Z:101")).put("AS", Annotation.valueOf("AS:i:101")).put("XS", Annotation.valueOf("XS:i:55")).put("RG", Annotation.valueOf("RG:Z:NA12878-1")).put("MQ", Annotation.valueOf("MQ:i:60")).put("ms", Annotation.valueOf("ms:i:3614")).put("mc", Annotation.valueOf("mc:i:60612")).put("MC", Annotation.valueOf("MC:Z:101M")).put("ZB", Annotation.valueOf("ZB:B:i,1,2")).put("ZT", Annotation.valueOf("ZT:B:f,3.4,4.5")).build();
    SamRecord expected = new SamRecord("ERR194147.765130386", 99, "chr20", 60250, 60, "101M", "=", 60512, 363, "ACTCCATCCCATTCCATTCCACTCCCTTCATTTCCATTCCAGTCCATTCCATTCCATTCCATTCCATTCCACTCCACTCCATTCCATTCCACTGCACTCCA", "CCCFFFFFHHHHHJJJJJJJJJJJJJJJJJJJJJJJJJIJJJJJJIIJJJJJJJJJJJJJHIIJIJGIJJJJJJJJJJJJJIJJJJJJJJJJJGGHHHFF@", annotations);
    File tmp = File.createTempFile("samReaderTest", ".sam");
    tmp.deleteOnExit();
    try (PrintWriter writer = new PrintWriter(new FileWriter(tmp))) {
        SamWriter.writeRecord(expected, writer);
    }
    SamRecord observed = records(tmp).iterator().next();
    assertEquals(expected.getQname(), observed.getQname());
    assertEquals(expected.getFlag(), observed.getFlag());
    assertEquals(expected.getRname(), observed.getRname());
    assertEquals(expected.getPos(), observed.getPos());
    assertEquals(expected.getMapq(), observed.getMapq());
    assertEquals(expected.getCigar(), observed.getCigar());
    assertEquals(expected.getRnext(), observed.getRnext());
    assertEquals(expected.getPnext(), observed.getPnext());
    assertEquals(expected.getTlen(), observed.getTlen());
    assertEquals(expected.getSeq(), observed.getSeq());
    assertEquals(expected.getQual(), observed.getQual());
    assertEquals(expected.getAnnotations(), observed.getAnnotations());
    assertEquals("B", observed.getAnnotations().get("ZB").getType());
    assertEquals("i", observed.getAnnotations().get("ZB").getArrayType());
    assertEquals(Integer.valueOf(1), observed.getAnnotationIntegers("ZB").get(0));
    assertEquals(Integer.valueOf(2), observed.getAnnotationIntegers("ZB").get(1));
    assertEquals("B", observed.getAnnotations().get("ZT").getType());
    assertEquals("f", observed.getAnnotations().get("ZT").getArrayType());
    assertEquals(Float.valueOf(3.4f), observed.getAnnotationFloats("ZT").get(0));
    assertEquals(Float.valueOf(4.5f), observed.getAnnotationFloats("ZT").get(1));
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) Annotation(org.dishevelled.bio.annotation.Annotation) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 13 with Annotation

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

the class Header method valueOf.

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

Example 14 with Annotation

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

the class Path method valueOf.

/**
 * Parse a path GFA 1.0 record from the specified value.
 *
 * @param value value, must not be null
 * @return a path GFA 1.0 record parsed from the specified value
 */
public static Path valueOf(final String value) {
    checkNotNull(value);
    checkArgument(value.startsWith("P"), "path value must start with P");
    List<String> tokens = Splitter.on("\t").splitToList(value);
    if (tokens.size() < 4) {
        throw new IllegalArgumentException("path value must have at least four tokens, was " + tokens.size());
    }
    String name = tokens.get(1);
    List<Reference> segments = "*".equals(tokens.get(2)) ? EMPTY_SEGMENTS : Splitter.on(",").splitToList(tokens.get(2)).stream().map(Reference::valueOf).collect(Collectors.toList());
    List<String> overlaps = "*".equals(tokens.get(3)) ? null : ImmutableList.copyOf(Splitter.on(",").split(tokens.get(3)));
    ImmutableMap.Builder<String, Annotation> annotations = ImmutableMap.builder();
    for (int i = 4; i < tokens.size(); i++) {
        String token = tokens.get(i);
        if (!token.isEmpty()) {
            Annotation annotation = Annotation.valueOf(token);
            annotations.put(annotation.getName(), annotation);
        }
    }
    return new Path(name, segments, overlaps, annotations.build());
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Annotation(org.dishevelled.bio.annotation.Annotation)

Example 15 with Annotation

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

the class Path method valueOf.

/**
 * Parse a path GFA 2.0 record from the specified value.
 *
 * @param value value, must not be null
 * @return a path GFA 2.0 record parsed from the specified value
 */
public static Path valueOf(final String value) {
    checkNotNull(value);
    checkArgument(value.startsWith("O"), "path value must start with O");
    List<String> tokens = Splitter.on("\t").splitToList(value);
    if (tokens.size() < 3) {
        throw new IllegalArgumentException("path value must have at least three tokens, was " + tokens.size());
    }
    String id = "*".equals(tokens.get(1)) ? null : tokens.get(1);
    List<Reference> references = Splitter.on(" ").splitToList(tokens.get(2)).stream().map(Reference::valueOf).collect(Collectors.toList());
    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 Path(id, references, 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