Search in sources :

Example 1 with SequenceAddress

use of io.repseq.seqbase.SequenceAddress in project repseqio by repseqio.

the class VDJCLibraryRegistry method registerLibrary.

/**
 * Creates and registers single library from VDJCLibraryData
 *
 * @param context context to use for resolution of sequences
 * @param name    library name
 * @param data    library data
 * @return created library
 */
public synchronized VDJCLibrary registerLibrary(Path context, String name, VDJCLibraryData data) {
    // Creating library object
    VDJCLibrary library = new VDJCLibrary(data, name, this, context);
    // Getting library id
    VDJCLibraryId rootId = library.getLibraryIdWithoutChecksum();
    // Check if such library is already registered
    if (libraries.containsKey(rootId))
        throw new RuntimeException("Duplicate library: " + rootId);
    // Loading known sequence fragments from VDJCLibraryData to current SequenceResolver
    SequenceResolver resolver = getSequenceResolver();
    for (KnownSequenceFragmentData fragment : data.getSequenceFragments()) resolver.resolve(new SequenceAddress(context, fragment.getUri())).setRegion(fragment.getRange(), fragment.getSequence());
    // Adding genes
    for (VDJCGeneData gene : data.getGenes()) VDJCLibrary.addGene(library, gene);
    // Adding common species names
    Long taxonId = data.getTaxonId();
    for (String speciesName : data.getSpeciesNames()) {
        String cSpeciesName = canonicalizeSpeciesName(speciesName);
        if (speciesNames.containsKey(cSpeciesName) && !speciesNames.get(cSpeciesName).equals(taxonId))
            throw new IllegalArgumentException("Mismatch in common species name between several libraries. " + "(Library name = " + name + "; name = " + speciesName + ").");
        speciesNames.put(cSpeciesName, taxonId);
        List<String> names = speciesNamesReverse.get(taxonId);
        if (names == null)
            speciesNamesReverse.put(taxonId, names = new ArrayList<>());
        names.add(speciesName);
    }
    // Adding this library to collection
    libraries.put(library.getLibraryIdWithoutChecksum(), library);
    return library;
}
Also used : SequenceResolver(io.repseq.seqbase.SequenceResolver) KnownSequenceFragmentData(io.repseq.dto.KnownSequenceFragmentData) SequenceAddress(io.repseq.seqbase.SequenceAddress) VDJCGeneData(io.repseq.dto.VDJCGeneData)

Example 2 with SequenceAddress

use of io.repseq.seqbase.SequenceAddress in project repseqio by repseqio.

the class BaseSequence method resolve.

/**
 * Returns SequenceProvider to access underlying sequence
 *
 * @param context  resolution context
 * @param resolver sequence resolver
 * @return SequenceProvider to access underlying sequence
 */
public SequenceProvider<NucleotideSequence> resolve(Path context, SequenceResolver resolver) {
    CachedSequenceProvider<NucleotideSequence> originalProvider = resolver.resolve(new SequenceAddress(context, origin));
    if (isPureOriginalSequence()) {
        return originalProvider;
    } else {
        // TODO implement more lazy algorithm
        int length = 0;
        for (Range region : regions) length += region.length();
        SequenceBuilder<NucleotideSequence> builder = NucleotideSequence.ALPHABET.createBuilder().ensureCapacity(length);
        for (Range region : regions) builder.append(originalProvider.getRegion(region));
        NucleotideSequence seq = builder.createAndDestroy();
        seq = mutations == null ? seq : mutations.mutate(seq);
        return SequenceProviderUtils.fromSequence(seq);
    }
}
Also used : SequenceAddress(io.repseq.seqbase.SequenceAddress) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) Range(com.milaboratory.core.Range)

Aggregations

SequenceAddress (io.repseq.seqbase.SequenceAddress)2 Range (com.milaboratory.core.Range)1 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)1 KnownSequenceFragmentData (io.repseq.dto.KnownSequenceFragmentData)1 VDJCGeneData (io.repseq.dto.VDJCGeneData)1 SequenceResolver (io.repseq.seqbase.SequenceResolver)1