[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ micropan  (version  1.0  ) ](/packages/micropan/versions/1.0)

#  distManhattan: Computing Manhattan distances between genomes

##  Description

Computes the (weighted) Manhattan distances beween all pairs of genomes.

##  Usage

    
    
    distManhattan(pan.matrix,scale=0.0,weights=rep(1,dim(pan.matrix)[2]))

##  Arguments

pan.matrix

A ` Panmat ` object, see ` [ panMatrix
](/link/panMatrix?package=micropan&version=1.0) ` for details.

scale

An optional scale to control how copy numbers should affect the distances.

weights

Vector of optional weights of gene clusters.

##  Value

A ` dist ` object (see ` [ dist ](/link/dist?package=micropan&version=1.0) ` )
containing all pairwise Manhattan distances between genomes.

##  Details

The Manhattan distance is defined as the sum of absolute elementwise
differences between two vectors. Each genome is represented as a vector (row)
of integers in  pan.matrix  . The Manhattan distance between two genomes is
the sum of absolute difference between these rows. If two rows (genomes) of
the  pan.matrix  are identical, the corresponding Manhattan distance is  0.0
. The  scale  can be used to control how copy number differences play a role
in the distances computed. Usually we assume that going from 0 to 1 copy of a
gene is the big change of the genome, and going from 1 to 2 (or more) copies
is less. Prior to computing the Manhattan distance, the  pan.matrix  is
transformed according to the following affine mapping: If the original value
in  pan.matrix  is  x  , and  x  is not 0, then the transformed value is  1 +
(x-1)*scale  . Note that with  scale=0.0  (default) this will result in 1
regardless of how large  x  was. In this case the Manhattan distance only
distinguish between presence and absence of gene clusters. If  scale=1.0  the
value  x  is left untransformed. In this case the difference between 1 copy
and 2 copies is just as big as between 1 copy and 0 copies. For any  scale
between 0.0 and 1.0 the transformed value is shrunk towards 1, but a certain
effect of larger copy numbers is still present. In this way you can decide if
the distances between genomes should be affected, and to what degree, by
differences in copy numbers beyond 1. Notice that as long as  scale=0.0  (and
no weighting) the Manhattan distance has a nice interpretation, namely the
number of gene clusters that differ in present/absent status between two
genomes. When summing the difference across gene clusters we can also up- or
downweight some clusters compared to others. The vector  weights  must contain
one value for each column in  pan.matrix  . The default is to use flat
weights, i.e. all clusters count equal. See ` [ geneWeights
](/link/geneWeights?package=micropan&version=1.0) ` for alternative weighting
strategies.

##  See Also

` [ panMatrix ](/link/panMatrix?package=micropan&version=1.0) ` , ` [
distJaccard ](/link/distJaccard?package=micropan&version=1.0) ` , ` [
geneWeights ](/link/geneWeights?package=micropan&version=1.0) ` , ` [ panTree
](/link/panTree?package=micropan&version=1.0) ` .

##  Examples

[ Run this code
](https://www.datacamp.com/datalab/preview?_tag=rdocs&rdocsPath=packages%2Fmicropan%2Fversions%2F1.0%2Ftopics%2FdistManhattan&utm_source=r-docs&utm_medium=docs&utm_term=distManhattan&utm_content=run_example_in_datalab)

    
    
    # Loading two Panmat objects in the micropan package
    data(list=c("Mpneumoniae.blast.panmat","Mpneumoniae.domain.panmat"),package="micropan")
    
    # Manhattan distances based on a BLAST clustering Panmat object
    Mdist.blast <- distManhattan(Mpneumoniae.blast.panmat)
    
    # Manhattan distances based on domain sequence clustering Panmat object
    Mdist.domains <- distManhattan(Mpneumoniae.domain.panmat,scale=0.5)
    

Run the code above in your browser using  [ DataLab
](https: