-
Notifications
You must be signed in to change notification settings - Fork 295
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
Add get_kmers() and get_kmer_counts() functions #1049
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d42177c
cleaned up the hashtable_methods table a bit
ctb ae175c0
add get_kmers and get_kmer_counts to Hashtable objects
ctb 4a66496
minor refactoring
ctb d1cf0b2
Merge branch 'master' of github.com:ged-lab/khmer into feature/kmer_c…
ctb 527dac5
Merge branch 'master' of github.com:ged-lab/khmer into feature/kmer_c…
ctb 56e1990
added test for Hashtable.get on numerical hash
ctb 6de148b
fixed nasty bug in Hashtable.get() at CPython layer
ctb 1de9d5a
added get_kmer_hashes()
ctb 045e5f9
update ChangeLog
ctb 1f41c51
added some tests for short sequences
ctb 7be805b
Merge branch 'master' into feature/kmer_counts
luizirber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,24 +193,10 @@ void Hashtable::get_median_count(const std::string &s, | |
float &stddev) | ||
{ | ||
std::vector<BoundedCounterType> counts; | ||
KMerIterator kmers(s.c_str(), _ksize); | ||
|
||
while(!kmers.done()) { | ||
HashIntoType kmer = kmers.next(); | ||
BoundedCounterType count = this->get_count(kmer); | ||
counts.push_back(count); | ||
} | ||
this->get_kmer_counts(s, counts); | ||
|
||
if (!counts.size()) { | ||
throw khmer_exception(); | ||
} | ||
|
||
if (!counts.size()) { | ||
median = 0; | ||
average = 0; | ||
stddev = 0; | ||
|
||
return; | ||
throw khmer_exception("no k-mer counts for this string; too short?"); | ||
} | ||
|
||
average = 0; | ||
|
@@ -1522,4 +1508,43 @@ void Hashtable::extract_unique_paths(std::string seq, | |
} | ||
} | ||
} | ||
|
||
|
||
void Hashtable::get_kmers(const std::string &s, | ||
std::vector<std::string> &kmers_vec) const | ||
{ | ||
if (s.length() < _ksize) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other cases where the sequence is shorter than K, we raise an exception; is this a case of letting an error pass silently? |
||
} | ||
for (unsigned int i = 0; i < s.length() - _ksize + 1; i++) { | ||
std::string sub = s.substr(i, i + _ksize); | ||
kmers_vec.push_back(sub); | ||
} | ||
} | ||
|
||
|
||
void Hashtable::get_kmer_hashes(const std::string &s, | ||
std::vector<HashIntoType> &kmers_vec) const | ||
{ | ||
KMerIterator kmers(s.c_str(), _ksize); | ||
|
||
while(!kmers.done()) { | ||
HashIntoType kmer = kmers.next(); | ||
kmers_vec.push_back(kmer); | ||
} | ||
} | ||
|
||
|
||
void Hashtable::get_kmer_counts(const std::string &s, | ||
std::vector<BoundedCounterType> &counts) const | ||
{ | ||
KMerIterator kmers(s.c_str(), _ksize); | ||
|
||
while(!kmers.done()) { | ||
HashIntoType kmer = kmers.next(); | ||
BoundedCounterType c = this->get_count(kmer); | ||
counts.push_back(c); | ||
} | ||
} | ||
|
||
// vim: set sts=2 sw=2: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has no dependency on Hashtable; it should go elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It uses ksize.
Titus Brown, ctbrown@ucdavis.edu