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/vejnar/GeneAbacus
20 February 2026, 23:11:59 UTC
  • Code
  • Branches (1)
  • Releases (6)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/main
    • v0.2.2
    • v0.2.1
    • v0.2.0
    • v0.1.2
    • v0.1.1
    • v0.1
  • b878b8a
  • /
  • lib
  • /
  • esam
  • /
  • align.go
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
  • release
origin badgecontent badge
swh:1:cnt:3b4333f985207b36f39842bf071fc0f2c27de0ab
origin badgedirectory badge
swh:1:dir:39d35e446a20a2386f6e24f0a39c279d9149e531
origin badgerevision badge
swh:1:rev:abea966ebc8d4fc7fee5cd87db27828e38bb9dec
origin badgesnapshot badge
swh:1:snp:c9ab8ea277d970770721ef06ce2eff7a73c0e990
origin badgerelease badge
swh:1:rel:9cddf9b46c4d3b1c2c8fec7685f447127cadca4b

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
  • release
(requires biblatex-software package)
Generating citation ...
(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: abea966ebc8d4fc7fee5cd87db27828e38bb9dec authored by vejnar on 12 August 2022, 03:00:06 UTC
Fix source in CI
Tip revision: abea966
align.go
//
// Copyright (C) 2015-2022 Charles E. Vejnar
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://www.mozilla.org/MPL/2.0/.
//

package esam

import (
	"bytes"
	"strconv"
	"unicode"

	"github.com/biogo/hts/sam"
)

const (
	MDInsertion = iota
	MDMismatch
	MDSkip
)

type TagMDOp struct {
	Op     int
	Length int
	Seq    []byte
}

// ParseTagMD parses the MD attribute to blocks.
func ParseTagMD(rawTag string) (blocks []TagMDOp, err error) {
	var block []byte
	var l byte
	// Parsing tag
	i := 0
	for i < len(rawTag) {
		l = rawTag[i]
		if l == '^' {
			block = []byte("")
			i++ // Skipping "^"
			l = rawTag[i]
			for i < len(rawTag) {
				l = rawTag[i]
				if unicode.IsLetter(rune(l)) {
					block = append(block, l)
					i++
				} else {
					break
				}
			}
			blocks = append(blocks, TagMDOp{Op: MDInsertion, Length: len(block), Seq: block})
		} else if unicode.IsLetter(rune(l)) {
			blocks = append(blocks, TagMDOp{Op: MDMismatch, Length: 1, Seq: []byte{l}})
			i++
		} else {
			block = []byte("")
			for i < len(rawTag) {
				l = rawTag[i]
				if unicode.IsNumber(rune(l)) {
					block = append(block, l)
					i++
				} else {
					break
				}
			}
			step, err := strconv.Atoi(string(block))
			if err != nil {
				return blocks, nil
			}
			blocks = append(blocks, TagMDOp{Op: MDSkip, Length: step})
		}
	}
	return blocks, nil
}

// GetAln reconstitutes read alignment based on cigar string. The MD tag is used if present.
func GetAln(r *sam.Record) (ref, read, symbol []byte, err error) {
	// Parsing CIGAR string
	var iRead, length int
	var co sam.CigarOp
	var con sam.Consume
	seq := r.Seq.Expand()
	for i := 0; i < len(r.Cigar); i++ {
		co = r.Cigar[i]
		con = co.Type().Consumes()
		length = co.Len()
		if con.Query == 1 && con.Reference == 1 {
			ref = append(ref, seq[iRead:iRead+length]...)
			read = append(read, seq[iRead:iRead+length]...)
			if co.Type() == sam.CigarMatch {
				symbol = append(symbol, bytes.Repeat([]byte("|"), length)...)
			} else {
				symbol = append(symbol, bytes.Repeat([]byte("X"), length)...)
			}
			iRead += length
		} else if con.Query == 0 && con.Reference == 1 {
			ref = append(ref, bytes.Repeat([]byte("N"), length)...)
			read = append(read, bytes.Repeat([]byte("-"), length)...)
			symbol = append(symbol, bytes.Repeat([]byte("."), length)...)
		} else if con.Query == 1 && con.Reference == 0 {
			if co.Type() == sam.CigarInsertion {
				ref = append(ref, bytes.Repeat([]byte("-"), length)...)
				symbol = append(symbol, bytes.Repeat([]byte("."), length)...)
			} else {
				ref = append(ref, bytes.Repeat([]byte(" "), length)...)
				symbol = append(symbol, bytes.Repeat([]byte(" "), length)...)
			}
			read = append(read, seq[iRead:iRead+length]...)
			iRead += length
		}
	}
	// Parsing MD tag if present
	tag, found := r.Tag([]byte("MD"))
	if found {
		var blocks []TagMDOp
		blocks, err = ParseTagMD(tag.Value().(string))
		if err != nil {
			return
		}
		var iRef, iBlock int
		for _, b := range blocks {
			for iRef < len(ref) && (ref[iRef] == '-' || ref[iRef] == ' ') {
				iRef++
			}
			switch b.Op {
			case MDInsertion:
				for _, nt := range b.Seq {
					ref[iRef] = nt
					iRef++
				}
			case MDMismatch:
				ref[iRef] = b.Seq[0]
				symbol[iRef] = 'X'
				iRef++
			case MDSkip:
				iBlock = 0
				for iBlock < b.Length {
					if ref[iRef] != '-' && ref[iRef] != ' ' && symbol[iRef] != '.' {
						iBlock++
					}
					iRef++
				}
			}
		}
	}
	return
}

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