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
22 June 2021, 01:27:41 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
  • eb905b6
  • /
  • scripts
  • /
  • split_blocks.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:5755caa2a288cbae2eda8f8f0b701af2d3367f93
origin badgedirectory badge
swh:1:dir:764b779386231c33cc22c428cab1840bb329b5ec
origin badgerevision badge
swh:1:rev:54ec8318ee615f6aa28b3188cfd95ee5679cc317
origin badgesnapshot badge
swh:1:snp:049c406b15a9a28e76d942bfc1fe2a04f4142f61

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: 54ec8318ee615f6aa28b3188cfd95ee5679cc317 authored by fenderglass on 15 January 2014, 22:20:24 UTC
sibelia path fix
Tip revision: 54ec831
split_blocks.py
#!/usr/bin/env python

from Bio import SeqIO
from Bio.SeqRecord import SeqRecord
from collections import namedtuple
import sys, os
SyntenyBlock = namedtuple("SyntenyBlock", ["seq", "chr_id", "strand", "id", "start", "end", "chr_num"])
SeqInfo = namedtuple("SeqInfo", ["id", "length"])


def parse_coords_file(blocks_file):
    group = [[]]
    seq_info = {}
    blocks_info = {}
    line = [l.strip() for l in open(blocks_file) if l.strip()]
    for l in line:
        if l.startswith("-"):
            group.append([])
        else:
            group[-1].append(l)
    for l in group[0][1:]:
        seq_num, seq_len, seq_id = l.split()
        seq_num = int(seq_num)
        seq_info[seq_num] = SeqInfo(seq_id, int(seq_len))
    for g in [g for g in group[1:] if g]:
        block_id = int(g[0].split()[1][1:])
        blocks_info[block_id] = []
        for l in g[2:]:
            chr_num, bl_strand, bl_start, bl_end, bl_length = l.split()
            chr_num = int(chr_num)
            chr_id = seq_info[chr_num].id
            blocks_info[block_id].append(SyntenyBlock(seq="", chr_id=chr_id,
                                        strand=bl_strand, id=block_id,
                                        start=int(bl_start), end=int(bl_end),
                                        chr_num=int(chr_num)))
    return (blocks_info, seq_info)


def check_block(ngenomes, block_list):
    MIN = 2000
    MAX = 5000
    #ids = map(lambda x: x.chr_id, block_list)
    if check_unique(block_list) and len(block_list) == ngenomes:
        length = abs(block_list[0].start - block_list[0].end)
        if MIN <= length <= MAX:
            return True
    return False


def check_unique(block_list):
    ids = map(lambda x: x.chr_id, block_list)
    return len(ids) == len(set(ids))


def main(blocks_file, genomes):
    blocks, seq_info = parse_coords_file(blocks_file)
    seqs = {}
    out_files = {}
    id_to_name = {}
    for genome in genomes:
        seq = SeqIO.parse(genome, "fasta").next()
        seqs[seq.id] = seq.seq
        filename = genome[0:genome.rfind(".")] + "_blocks.fasta"
        out_files[seq.id] = open(filename, "w")
        id_to_name[seq.id] = os.path.basename(genome)

    for block_id, block_list in blocks.iteritems():
        #if len(block_list) != len(genomes):
        #    continue
        if not check_unique(block_list):
            continue

        """
        if check_block(len(genomes), block_list):
            out_block = open("block_" + str(block_id) + ".fasta", "w")
            for block in block_list:
                if block.strand == "+":
                    block_seq = seqs[block.chr_id][block.start : block.end + 1]
                else:
                    block_seq = seqs[block.chr_id][block.end : block.start + 1]

                name = id_to_name[block.chr_id]
                SeqIO.write(SeqRecord(seq=block_seq, id=name, description=""), out_block, "fasta")
        """

        for block in block_list:
            name = ""
            if block.strand == "+":
                block_seq = seqs[block.chr_id][block.start : block.end + 1]
            else:
                block_seq = seqs[block.chr_id][block.end : block.start + 1]

            block_name = "{0}_block_{1}".format(block.chr_id, block_id)
            SeqIO.write(SeqRecord(seq=block_seq, id=block_name, description=""), out_files[block.chr_id], "fasta")

if __name__ == "__main__":
    main(sys.argv[1], sys.argv[2:])

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