Search in sources :

Example 31 with Annotation

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

the class EdgeTest method setUp.

@Before
public void setUp() {
    id = "id";
    source = Reference.valueOf("source+");
    target = Reference.valueOf("target+");
    sourceStart = Position.valueOf("1");
    sourceEnd = Position.valueOf("10");
    targetStart = Position.valueOf("101");
    targetEnd = Position.valueOf("110");
    alignment = Alignment.valueOf("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 32 with Annotation

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

the class GapTest method setUp.

@Before
public void setUp() {
    id = "id";
    source = Reference.valueOf("source+");
    target = Reference.valueOf("target+");
    distance = 42;
    variance = Integer.valueOf(2);
    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 33 with Annotation

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

the class SamRecord method valueOf.

/**
 * Parse a SAM record from the specified value.
 *
 * @param value value, must not be null
 * @return a SAM record parsed from the specified value
 */
public static SamRecord valueOf(final String value) {
    checkNotNull(value);
    List<String> tokens = Splitter.on("\t").splitToList(value);
    if (tokens.size() < 11) {
        throw new IllegalArgumentException("invalid record, expected 11 or more tokens, found " + tokens.size());
    }
    // QNAME String [!-?A-~]{1,254} Query template NAME
    String qname = "*".equals(tokens.get(0)) ? null : tokens.get(0);
    // FLAG Int [0,2^16-1] bitwise FLAG
    int flag = Integer.parseInt(tokens.get(1));
    // RNAME String \*|[!-()+-<>-~][!-~]* Reference sequence NAME
    String rname = "*".equals(tokens.get(2)) ? null : tokens.get(2);
    // POS Int [0,2^31-1] 1-based leftmost mapping POSition
    int pos = Integer.parseInt(tokens.get(3));
    // MAPQ Int [0,28-1] MAPping Quality
    int mapq = Integer.parseInt(tokens.get(4));
    // CIGAR String \*|([0-9]+[MIDNSHPX=])+ CIGAR string
    String cigar = "*".equals(tokens.get(5)) ? null : tokens.get(5);
    // RNEXT String \*|=|[!-()+-<>-~][!-~]* Ref. name of the mate/next read
    String rnext = "*".equals(tokens.get(6)) ? null : tokens.get(6);
    // PNEXT Int [0,2^31-1] Position of the mate/next read
    int pnext = Integer.parseInt(tokens.get(7));
    // TLEN Int [-2^31+1,2^31-1] observed Template LENgth
    int tlen = Integer.parseInt(tokens.get(8));
    // SEQ String \*|[A-Za-z=.]+ segment SEQuence
    String seq = "*".equals(tokens.get(9)) ? null : tokens.get(9);
    // QUAL String [!-~]+ ASCII of Phred-scaled base QUALity+33
    String qual = "*".equals(tokens.get(10)) ? null : tokens.get(10);
    ImmutableMap.Builder<String, Annotation> annotations = ImmutableMap.builder();
    for (int i = 11; 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 SamRecord(qname, flag, rname, pos, mapq, cigar, rnext, pnext, tlen, seq, qual, annotations.build());
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Annotation(org.dishevelled.bio.annotation.Annotation)

Example 34 with Annotation

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

the class PafRecord method valueOf.

/**
 * Parse a PAF record from the specified value.
 *
 * @param value value, must not be null
 * @return a PAF record parsed from the specified value
 */
public static PafRecord valueOf(final String value) {
    checkNotNull(value);
    List<String> tokens = Splitter.on("\t").splitToList(value);
    if (tokens.size() < 12) {
        throw new IllegalArgumentException("PAF record value must have at least twelve tokens, was " + tokens.size());
    }
    String queryName = tokens.get(0);
    long queryLength = Long.parseLong(tokens.get(1));
    long queryStart = Long.parseLong(tokens.get(2));
    long queryEnd = Long.parseLong(tokens.get(3));
    char strand = tokens.get(4).charAt(0);
    String targetName = tokens.get(5);
    long targetLength = Long.parseLong(tokens.get(6));
    long targetStart = Long.parseLong(tokens.get(7));
    long targetEnd = Long.parseLong(tokens.get(8));
    long matches = Long.parseLong(tokens.get(9));
    long alignmentBlockLength = Long.parseLong(tokens.get(10));
    int mappingQuality = Integer.parseInt(tokens.get(11));
    ImmutableMap.Builder<String, Annotation> annotations = ImmutableMap.builder();
    for (int i = 12; 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 PafRecord(queryName, queryLength, queryStart, queryEnd, strand, targetName, targetLength, targetStart, targetEnd, matches, alignmentBlockLength, mappingQuality, 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