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

https://github.com/fenderglass/Ragout
05 April 2024, 18:02:13 UTC
  • Code
  • Branches (21)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/chr_map
    • refs/heads/devel
    • refs/heads/gh-pages
    • refs/heads/ismb_2014
    • refs/heads/master
    • refs/heads/path_cover
    • refs/heads/py3
    • refs/heads/rr_devel
    • refs/heads/tree_infer
    • refs/remotes/origin/devel
    • refs/tags/1.0
    • refs/tags/1.1
    • refs/tags/2.0
    • refs/tags/2.1
    • refs/tags/2.1.1
    • refs/tags/2.2
    • refs/tags/2.3
    • refs/tags/v0.1b
    • refs/tags/v0.2b
    • refs/tags/v0.3b
    • refs/tags/v1.2
    No releases to show
  • 4cbe8e4
  • /
  • ragout
  • /
  • breakpoint_graph
  • /
  • permutation.py
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

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.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:23e9ff6876a63ec01de96ebe683dd8c166067681
origin badgedirectory badge
swh:1:dir:26947386b480ee415a03856d8895bfb76ec556e2
origin badgerevision badge
swh:1:rev:4b42ddec7d839ab6369faa31a49e2d3a8db7d124
origin badgesnapshot badge
swh:1:snp:12412e9d5850529b00b9f75cc3a4b47d1a47cc92

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.

  • content
  • directory
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 4b42ddec7d839ab6369faa31a49e2d3a8db7d124 authored by fenderglass on 26 April 2014, 05:29:56 UTC
instal
Tip revision: 4b42dde
permutation.py
#This module provides PermutationContainer class
#which stores permutations and provides some filtering
#procedures
######################################################

from collections import defaultdict
import logging
import os

from ragout.shared.debug import DebugConfig
import ragout.parsers.config_parser as parser

logger = logging.getLogger()
debugger = DebugConfig.get_instance()

#PUBLIC:
########################################################

class Permutation:
    def __init__(self, ref_id, chr_id, chr_num, blocks):
        self.ref_id = ref_id
        self.chr_id = chr_id
        self.chr_num = chr_num
        self.blocks = blocks
        self.target_perms = []
        self.ref_perms = []
        self.ref_perms_filtered = []
        self.target_perms_filtered = []

    #iterates over synteny blocks in permutation
    def iter_blocks(self, circular=False):
        if not len(self.blocks):
            return

        for block in self.blocks:
            yield block

        if circular:
            yield self.blocks[0]


class PermutationContainer:
    #parses permutation files referenced from config and filters duplications
    def __init__(self, config_file):
        self.ref_perms = []
        self.target_perms = []

        logging.info("Reading permutation file")
        config = parser.parse_ragout_config(config_file)
        for ref_id, ref_file in config.references.items():
            self.ref_perms.extend(_parse_blocks_file(ref_id, ref_file))

        for t_id, t_file in config.targets.items():
            self.target_perms.extend(_parse_blocks_file(t_id, t_file))

        self.target_blocks = set()
        for perm in self.target_perms:
            self.target_blocks |= set(map(abs, perm.blocks))

        #filter dupilcated blocks
        self.duplications = _find_duplications(self.ref_perms,
                                               self.target_perms)
        to_hold = self.target_blocks - self.duplications
        self.ref_perms_filtered = [_filter_perm(p, to_hold)
                                      for p in self.ref_perms]
        self.target_perms_filtered = [_filter_perm(p, to_hold)
                                         for p in self.target_perms]
        self.target_perms_filtered = list(filter(lambda p: p.blocks,
                                                 self.target_perms_filtered))

        if debugger.debugging:
            file = os.path.join(debugger.debug_dir, "used_contigs.txt")
            _write_permutations(self.target_perms_filtered, open(file, "w"))


#PRIVATE:
#######################################################

#find duplicated blocks
def _find_duplications(ref_perms, target_perms):
    index = defaultdict(set)
    duplications = set()
    for perm in ref_perms + target_perms:
        for block in map(abs, perm.blocks):
            if perm.ref_id in index[block]:
                duplications.add(block)
            else:
                index[block].add(perm.ref_id)

    return duplications


#filters duplications
def _filter_perm(perm, to_hold):
    new_perm = Permutation(perm.ref_id, perm.chr_id, perm.chr_num, [])
    for block in perm.blocks:
        if abs(block) in to_hold:
            new_perm.blocks.append(block)
    return new_perm


#parses config file
def _parse_blocks_file(ref_id, filename):
    name = ""
    permutations = []
    chr_count = 0
    for line in open(filename, "r").read().splitlines():
        line = line.strip()
        if not line:
            continue

        if line.startswith(">"):
            name = line[1:]
        else:
            blocks = line.split(" ")[:-1]
            permutations.append(Permutation(ref_id, name, chr_count,
                                list(map(int, blocks))))
            chr_count += 1
    return permutations


#iutputs permutations to stream
def _write_permutations(permutations, out_stream):
    for perm in permutations:
        out_stream.write(">" + perm.chr_id + "\n")
        for block in perm.blocks:
            out_stream.write("{0:+} ".format(block))
        out_stream.write("$\n")

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