Search in sources :

Example 21 with Annotation

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

the class Traversal method valueOf.

/**
 * Parse a traversal GFA 1.0 record from the specified value.
 *
 * @param value value, must not be null
 * @return a traversal GFA 1.0 record parsed from the specified value
 */
public static Traversal valueOf(final String value) {
    checkNotNull(value);
    checkArgument(value.startsWith("t"), "traversal value must start with t");
    List<String> tokens = Splitter.on("\t").splitToList(value);
    if (tokens.size() < 8) {
        throw new IllegalArgumentException("traversal value must have at least eight tokens, was " + tokens.size());
    }
    String name = tokens.get(1);
    int ordinal = Integer.parseInt(tokens.get(2));
    Reference source = Reference.splitValueOf(tokens.get(3), tokens.get(4));
    Reference target = Reference.splitValueOf(tokens.get(5), tokens.get(6));
    String overlap = "*".equals(tokens.get(7)) ? null : tokens.get(7);
    ImmutableMap.Builder<String, Annotation> annotations = ImmutableMap.builder();
    for (int i = 8; 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 Traversal(name, ordinal, source, target, overlap, annotations.build());
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Annotation(org.dishevelled.bio.annotation.Annotation)

Example 22 with Annotation

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

the class SamWriterTest method setUp.

@Before
public void setUp() {
    header = SamHeader.builder().withHeaderLine(SamHeaderLine.valueOf(SAM_HEADER)).build();
    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();
    record = new SamRecord("ERR194147.765130386", 99, "chr20", 60250, 60, "101M", "=", 60512, 363, "ACTCCATCCCATTCCATTCCACTCCCTTCATTTCCATTCCAGTCCATTCCATTCCATTCCATTCCATTCCACTCCACTCCATTCCATTCCACTGCACTCCA", "CCCFFFFFHHHHHJJJJJJJJJJJJJJJJJJJJJJJJJIJJJJJJIIJJJJJJJJJJJJJHIIJIJGIJJJJJJJJJJJJJIJJJJJJJJJJJGGHHHFF@", annotations);
    records = ImmutableList.of(record);
    outputStream = new ByteArrayOutputStream();
    writer = new PrintWriter(outputStream);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Annotation(org.dishevelled.bio.annotation.Annotation) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 23 with Annotation

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

the class Containment method valueOf.

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

Example 24 with Annotation

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

the class Edge method valueOf.

/**
 * Parse an edge GFA 2.0 record from the specified value.
 *
 * @param value value, must not be null
 * @return an edge GFA 2.0 record parsed from the specified value
 */
public static Edge valueOf(final String value) {
    checkNotNull(value);
    checkArgument(value.startsWith("E"), "edge value must start with E");
    List<String> tokens = Splitter.on("\t").splitToList(value);
    if (tokens.size() < 9) {
        throw new IllegalArgumentException("edge value must have at least nine tokens, was " + tokens.size());
    }
    String id = "*".equals(tokens.get(1)) ? null : tokens.get(1);
    Reference source = Reference.valueOf(tokens.get(2));
    Reference target = Reference.valueOf(tokens.get(3));
    Position sourceStart = Position.valueOf(tokens.get(4));
    Position sourceEnd = Position.valueOf(tokens.get(5));
    Position targetStart = Position.valueOf(tokens.get(6));
    Position targetEnd = Position.valueOf(tokens.get(7));
    Alignment alignment = Alignment.valueOf(tokens.get(8));
    ImmutableMap.Builder<String, Annotation> annotations = ImmutableMap.builder();
    for (int i = 9; i < tokens.size(); i++) {
        String token = tokens.get(i);
        if (!token.isEmpty()) {
            Annotation annotation = Annotation.valueOf(token);
            annotations.put(annotation.getName(), annotation);
        }
    }
    return new Edge(id, source, target, sourceStart, sourceEnd, targetStart, targetEnd, alignment, annotations.build());
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Annotation(org.dishevelled.bio.annotation.Annotation)

Example 25 with Annotation

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

the class Fragment method valueOf.

/**
 * Parse a fragment GFA 2.0 record from the specified value.
 *
 * @param value value, must not be null
 * @return a fragment GFA 2.0 record parsed from the specified value
 */
public static Fragment valueOf(final String value) {
    checkNotNull(value);
    checkArgument(value.startsWith("F"), "fragment value must start with F");
    List<String> tokens = Splitter.on("\t").splitToList(value);
    if (tokens.size() < 8) {
        throw new IllegalArgumentException("fragment value must have at least eight tokens, was " + tokens.size());
    }
    String segmentId = tokens.get(1);
    Reference external = Reference.valueOf(tokens.get(2));
    Position segmentStart = Position.valueOf(tokens.get(3));
    Position segmentEnd = Position.valueOf(tokens.get(4));
    Position fragmentStart = Position.valueOf(tokens.get(5));
    Position fragmentEnd = Position.valueOf(tokens.get(6));
    Alignment alignment = Alignment.valueOf(tokens.get(7));
    ImmutableMap.Builder<String, Annotation> annotations = ImmutableMap.builder();
    for (int i = 8; i < tokens.size(); i++) {
        String token = tokens.get(i);
        if (!token.isEmpty()) {
            Annotation annotation = Annotation.valueOf(token);
            annotations.put(annotation.getName(), annotation);
        }
    }
    return new Fragment(segmentId, external, segmentStart, segmentEnd, fragmentStart, fragmentEnd, alignment, 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