Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 7b92fe7a0c5fc29dce009c066d35dd8298462388 authored by Mikhail Kolmogorov on 08 December 2020, 17:38:21 UTC, committed by GitHub on 08 December 2020, 17:38:21 UTC
Merge pull request #70 from ddeka2910/master
Add architecture ppc64le to travis build
2 parent s 031e062 + 686db1b
  • Files
  • Changes
  • fdbb28c
  • /
  • scripts
  • /
  • utils
  • /
  • lastz_parser.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:7b92fe7a0c5fc29dce009c066d35dd8298462388
directory badge Iframe embedding
swh:1:dir:26071198c1f6777d252cd728fd013ae9fbbcca45
content badge Iframe embedding
swh:1:cnt:e55a4a7b5539c08d6f74c20f0d00b9494a7e4732

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
lastz_parser.py

#(c) 2013-2014 by Authors
#This file is a part of Ragout program.
#Released under the BSD license (see LICENSE file)

"""
Functions for lastz input handling
"""

from __future__ import absolute_import
from __future__ import print_function
import subprocess
import os
from itertools import combinations

from .common import AlignmentColumn, AlignmentRow
from six.moves import filter

def parse_lastz_maf(filename):
    alignments = []
    with open(filename, "r") as f:
        while True:
            line = f.readline()
            if not line:
                break

            if not line.startswith("a"):
                state = 1
                continue

            #read two next lines
            ref_line = f.readline().strip()
            qry_line = f.readline().strip()
            assert ref_line.startswith("s") and qry_line.startswith("s")

            def parse_column(string):
                seq_id, start, aln_len, strand, seq_len = string.split()[1:6]
                aln_len, seq_len = int(aln_len), int(seq_len)
                strand = 1 if strand == "+" else -1
                if strand > 0:
                    start, end = int(start), int(start) + aln_len
                else:
                    end = seq_len - 1 - int(start)
                    start = end - aln_len

                assert end >= start
                return AlignmentRow(start, end, strand, seq_len, seq_id)

            alignments.append(AlignmentColumn(parse_column(ref_line),
                                              parse_column(qry_line)))

    return alignments


def filter_intersecting(alignments):
    to_filter = set()

    def filter_by_rows(rows):
        for row_1, row_2 in combinations(rows, 2):
            if row_1.seq_id != row_2.seq_id:
                continue

            if row_1.start <= row_2.start <= row_1.end:
                to_filter.add(row_2)
                if not (row_1.start <= row_2.end <= row_1.end):
                    to_filter.add(row_1)
            continue

            #if row_2.start <= row_1.start <= row_2.end:
            #    to_filter.add(row_1)
            #    if not (row_2.start <= row_1.end <= row_2.end):
            #        to_filter.add(row_2)

    filter_by_rows([ap.ref for ap in alignments])
    filter_by_rows([ap.qry for ap in alignments])

    return [a for a in alignments if a.ref not in to_filter and
                                     a.qry not in to_filter]


def filter_by_length(alignments, min_len):
    func = (lambda a: abs(a.ref.start - a.ref.end) > min_len and
                      abs(a.qry.start - a.qry.end) > min_len)
    return list(filter(func, alignments))


LASTZ_BIN = "lastz"
def run_lastz(reference, target, out_file):
    print("Running lastz")
    reference = os.path.abspath(reference)
    target = os.path.abspath(target)
    out_file = os.path.abspath(out_file)
    cmdline = [LASTZ_BIN, reference + "[multiple,nameparse=darkspace]",
               target + "[nameparse=darkspace]","--notransition",
               "--step=20", "--chain", "--gapped", "--gfextend",
               "--ambiguous=iupac", "--format=maf", "--output=" + out_file,
               "--rdotplot=dotplot.txt"]
    devnull = os.devnull
    subprocess.check_call(cmdline, stderr=open(devnull, "w"))
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API