use of io.repseq.core.VDJCGeneId in project mixcr by milaboratory.
the class ActionClonesDiff method getKey.
private CKey getKey(Clone clone) {
final NucleotideSequence[] clonalSequence = new NucleotideSequence[clone.numberOfTargets()];
for (int i = 0; i < clonalSequence.length; i++) clonalSequence[i] = clone.getTarget(i).getSequence();
final VDJCGeneId v = params.useV() ? getBestGene(clone, GeneType.Variable) : null;
final VDJCGeneId j = params.useJ() ? getBestGene(clone, GeneType.Joining) : null;
final VDJCGeneId c = params.useC() ? getBestGene(clone, GeneType.Constant) : null;
return new CKey(clonalSequence, v, j, c);
}
use of io.repseq.core.VDJCGeneId in project mixcr by milaboratory.
the class IOUtil method readGeneReferences.
public static List<VDJCGene> readGeneReferences(PrimitivI input, VDJCLibraryRegistry registry) {
// Reading gene ids
int count = input.readInt();
List<VDJCGene> genes = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
VDJCGeneId id = input.readObject(VDJCGeneId.class);
VDJCGene gene = registry.getGene(id);
if (gene == null)
throw new RuntimeException("Gene not found: " + id);
genes.add(gene);
}
return genes;
}
use of io.repseq.core.VDJCGeneId in project mixcr by milaboratory.
the class CloneAccumulator method calculateScores.
public void calculateScores(CloneFactoryParameters parameters) {
for (GeneType geneType : GeneType.VJC_REFERENCE) {
VJCClonalAlignerParameters vjcParameters = parameters.getVJCParameters(geneType);
if (vjcParameters == null)
continue;
TObjectFloatHashMap<VDJCGeneId> accumulatorGeneIds = geneScores.get(geneType);
if (accumulatorGeneIds == null)
continue;
TObjectFloatIterator<VDJCGeneId> iterator = accumulatorGeneIds.iterator();
float maxScore = 0;
while (iterator.hasNext()) {
iterator.advance();
float value = iterator.value();
if (value > maxScore)
maxScore = value;
}
maxScore = maxScore * vjcParameters.getRelativeMinScore();
iterator = accumulatorGeneIds.iterator();
while (iterator.hasNext()) {
iterator.advance();
if (maxScore > iterator.value())
iterator.remove();
else
iterator.setValue(Math.round(iterator.value() * 10f / coreCount) / 10f);
}
}
}
use of io.repseq.core.VDJCGeneId in project mixcr by milaboratory.
the class TargetMerger method extractHitsMapping.
@SuppressWarnings("unchecked")
static Map<VDJCGeneId, HitMappingRecord> extractHitsMapping(AlignedTarget targetLeft, AlignedTarget targetRight, GeneType geneType) {
Map<VDJCGeneId, HitMappingRecord> map = new HashMap<>();
for (VDJCHit l : targetLeft.getAlignments().getHits(geneType)) {
final VDJCGene gene = l.getGene();
final Alignment<NucleotideSequence> al = l.getAlignment(targetLeft.getTargetId());
if (al != null)
map.put(gene.getId(), new HitMappingRecord(gene, new Alignment[] { al, null }));
}
for (VDJCHit r : targetRight.getAlignments().getHits(geneType)) {
final VDJCGene gene = r.getGene();
final Alignment<NucleotideSequence> alignment = r.getAlignment(targetRight.getTargetId());
if (alignment == null)
continue;
final HitMappingRecord als = map.get(gene.getId());
if (als == null)
map.put(gene.getId(), new HitMappingRecord(gene, new Alignment[] { null, alignment }));
else {
assert als.alignments[1] == null;
als.alignments[1] = alignment;
}
}
return map;
}
use of io.repseq.core.VDJCGeneId in project mixcr by milaboratory.
the class TargetMerger method extractSortedHits.
@SuppressWarnings("unchecked")
static List<HitMappingRecord> extractSortedHits(AlignedTarget targetLeft, AlignedTarget targetRight, GeneType geneType) {
// Fast calculation for targets from the same PE-read (or multi-read)
if (targetLeft.getAlignments() == targetRight.getAlignments()) {
VDJCHit[] hits = targetLeft.getAlignments().getHits(geneType);
List<HitMappingRecord> mRecords = new ArrayList<>(hits.length);
for (VDJCHit hit : hits) mRecords.add(new HitMappingRecord(hit.getGene(), new Alignment[] { hit.getAlignment(targetLeft.getTargetId()), hit.getAlignment(targetRight.getTargetId()) }));
// other parts of the multi-read object
return mRecords;
}
// Full recalculation for targets form two different Alignments objects
Map<VDJCGeneId, HitMappingRecord> map = extractHitsMapping(targetLeft, targetRight, geneType);
List<HitMappingRecord> mRecords = new ArrayList<>(map.values());
Collections.sort(mRecords, new Comparator<HitMappingRecord>() {
@Override
public int compare(HitMappingRecord o1, HitMappingRecord o2) {
return Integer.compare(sumScore(o2.alignments), sumScore(o1.alignments));
}
});
return mRecords;
}
Aggregations