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

  • 864fd35
  • /
  • cmd
  • /
  • mcorr-xmfa
  • /
  • noncoding_calculator.go
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.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:bf52ca4ebcc44868ec902b9ab43580d0298ca6c2
directory badge Iframe embedding
swh:1:dir:2bef742783df8312583d465c527370dfc4e25e9d

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
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
noncoding_calculator.go
package main

import (
	"github.com/apsteinberg/biogo/seq"
	"github.com/apsteinberg/mcorr"
)

// NoncodingCalculator for calculating noncoding sequences.
type NoncodingCalculator struct {
	MaxLen int
}

// NewNoncodingCalculator return a NoncodingCalculator
func NewNoncodingCalculator(maxLen int) *NoncodingCalculator {
	return &NoncodingCalculator{
		MaxLen: maxLen,
	}
}

// CalcP2 calculate P2
func (cc *NoncodingCalculator) CalcP2(alignment []seq.Sequence, others ...[]seq.Sequence) (results []mcorr.CorrResult) {
	return calcP2Noncoding(alignment, cc.MaxLen)
}

func calcP2Noncoding(aln []seq.Sequence, maxLen int) (results []mcorr.CorrResult) {
	for l := 0; l < maxLen; l++ {
		totalxy := 0.0
		totaln := 0
		for i := 0; i+l < len(aln[0].Seq); i++ {
			j := i + l
			basePairs := [][]byte{}
			for _, s := range aln {
				basePairs = append(basePairs, []byte{s.Seq[i], s.Seq[j]})
			}

			nc := doubleCounts(basePairs)
			xy, n := nc.P11(0)
			totalxy += xy
			totaln += n
		}
		if totaln > 0 {
			res := mcorr.CorrResult{
				Lag:  l,
				Mean: totalxy / float64(totaln),
				N:    totaln,
				Type: "P2"}
			results = append(results, res)
		}
	}

	return
}

func doubleCounts(basePairs [][]byte) *mcorr.NuclCov {
	alphabet := []byte{'A', 'T', 'G', 'C'}
	c := mcorr.NewNuclCov(alphabet)
	for _, basePair := range basePairs {
		a := basePair[0]
		b := basePair[1]
		if isATGC(a) && isATGC(b) {
			c.Add(a, b)
		}
	}
	return c
}

// ATGC is DNA alphabet.
const ATGC = "ATGC"
const atgc = "atgc"

func isATGC(b byte) bool {
	yes := false
	for i := 0; i < len(ATGC); i++ {
		if b == ATGC[i] {
			yes = true
			break
		}
	}
	return yes
}

back to top

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