Skip to content

How splitcode prioritizes matches beyond position and length of match: edit distance and order of tags in the config file #56

Open

Description

@bentyeh

When 2 config entries with the same name and same tag sequence length match a read subsequence with the same edit distance at the same position, which entry does splitcode determine to match?

Splitcode's documentation currently does not address this question. The FAQ only notes that splitcode prioritizes matches based on:

  1. position (left to right)
  2. length of match

My understanding based on the source code is that splitcode additionally prioritizes based on the following:

  1. shortest edit distance

    splitcode/src/SplitCode.h

    Lines 2213 to 2216 in 530d1fe

    if (!found_curr || (found_curr && error_prev > x.second)) {
    error_prev = x.second;
    tag_id_curr = tag_id_; // if tags have same name but different mismatch errors: choose the tag w/ smallest error
    }

  2. order in which the entry appeared in the config file (earlier is higher priority)
    • The iteration order is over it->second — the vector stored in the tags hash map for the key corresponding to the current k-mer subsequence of the read being check. This vector is populated by addToMap in the order the tags were processed during config file loading.

This understanding matches the results from the example below.

@Yenaled would you mind confirming my understanding? If so, I'm happy to submit a pull request to update the documentation.


Example

Both tagA entries match read1 with 1 mismatch, and both tagB entries match read2 with 1 mismatch. How does splitcode choose which tagA entry (the one with sequence ATGT or ACGT) matches read1, and which tagB entry (TCGG or TCAG) matches read2? Is it based on the order in which the entries appear in the config file?

The first tagC entry matches read3 with 1 mismatch, while the second tagC entry matches read3 with 0 mismatches. Does splitcode prioritize matching based on the number of mismatches or the order in which entries appear in the config file?

In each case, splitcode's choice should be reflected in whether the sequence is trimmed or not.

input.fasta

>read1
AGGT
>read2
TCTG
>read3
GCCAT

config.txt

ids	tags	distance	left
tagA	ATGT	1	1
tagA	ACGT	1	-
tagB	TCGG	1	-
tagB	TCAG	1	1
tagC	GCCAG	1	-
tagC	GCCAT	1	1

splitcode command

splitcode -c config.txt --loc-names --out-fasta --output=out.fasta input.fasta
cat out.fasta

Result

* Using a list of 4 tags (vector size: 4; map size: 56; num elements in map: 68)
* will process sample 1: input.fasta
* processing the reads ...
done 
* processed 2 reads
>read1 LX:Z:tagA:0,0-4

>read2 LX:Z:tagB:0,0-4
TCTG
>read3 LX:Z:tagC:0,0-5

splitcode matched the first tagA entry ATGT to read1 (so trimming was applied) and the first tagB entry TCGG to read2 (so trimming was not applied), indicating that when the edit distance is the same, splitcode prioritizes entries based on their order in the config file.

splitcode matched the second tagC entry (with 0 mismatches) to read3 (so trimming was applied), even though the first tagC entry could have matched as well (with 1 mismatch), indicating that splitcode prioritizes edit distance above entry order in the config file.

Tested with splitcode version 0.31.6: https://colab.research.google.com/drive/1kPGq5Zi0yii4dTZIeKmXkxvgRbvrdn1x

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions