Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for ccm and cmx out of sync #171

Merged
merged 3 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/core/conditionaltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ std::unique_ptr<EAbstractAnalyticBlock> ConditionalTest::makeWork(int index) con

// initialize pairwise iterator for cmx file
CorrelationMatrix::Pair cmxPair(_cmx);
if (index == 0)
{
cmxPair.readFirst();
}
else
{
cmxPair.read(Pairwise::Index(start));
}

// iterate to the start index of the next work block
cmxPair.read(Pairwise::Index(start));

// Iterate to the start index of the next work block
for ( qint64 i = 0; i < size; i++ )
{
cmxPair.readNext();
Expand Down Expand Up @@ -134,6 +140,7 @@ void ConditionalTest::process(const EAbstractAnalyticBlock* result)
{
csmPair.write(pair.index);
}

}
}

Expand Down
10 changes: 5 additions & 5 deletions src/core/conditionaltest_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ std::unique_ptr<EAbstractAnalyticBlock> ConditionalTest::Serial::execute(const E
// iterate through each pair in the work block
for ( qint64 wbIndex = 0; wbIndex < workBlock->size(); ++wbIndex )
{

// print warning if iterator indices do not match
if ( ccmPair.index() != cmxPair.index() )
{
qInfo() << "warning: ccm and cmx files are out of sync";
qInfo() << "warning: ccm and cmx files are out of sync at cmx coordinate ("
<< cmxPair.index().getX() << "," << cmxPair.index().getY() <<").";
}

// initialize set of p values and r2 values for each cluster
Expand Down Expand Up @@ -117,14 +119,14 @@ std::unique_ptr<EAbstractAnalyticBlock> ConditionalTest::Serial::execute(const E

// append pair to result block
resultBlock->append(Pair {
ccmPair.index(),
cmxPair.index(),
pValues,
r2
});

// read the next pair
ccmPair.readNext();
cmxPair.readNext();
ccmPair.read(cmxPair.index());
}

return std::unique_ptr<EAbstractAnalyticBlock>(resultBlock);
Expand Down Expand Up @@ -422,7 +424,6 @@ void ConditionalTest::Serial::test_proportions (
{
// Keeps track of the number of successes for each iteration.
int ns = 0;
int fs = 0;

// The gsl_ran_sample function randomly chooses samples with replacement from a list.
int chosen[bs_t];
Expand All @@ -431,7 +432,6 @@ void ConditionalTest::Serial::test_proportions (
// Now count the number of randomly selected items from the cluster.
for ( int j = 0; j < bs_t; j++ )
{
int etype = ccmPair.at(clusterIndex, chosen[j]);
QString slabel = amx_column.at(chosen[j]);
if ( ccmPair.at(clusterIndex, chosen[j]) == 1 && amx_column.at(chosen[j]) == test_label )
{
Expand Down
13 changes: 10 additions & 3 deletions src/core/corrpower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ std::unique_ptr<EAbstractAnalyticBlock> CorrPowerFilter::makeWork(int index) con

// initialize pairwise iterator for cmx file
CorrelationMatrix::Pair cmxPair(_cmx);
if (index == 0)
{
cmxPair.readFirst();
}
else
{
cmxPair.read(Pairwise::Index(start));
}

// iterate to the start index of the next work block
cmxPair.read(Pairwise::Index(start));

// Iterate to the start index of the next work block
for ( qint64 i = 0; i < size; i++ )
{
cmxPair.readNext();
Expand All @@ -59,6 +65,7 @@ std::unique_ptr<EAbstractAnalyticBlock> CorrPowerFilter::makeWork(int index) con
// save start index of next work block
_workBlockStart = cmxPair.index().toRawIndex();


// construct work block
return std::unique_ptr<EAbstractAnalyticBlock>(new WorkBlock(index, start, size));
}
Expand Down
9 changes: 6 additions & 3 deletions src/core/corrpower_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ std::unique_ptr<EAbstractAnalyticBlock> CorrPowerFilter::Serial::execute(const E
// Iterate through each pair in the work block.
for ( qint64 wbIndex = 0; wbIndex < workBlock->size(); ++wbIndex )
{

// Print warning if iterator indices do not match
if ( ccmPair.index() != cmxPair.index() )
{
qInfo() << "warning: ccm and cmx files are out of sync";
qInfo() << "warning: ccm and cmx files are out of sync at cmx coordinate ("
<< cmxPair.index().getX() << "," << cmxPair.index().getY() <<").";
}

// Get the number of samples and clusters.
Expand Down Expand Up @@ -128,16 +130,17 @@ std::unique_ptr<EAbstractAnalyticBlock> CorrPowerFilter::Serial::execute(const E
if ( new_correlations.size() > 0 )
{
resultBlock->append(Pair {
ccmPair.index(),
cmxPair.index(),
new_labels,
new_correlations,
k_keep
});
}

// read the next pair
ccmPair.readNext();
cmxPair.readNext();
ccmPair.read(cmxPair.index());

}

// We're done! Return the result block.
Expand Down
20 changes: 14 additions & 6 deletions src/core/extract_networkwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,36 @@ int Extract::NetworkWriter::readNext()
{
EDEBUG_FUNC(this,cmx_index);

// read the next pair in the cmx
_cmxPair.readNext();
// Read the next pair in the cmx.
if(_cmxPair.index().toRawIndex() == 0)
{
_cmxPair.readFirst();
}
else {
_cmxPair.readNext();
}

// read the next pair in the ccm (should always match cmx)
if ( _ccm )
{
_ccmPair.readNext();
_ccmPair.read(_cmxPair.index());

if ( _cmxPair.index() != _ccmPair.index() )
{
qInfo() << "warning: cmx and ccm are out of sync";
qInfo() << "warning: cmx and ccm are out of sync at cmx coordinate ("
<< _cmxPair.index().getX() << "," << _cmxPair.index().getY() <<").";
}
}

// read the next pair in the csm (should always match cmx)
if ( _csm )
{
_csmPair.readNext();
_csmPair.read(_cmxPair.index());

if ( _cmxPair.index() != _csmPair.index() )
{
qInfo() << "warning: cmx and ccm are out of sync";
qInfo() << "warning: cmx and ccm are out of sync at cmx coordinate ("
<< _cmxPair.index().getX() << "," << _cmxPair.index().getY() <<").";
}
}

Expand Down
24 changes: 23 additions & 1 deletion src/core/pairwise_matrix_pair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ void Matrix::Pair::write(const Index& index)
* Read the pair with the given pairwise index from the data object file.
*
* @param index
*
* @return the index of the pair. If no pair is found at this index then -1 is returned.
*/
void Matrix::Pair::read(const Index& index) const
qint64 Matrix::Pair::read(const Index& index) const
{
EDEBUG_FUNC(this,&index);

Expand All @@ -61,10 +63,30 @@ void Matrix::Pair::read(const Index& index) const
_rawIndex = clusterIndex;
readNext();
}
return clusterIndex;

}



/*!
spficklin marked this conversation as resolved.
Show resolved Hide resolved
* For sparse matricies the index of the first pair may not be know.
*
* This function is used to find that first pair and read it.
*/
void Matrix::Pair::readFirst() const
{
EDEBUG_FUNC(this);

for (qint64 i = 0; i < _cMatrix->size(); i++)
{
if (this->read(Pairwise::Index(i)) != -1) {
return;
}
}
}


/*!
* Read the next pair in the data object file.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/core/pairwise_matrix_pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ namespace Pairwise
virtual int clusterSize() const = 0;
virtual bool isEmpty() const = 0;
void write(const Index& index);
void read(const Index& index) const;
qint64 read(const Index& index) const;
void reset() const { _rawIndex = 0; }
void readFirst() const;
void readNext() const;
bool hasNext() const { return _rawIndex != _cMatrix->_clusterSize; }
const Index& index() const { return _index; }
Expand Down