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 d3f213f733f5d80a62f00d4967b26edb7a06ba72 authored by Mikhail Kolmogorov on 22 March 2015, 19:11:36 UTC, committed by Mikhail Kolmogorov on 22 March 2015, 19:11:36 UTC
1.1 release
1 parent 4bf798f
  • Files
  • Changes
  • 53dbc5f
  • /
  • ragout
  • /
  • shared
  • /
  • datatypes.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:d3f213f733f5d80a62f00d4967b26edb7a06ba72
directory badge
swh:1:dir:0a8cd1a5f540ec5e1e128be7f47506fb8d26e575
content badge
swh:1:cnt:dc7f01ea94318d314e436f660240ef747ac10d53

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 ...
datatypes.py
#(c) 2013-2014 by Authors
#This file is a part of Ragout program.
#Released under the BSD license (see LICENSE file)

"""
This module provides some common data structures
"""

from collections import namedtuple
from copy import deepcopy


class Block:
    """
    Represents synteny block
    """
    def __init__(self, block_id, sign, start=None, end=None):
        self.block_id = block_id
        self.sign = sign
        self.start = start
        self.end = end

    def length(self):
        if self.start is None or self.end is None:
            return None

        assert self.end >= self.start
        return self.end - self.start

    def signed_id(self):
        return self.block_id * self.sign


class Permutation:
    """
    Represents signed permutation
    """
    def __init__(self, genome_name, chr_name, chr_id, chr_len, blocks):
        self.genome_name = genome_name
        self.chr_name = chr_name
        self.chr_id = chr_id
        self.chr_len = chr_len
        self.blocks = blocks

    def iter_pairs(self):
        for pb, nb in zip(self.blocks[:-1], self.blocks[1:]):
            yield pb, nb

    def __str__(self):
        return "[{0}, {1}, {2}]".format(self.genome_name, self.chr_name,
                                        list(map(lambda b: b.signed_id(),
                                                 self.blocks)))


class Contig:
    """
    Contig data structure for more convenient use
    """
    def __init__(self, seq_name, permutation, sign=1):
        self.perm = permutation
        self.seq_name = seq_name
        self.sign = sign
        self.link = Link(0, [])

    def left_end(self):
        return (self.perm.blocks[0].signed_id() if self.sign > 0
                else -self.perm.blocks[-1].signed_id())

    def right_end(self):
        return (-self.perm.blocks[-1].signed_id() if self.sign > 0
                else self.perm.blocks[0].signed_id())

    def left_gap(self):
        return (self.perm.blocks[0].start if self.sign > 0
                else self.perm.chr_len - self.perm.blocks[-1].end)

    def right_gap(self):
        return (self.perm.chr_len - self.perm.blocks[-1].end
                if self.sign > 0 else self.perm.blocks[0].start)

    def reverse_copy(self):
        contig = deepcopy(self)
        contig.sign = -contig.sign
        return contig

    def signed_perm(self):
        if self.sign > 0:
            return list(map(lambda b: b.signed_id(), self.perm.blocks))
        else:
            return list(map(lambda b: -b.signed_id(), self.perm.blocks[::-1]))

    def __str__(self):
        sign = "+" if self.sign > 0 else "-"
        return sign + self.seq_name


class Link:
    """
    Represens an adjancency between teo contigs
    """
    def __init__(self, gap, supporting_genomes):
        self.gap = gap
        self.supporting_genomes = supporting_genomes
        self.supporting_assembly = False


class Scaffold:
    def __init__(self, name):
        self.left = None
        self.right = None
        self.contigs = []
        self.name = name

    @staticmethod
    def with_contigs(name, left, right, contigs):
        scf = Scaffold(name)
        scf.left = left
        scf.right = right
        scf.contigs = contigs
        return scf
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–2026, 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