From cc65705b3eab17462bef617f53eb5f0f874c0bf4 Mon Sep 17 00:00:00 2001 From: Pavel Silin Date: Mon, 7 Aug 2017 16:40:05 +0300 Subject: [PATCH] implement logic for searching the real name of the given chr from reference (#29) --- .../manager/wig/BedGraphProcessor.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/server/catgenome/src/main/java/com/epam/catgenome/manager/wig/BedGraphProcessor.java b/server/catgenome/src/main/java/com/epam/catgenome/manager/wig/BedGraphProcessor.java index 3364d027f..858536e20 100644 --- a/server/catgenome/src/main/java/com/epam/catgenome/manager/wig/BedGraphProcessor.java +++ b/server/catgenome/src/main/java/com/epam/catgenome/manager/wig/BedGraphProcessor.java @@ -37,7 +37,9 @@ import com.epam.catgenome.manager.wig.reader.BedGraphReader; import com.epam.catgenome.util.IOHelper; import com.epam.catgenome.util.NgbFileUtils; +import com.epam.catgenome.util.Utils; import htsjdk.samtools.util.PeekableIterator; +import htsjdk.tribble.index.Index; import htsjdk.tribble.index.IndexFactory; import htsjdk.tribble.index.interval.IntervalTreeIndex; import org.springframework.util.Assert; @@ -90,15 +92,14 @@ protected void prepareWigFileToWork(WigFile wigFile) throws IOException { biologicalDataItemManager.createBiologicalDataItem(wigFile.getIndex()); } - - @Override protected void splitByChromosome(WigFile wigFile, Map chromosomeMap) throws IOException { List sectionList = new ArrayList<>(); for (Chromosome chromosome : chromosomeMap.values()) { + String realChrName = fetchRealChrName(wigFile.getIndex().getPath(), chromosome.getName()); try (PeekableIterator query = new PeekableIterator<>( new BedGraphReader(wigFile.getPath(), wigFile.getIndex().getPath()).query( - chromosome.getName(), 1, chromosome.getSize() - 1))) { + realChrName, 1, chromosome.getSize() - 1))) { int start = 0; int stop = chromosome.getSize(); int bp = start; @@ -126,10 +127,12 @@ protected void assertFile(String requestPath) { } private void fillBlocksFromFile(String bedGraphPath, String bedGraphIndexPath, Track track, - String chromosome) throws IOException { + String chromosomeName) throws IOException { + String realChrName = fetchRealChrName(bedGraphIndexPath, chromosomeName); try (PeekableIterator bedGraphFeatureIterator = new PeekableIterator<>( new BedGraphReader(bedGraphPath, bedGraphIndexPath) - .query(chromosome, track.getStartIndex(), track.getEndIndex()))) { + .query(realChrName, track.getStartIndex(), track.getEndIndex()) + )) { for (Wig trackBlock : track.getBlocks()) { float score = getScoreForBounds( bedGraphFeatureIterator, track.getStartIndex(), trackBlock.getEndIndex() @@ -139,6 +142,21 @@ private void fillBlocksFromFile(String bedGraphPath, String bedGraphIndexPath, T } } + private String fetchRealChrName(String bedGraphIndexPath, String chromosomeName) { + Index index = IndexFactory.loadIndex(bedGraphIndexPath); + String realName = chromosomeName; + for (String chr : index.getSequenceNames()) { + if (chromosomeName.equals(chr)) { + realName = chr; + break; + } else if (Utils.changeChromosomeName(chromosomeName).equals(chr)) { + realName = chr; + break; + } + } + return realName; + } + private float getScoreForBounds(PeekableIterator query, int chunkStart, int chunkStop) { float score = 0.0f; while (query.hasNext()) {