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

Feature request - add option to sort by query name like Picard #369

Closed
TimurIs opened this issue Oct 2, 2018 · 5 comments
Closed

Feature request - add option to sort by query name like Picard #369

TimurIs opened this issue Oct 2, 2018 · 5 comments

Comments

@TimurIs
Copy link
Contributor

TimurIs commented Oct 2, 2018

Hi,

I think it could be a good thing to make sambamba query-name sort be compatible with other Picard tools. I wrote a quick implementation of this in BioD/bio/bam/reader.d (based on https://github.com/samtools/htsjdk/blob/master/src/main/java/htsjdk/samtools/SAMRecordQueryNameComparator.java)

bool compareReadNames(R1, R2)(const auto ref R1 a1, const auto ref R2 a2)
    if (isBamRead!R1 && isBamRead!R2)
{
    if(a1.name == a2.name)
    {
        if(a1.is_paired() || a2.is_paired())
        {
            if(!a1.is_paired())
                return false;
            if(!a2.is_paired())
                return true;

            if(a1.is_first_of_pair() && a2.is_second_of_pair())
                return true;

            if(a1.is_second_of_pair() && a2.is_first_of_pair())
                return false;
                
        }

        if(a1.strand() != a2.strand())
        {
            return a1.strand() == '-' ? false : true;
        }

        if(a1.is_secondary_alignment() != a2.is_secondary_alignment())
        {
            return a2.is_secondary_alignment();
        }

        if(a1.is_supplementary() != a2.is_supplementary())
        {
            return a2.is_supplementary();
        }

        if(!a1["HI"].is_nothing)
        {
                if(a2["HI"].is_nothing)
                        return true;

                int i1 = to!int(a1["HI"]);
                int i2 = to!int(a2["HI"]);
                return i1 < i2;
        }
        else
        if(!a2["HI"].is_nothing)
                return false;
    }
    return a1.name < a2.name;
}

But I'm very new to the field of bioinformatics and I'm using the D language for the first time, so that is why I've decided not to use the Pull-request.

I'm open for any kind of collaboration as long as I can get some guidence in D language.

Thank you,
Timur

@pjotrp
Copy link
Member

pjotrp commented Oct 3, 2018

Hi @TimurIs. I think you can make a PR no problem. I'll take a look at it when you do. You should be able to compile it and do a quick test run.

Thanks.

@pjotrp
Copy link
Member

pjotrp commented Oct 12, 2018

Can we expect a PR? Otherwise I'll close this issue.

@TimurIs
Copy link
Contributor Author

TimurIs commented Oct 12, 2018

Yes, I'll do it soon. Sorry for a delay

@TimurIs
Copy link
Contributor Author

TimurIs commented Oct 15, 2018

Hello @pjotrp,

I've created 2 PRs: 1 for sambamba and 1 for BioD. Check them please and let me know if I screwed something up :)

@pjotrp
Copy link
Member

pjotrp commented Oct 17, 2018

Added. Thanks @TimurIs

@pjotrp pjotrp closed this as completed Oct 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants