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/kussell-lab/mcorr
23 January 2022, 09:11:33 UTC
  • Code
  • Branches (5)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/2019natmethods
    • refs/heads/2021biorxiv
    • refs/heads/dev
    • refs/heads/master
    • refs/heads/x
    • 4adea90557f1e592123e073b46a859d879143a2a
    No releases to show
  • e49e01a
  • /
  • cmd
  • /
  • mcorr-bam
  • /
  • codon.go
Raw File Download
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 ...

Permalinks

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 Iframe embedding
swh:1:cnt:f521825ce3a0f1b29d0982a6b6148f2b17f03960
origin badgedirectory badge Iframe embedding
swh:1:dir:5908751cf4f5b1ba6235dac7bf385a94bea30b52
origin badgerevision badge
swh:1:rev:4adea90557f1e592123e073b46a859d879143a2a
origin badgesnapshot badge
swh:1:snp:bc0e5aa6513599be660f007d7b46ba12cce5b7e5
Citations

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
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 ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 4adea90557f1e592123e073b46a859d879143a2a authored by Asher Preska Steinberg on 07 January 2022, 17:44:00 UTC
Fixing go.mod file
Tip revision: 4adea90
codon.go
package main

import (
	"github.com/kussell-lab/ncbiftp/taxonomy"
)

// Codon stores a codon value, the position in a genome and the read id.
type Codon struct {
	Seq     string
	ReadID  string
	GenePos int
}

// ContainsGap return true if '-' in a sequence.
func (c Codon) ContainsGap() bool {
	for _, b := range c.Seq {
		if b == '-' {
			return true
		}
	}
	return false
}

// CodonPile stores a pile of Codon, which are at a particular genome position.
type CodonPile struct {
	genePos  int
	codonMap map[string]Codon
}

// NewCodonPile return a new CodonPile.
func NewCodonPile() *CodonPile {
	return &CodonPile{codonMap: make(map[string]Codon)}
}

// Add appends a new Codon.
func (cp *CodonPile) Add(c Codon) {
	cp.genePos = c.GenePos
	cp.codonMap[c.ReadID] = c
}

// LookUp search a codon by ReadName. If not found, it returns nil.
func (cp *CodonPile) LookUp(readID string) Codon {
	return cp.codonMap[readID]
}

// Len return the lenght of pileup Codons.
func (cp *CodonPile) Len() int {
	return len(cp.codonMap)
}

// GenePos return the gene position.
func (cp *CodonPile) GenePos() int {
	return cp.genePos
}

// CodonGene represents a gene with an array of CodonPile.
type CodonGene struct {
	CodonPiles []*CodonPile
}

// NewCodonGene return a new CodonGene.
func NewCodonGene() *CodonGene {
	return &CodonGene{}
}

// AddCodon add a codon.
func (cg *CodonGene) AddCodon(c Codon) {
	for len(cg.CodonPiles) <= c.GenePos {
		cg.CodonPiles = append(cg.CodonPiles, NewCodonPile())
	}
	cg.CodonPiles[c.GenePos].Add(c)
}

// DepthAt return the pile depth at position i.
func (cg *CodonGene) DepthAt(i int) int {
	if len(cg.CodonPiles) <= i {
		return 0
	}
	return cg.CodonPiles[i].Len()
}

// Len returns length of CodonPile array.
func (cg *CodonGene) Len() int {
	return len(cg.CodonPiles)
}

// CodonPair stores a pair of Codon
type CodonPair struct {
	A, B Codon
}

// PairCodonAt pairs codons at positions i and j.
func (cg *CodonGene) PairCodonAt(i, j int) (pairs []CodonPair) {
	if i >= len(cg.CodonPiles) || j >= len(cg.CodonPiles) {
		return
	}

	if i > j {
		j, i = i, j
	}

	pile1 := cg.CodonPiles[i]
	if i == j {
		for _, codon := range pile1.codonMap {
			pairs = append(pairs, CodonPair{A: codon, B: codon})
		}
	}
	pile2 := cg.CodonPiles[j]
	for readID, codon1 := range pile1.codonMap {
		codon2 := pile2.LookUp(readID)
		if codon2.ReadID != "" {
			pairs = append(pairs, CodonPair{A: codon1, B: codon2})
		}
	}
	return
}

// SynoumousSplitCodonPairs split codon pairs into synoumous pairs.
func SynoumousSplitCodonPairs(codonPairs []CodonPair, codeTable *taxonomy.GeneticCode) [][]CodonPair {
	var splittedPairs [][]CodonPair
	var aaArray []string
	for _, codonPair := range codonPairs {
		hasGap := false
		for _, codon := range []Codon{codonPair.A, codonPair.B} {
			for _, b := range codon.Seq {
				if !isATGC(byte(b)) {
					hasGap = true
					break
				}
			}
			if hasGap {
				break
			}
		}

		if hasGap {
			continue
		}

		a := codeTable.Table[codonPair.A.Seq]
		b := codeTable.Table[codonPair.B.Seq]
		ab := string([]byte{a, b})
		index := -1
		for i, aa := range aaArray {
			if aa == ab {
				index = i
			}
		}
		if index == -1 {
			index = len(aaArray)
			aaArray = append(aaArray, ab)
			splittedPairs = append(splittedPairs, []CodonPair{})
		}
		splittedPairs[index] = append(splittedPairs[index], codonPair)
	}
	return splittedPairs
}

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— Contact— JavaScript license information— Web API

back to top