.\" Copyright (c) 2022 Stijn van Dongen .TH "mcxio" 5 "9 Oct 2022" "mcxio 22-282" "FILE FORMATS " .po 2m .de ZI .\" Zoem Indent/Itemize macro I. .br 'in +\\$1 .nr xa 0 .nr xa -\\$1 .nr xb \\$1 .nr xb -\\w'\\$2' \h'|\\n(xau'\\$2\h'\\n(xbu'\\ .. .de ZJ .br .\" Zoem Indent/Itemize macro II. 'in +\\$1 'in +\\$2 .nr xa 0 .nr xa -\\$2 .nr xa -\\w'\\$3' .nr xb \\$2 \h'|\\n(xau'\\$3\h'\\n(xbu'\\ .. .if n .ll -2m .am SH .ie n .in 4m .el .in 8m .. .SH NAME mcxio \- the format specifications for input and output in \fBmcl-edge\fP .SH DESCRIPTION The easiest format to create graphs from is a line-based format where each lines represents an edge or arc\&. This format is known as the \fILarge Graph Layout\fP, as \fIncol\fP format (in \fIigraph\fP), and as \fIpairwise\fP format in BioLayout\&. In \fBmcl-edge\fP it is additionally referred to as \fIlabel\fP format or \fIabc\fP format\&. In this format each line has two or three fields\&. The first two fields define the source and destination node of an arc\&. Such an arc may be interpreted as a bidirectional edge, depending on the program reading the format\&. The third field is optional\&. If present, it should supply a numerical value that will be used as edge weights\&. By default, edge weights are set to one\&. Several programs in \fBmcl-edge\fP are able to directly use label format\&. For more elaborate workflows it may be useful to utilise one of the native \fBmcl-edge\fP formats that are optimised for interoperability and/or speed\&. The remainder of this manual page documents the format specifications in \fBmcl-edge\fP\&. For hands-on examples of workflows involving both label and other formats it may be useful to have a look at \fBclmprotocols(5)\fP\&. The primary objects in the MCL-edge network analysis suite are graphs and clusterings\&. Graphs can be directed and may have loops\&. Both graphs and clusterings are represented in a general unified format\&. This format specifies two domains (a \fIsource domain\fP and a \fIdestination domain\fP), along with lists of arcs linking pairs of elements from the two domains\&. For graphs the two domains are simply both equal to the graph node domain, whereas for clusterings one domain is the graph node domain and the other corresponds to the enumeration of clusters\&. Undirected graphs are a special instance of a directed graph, where an edge from the undirected graph is represented by two arcs of identical weight, one for each possible direction\&. The general unified format alluded to above is in fact a simple rectangular sparse matrix representation\&. Sparse means that zero entries in the matrix are not stored\&. A zero entry corresponds to an ordered node pair in the graph for which no arc exists from the first to the second node\&. An undirected graph corresponds with a symmetric matrix\&. The MCL suite uses a slight generalisation of the matrix concept, in that the row and column indices (that is, domains) can be arbitrary lists of nonnegative integers\&. Usually, but not necessarily, a domain of size\ \&\fCN\fP will use the common representation of the list of integers starting at\ \&\fC0\fP and ending at \ \&\fCN-1\fP\&. The \fIsource domain\fP is always associated with the columns of a matrix, and the \fIdestination domain\fP is always associated with the rows of a matrix\&. The matrix format, introduced below, first specifies the two domains\&. It then represents the nonzero matrix entries (corresponding with graph arc weights) in a column-wise fashion, as a list of lists\&. For each node from the source domain, it presents the list of all its neighbours in the destination domain along with the corresponding weights\&. This document describes .ZI 2m "\fInative matrix format\fP" \& .br The format that can be read in by any mcl application expecting a matrix argument\&. The native format closely resembles the layout of matrices as residing in computer memory\&. There are two distinct encodings, respectively \fIinterchange\fP and \fIbinary\fP\&. Their relative merits are described further below\&. .in -2m .ZI 2m "\fIconcatenated native matrix format\fP" \& .br This always pertains to matrices in native format concatenated in a single file, referred to as a \fIcat file\fP\&. It is used for example to encode hierarchical clusterings as generated by \fBmclcm\fP\&. A cat file either consists of matrices in interchange format or of matrices in binary format\&. .in -2m .ZI 2m "\fItab format\fP" \& .br Used by applications such as \fBmcl(1)\fP and \fBmcxdump(1)\fP to convert between meaningful labels describing the input data and the numerical identifiers used internally\&. .in -2m .ZI 2m "\fIlabel format\fP" \& .br The format used when streaming labels directly into \fBmcl(1)\fP, various modes of \fBmcx(1)\fP, or \fBmcxload(1)\fP\&. .in -2m .ZI 2m "\fItransformation syntax\fP" \& .br The syntax accepted by \fBmcl(1)\fP, \fBmcxalter(1)\fP and many other programs to transform graphs and matrices\&. .in -2m The interchange format is a portable format that can be transmitted across computers and over networks and will work with any version of mcl or its sibling programs\&. It is documented (here) and very stable\&. Applications can easily create matrices in this format\&. The drawback of interchange format is that for very large graphs matrix encodings grow very big and are slow to read\&. The binary format is \fInot\fP garantueed to be portable across machines or different versions of mcl or differently compiled versions of mcl\&. Its distinct advantage is that for very large graphs the speed advantage over interchange format is dramatic\&. Conversion between the two formats is easily achieved with \fBmcxconvert\fP\&. Both \fBmcl(1)\fP and \fBmcxload(1)\fP can save a matrix in either format after constructing it from label format\&. The concatenated format is generated e\&.g\&. by \fBmclcm(1)\fP and can be transformed by \fBmcxdump(1)\fP using the \fB-imx-cat\fP option\&. In cat format matrices are simply concatenated, so it is easily generated from the command line if needed\&. For native binary format it is imperative that no additional bytes are inserted inbetween the matrix encodings\&. For native interchange format the only requirement is that the last matrix is followed by nothing but white space\&. A remark on the sloppy naming conventions used for \fBmcl\fP and its sibling utilities may be in order here\&. The prefix \fBmcx\fP is used for generic matrix functionality, the prefix \fBclm\fP is used for generic cluster functionaliy\&. The \fIutility\fP \fBmcx\fP is a general purpose interpreter for manipulating matrices (and grahps, sets, and clusterings)\&. The set of all \fBmcl\fP siblings (cf\&. \fBmclfamily(7)\fP) is loosely referred to as the mcl family, which makes use of the mcl libraries (rather than the mcx libraries)\&. The full truth is even more horrible, as the mcl/mcx prefix conventions used in the C source code follow still other rules\&. In this document, \&'MCL\&' means \&'the mcl setting\&' or \&'the mcl family\&'\&. An MCL program is one of the programs in the mcl family\&. The remainder of this document contains the following sections\&. .SH Internal representation of matrices in MCL There are several aspects to the way in which MCL represents matrices\&. Internally, indices never act as an ofset in an array, and neither do they participate in ofset computations\&. This means that they purely act as identifiers\&. The upshot is that matrices can be handled in which the index domains are \fInon-sequential\fP (more below)\&. Thus one can work with different graphs and matrices all using subsets of the same set of indices/identifiers\&. This aids in combining data sets in different ways and easily comparing the respective results when experimenting\&. Secondly, only \fInonzero values\fP (and their corresponding indices) are stored\&. Thirdly, MCL stores a matrix as a listing of columns\&. Iterating over a column is trivial; iterating over a row requires a costly transposition computation\&. The last two points should matter little to the user of MCL programs\&. In textbook expositions and in many matrix manipulation implementations, matrices are represented with sequentially indexed rows and columns, with the indices usually starting at either zero or one\&. In the MCL setting, the requirement of sequentiality is dropped, and it follows naturally that no requirement is posed on the first index\&. The only requirement MCL poses on the indices is that they be nonnegative, and can be represented by the integer type used by MCL\&. On many machines, the largest allowable integer will be 2147483647\&. MCL associates two domains with a matrix\ \&\fCM\fP, the row domain and column domain\&. The matrix\ \&\fCM\fP can only have entries\ \&\fCM[i,j]\fP where\ \&\fCi\fP is in the row domain and\ \&\fCj\fP is in the column domain\&. This is vital when specifying a matrix: it is illegal to specify an entry\ \&\fCM[i,j]\fP violating this condition\&. However, it is not necessary to specify \fIall\fP entries\ \&\fCM[i,j]\fP for all possible combinations of\ \&\fCi\fP and\ \&\fCj\fP\&. One needs only specify those entries for which the value is nonzero, and only nonzero values will be stored internally\&. In the MCL matrix format, the matrix domains must be specified explicitly if they are not canonical (more below)\&. \fBStrictly as an aside\fP, the domains primarily exist to ensure data integrity\&. When combining matrices with addition or multiplication (e\&.g\&. using the \fBmcx\fP utility), MCL will happily combine matrices for which the domains do not match, although it will usually issue a warning\&. Conceptually, matrices auto-expand to the dimensions required for the operation\&. Alternatively, a matrix can be viewed as an infinite quadrant, with the domains delimiting the parts in which nonzero entries may exist\&. In the future, facilities could be added to MCL (c\&.q\&. \fBmcx\fP) to allow for placing strict domain requirements on matrices when submitted to binary operations such as addition and multiplication\&. .SH Specifying matrices From here on, all statements about matrices and graphs are really statements about matrices and graphs \fIin the MCL setting\fP\&. The \fIspecification\fP of a matrix quite closely matches the internal representation\&. A matrix M has two domains: the column domain and the row domain\&. Both simply take the form of a set (represented as an ordered list) of indices\&. A \fIcanonical domain\fP is a domain of some size \fCK\fP where the indices are simply the first \fCK\fP nonnegative integers \fC0,1\&.\&.,K-1\fP\&. The domains dictate which nonzero entries are allowed to occur in a matrix; only entries M[i,j] are allowed where i is in the row domain and j is in the column domain\&. The matrix M is specified in three parts, for which the second is optional\&. The parts are: .ZI 2m "Header specification" \& .br This specifies the dimensions K and L of the matrix, where K is the size of the row domain, and L is the size of the column domain\&. It looks as follows: .nf \fC (mclheader mcltype matrix dimensions 9x14 ) .fi \fR This dictates that a matrix will be specified for which the row domain has dimension 9 and the column domain has dimension 14\&. .in -2m .ZI 2m "Domain specification" \& .br The domain specification can have various forms: if nothing is specified, the matrix will have canonical domains and a canonical representation, similar to the representation encountered in textbooks\&. Alternatively, the row and column domains can each be specified separately, and it is also possible to specify only one of them; the other will simply be a canonical domain again\&. Finally, it is possible to declare the two domains identical and specify them simultaneously\&. It is perfectly legal in each case to explicitly specify a canonical domain\&. It is \fIrequired\fP in each case that the number of indices listed in a domain corresponds with the dimension given in the header\&. An example where both a row domain and a column domain are specified: .nf \fC (mclrows 100 200 300 400 500 600 700 800 900 $ ) (mclcols 30 32 34 36 38 40 42 44 46 48 50 52 56 58 $ ) .fi \fR This example combines with the header given above, as the dimensions fit\&. Had the row domain specification been omitted, the row domain would automatically be set to the integers \fC0,1,\&.\&.8\fP\&. Had the column specification been omitted, it would be set to \fC0,1,\&.\&.13\fP\&. Suppose now that the header did specify the dimensions 10x10\&. Because the dimensions are identical, this raises the possibility that the domains be identical\&. A valid way to specify the row domain and column domain in one go is this\&. .nf \fC (mcldoms 11 22 33 44 55 66 77 88 99 100 $ ) .fi \fR .in -2m .ZI 2m "Matrix specification" \& .br The matrix specification starts with the sequence .nf \fC (mclmatrix begin .fi \fR The \&'begin\&' keyword in the \&'(mclmatrix\&' part is followed by a list of listings, where the primary list ranges over all column indices in M (i\&.e\&. indices in the column domain), and where each secondary lists encodes all positive entries in the corresponding column\&. A secondary list (or matrix column) starts with the index c of the column, and then contains a listing of all row entries in c (these are matrix entries M[r,c] for varying r)\&. The entry M[r,c] is specified either as \&'r\&' or as \&'r:f\&', where f is a float\&. In the first case, the entry M[r,c] defaults to 1\&.0, in the second case, it is set to f\&. The secondary list is closed with the \&`$\&' character\&. A full fledged examples thus looks as follows: .nf \fC (mclheader mcltype matrix dimensions 12x3 ) (mclrows 11 22 33 44 55 66 77 88 99 123 456 2147483647 $ ) (mclcols 0 1 2 $ ) (mclmatrix begin 0 44 88 99 456 2147483647 $ 1 11 66 77 123 $ 2 22 33 55 $ ) .fi \fR Note that the column domain is canonical; its specifiation could have been omitted\&. In this example, no values were specified\&. See below for more\&. .in -2m .SH Specifying graphs A graph is simply a matrix where the row domain is the same as the column domain\&. Graphs should have positive entries only\&. Example: .nf \fC (mclheader mcltype matrix dimensions 12x12 ) (mcldoms 11 22 33 44 55 66 77 88 99 123 456 2147483647 $ ) (mclmatrix begin 11 22:2 66:3\&.4 77:3 123:8 $ 22 11:2 33:3\&.8 55:8\&.1 $ 33 22:3\&.8 44:7 55:6\&.2 $ 44 33:7 88:5\&.7 99:7\&.0 456:3 $ 55 22:8\&.1 33:6\&.2 77:2\&.9 88:3\&.0 $ 66 11:3\&.4 123:5\&.1 $ 77 11:3 55:2\&.9 123:1\&.5 $ 88 44:5\&.7 55:3\&.0 99:3\&.0 456:4\&.2 $ 99 44:7\&.0 88:3\&.0 456:1\&.8 2147483647:3\&.9 $ 123 11:8 66:5\&.1 77:1\&.5 $ 456 44:3 88:4\&.2 99:1\&.8 2147483647:6\&.3 $ 2147483647 99:3\&.9 456:6\&.3 $ ) .fi \fR Incidentally, clustering this graph with mcl, using default parameters, yields a cluster that is represented by the 12x3 matrix shown earlier\&. The following example shows the same graph, now represented on a canonical domain, and with all values implicitly set to 1\&.0: .nf \fC (mclheader mcltype matrix dimensions 12x12 ) (mclmatrix begin 0 1 5 6 9 $ 1 0 2 4 $ 2 1 3 4 $ 3 2 7 8 10 $ 4 1 2 6 7 $ 5 0 9 $ 6 0 4 9 $ 7 3 4 8 10 $ 8 3 7 10 11 $ 9 0 5 6 $ 10 3 7 8 11 $ 11 8 10 $ ) .fi \fR \fBAdditional notes\fP .br There are few restrictions on the format that one might actually expect\&. Vectors and entries may occur in any order and need not be sorted\&. Repeated entries and repeated vectors are allowed but are always discarded while an error message is emitted\&. If you want \fIfunctionally interesting behaviour\fP in combining repeated vectors and repeated entries, have a look at the next section and at \fBmcxassemble(1)\fP\&. Within the vector listing, the \&'#\&' is a token that introduces a comment until the end of line\&. .SH Raw format A file in \fIraw format\fP is simply a listing of vectors without any sectioning structure\&. No header specification, no domain specification, and no matrix introduction syntax is used - these are supplied to the processing application by other means\&. The end-of-vector token \&'$\&' must still be used, and the comment token \&'#\&' is still valid\&. \fBmcxassemble(1)\fP imports a file in raw format, creates a native matrix from the data therein, and writes the matrix to (a different) file\&. It allows customizable behaviour in how to combine repeated entries and repeated vectors\&. This is typically used in the following procedure\&. A) Do a one-pass-parse on some external cooccurrence file/format, generate raw data during the parse and write it to file (without needing to build a huge data structure in memory)\&. B) mcxassemble takes the raw data and assembles it according to instruction into a native mcl matrix\&. .SH Tab format / label information Several mcl programs accept options such as \fB-tab\fP, \fB-tabc\fP, \fB-tabr\fP, \fB-use-tab\fP, \fB-strict-tab\fP, and \fB-extend-tab\fP\&. The argument to these options is invariably the name of a so-called \fItab file\fP\&. Tab files are used to convert between labels (describing entities in the data) and indices as used in the mcl matrix format\&. In a tab file each line starts with a unique number which presumably corresponds to an index used in a matrix file\&. The rest of the line contains a descriptive string associated with the number\&. It is required that each string is unique, although not all mcl programs enforce this at the time of writing\&. The string may contain spaces\&. Lines starting with \fC#\fP are considered comment and are disregarded\&. \fBTab domain\fP .br The ordered set of indices found in the tab file is called the \fItab domain\fP\&. Tab files are almost always employed in conjunction with an mcl matrix file\&. \fBmcxdump(1)\fP requires by default that the tab domain coincides with the matrix domain (either row or column or both) to which they will be applied\&. This can be relaxed by supplying the \fB--lazy-tab\fP option\&. mcl provides explicit modes for dealing with tab structures by means of the \fB-extend-tab\fP, \fB-restrict-tab\fP and \fB-strict-tab\fP options\&. Refer to the \fBmcl(1)\fP documentation\&. .SH Label format Label format is a line based input where two nodes and an optional value are specified on each line\&. The nodes should be specified by labels\&. If the labels contain spaces they should be separated by tabs (and the value if present should be separated from the second label by a tab as well)\&. The parse code will assume tab-separated labels if it sees a tab character in the input, otherwise it will split the input on any kind of whitespace\&. Any line where the first non-whitespace character is the octothorp (#) is ignored\&. The following is an example of label format\&. .di ZV .in 0 .nf \fC ---8<------8<------8<------8<------8<--- # the cat and the hat example cat hat 0\&.2 hat bat 0\&.16 bat cat 1\&.0 bat bit 0\&.125 bit fit 0\&.25 fit hit 0\&.5 hit bit 0\&.16 --->8------>8------>8------>8------>8--- .fi \fR .in .di .ne \n(dnu .nf \fC .ZV .fi \fR \fBmcl(1)\fP can read in label format and cluster it when it is given the \fB--abc\fP option\&. It can optionally save the input graph in native format and save the label information in a tab file with the \fB-save-graph\fP and \fB-save-tab\fP options\&. Refer to the \fBMCL getting started\fP and \fBMCL manual examples\fP sections for more information on how MCL deals with label format\&. \fBmcxload(1)\fP is a general purpose program for reading in label data and other stream formats\&. It encodes them in native mcl format and tab files\&. It allows intermediate transformations on the values\&. .SH Transformation syntax \fBmcl(1)\fP, \fBmcxload(1)\fP, \fBmcxsubs(1)\fP, \fBmcxassemble(1)\fP and \fBmcxalter(1)\fP all accept the same transformation language in their respective \fBtf\fP-type options and mcxsub\&'s \fBval\fP specification\&. A statement in this language is simply a comma-separated list of functions accepting a single numerical value\&. The syntax of a function invocation in general is \fBfunc\fP(\fIarg\fP)\&. The functions \fBexp\fP, \fBlog\fP, \fBneglog\fP can also be given an empty parameter list, indicating that \fIe\fP is taken as the exponent base\&. In this case, the invocation looks like \fBfunc\fP()\&. Functions with names that start with \fC#\fP operate on graphs in their entirety\&. For example, \fC#knn(50)\fP indicates the k-Nearest Neighbour transformation for \fCk=50\fP\&. All other names encode functions that operate directly on edges\&. Functions with names that start with \fC#arc\fP operate on directed graphs and yield directed graphs\&. Most of the other \fC#\fP functions either expect an undirected graph (such as \fC#knn()\fP) or yield an undirected graph (such as \fC#add()\fP and \fC#max()\fP\&. The following are supported\&. .ZI 12m "lt" Filter out values greater than or equal to arg\&. .in -12m .ZI 12m "lq" Filter out values greater than arg\&. .in -12m .ZI 12m "gq" Filter out values less than arg\&. .in -12m .ZI 12m "gt" Filter out values less than or equal to arg\&. .in -12m .ZI 12m "ceil" Set everything higher than arg to arg\&. .in -12m .ZI 12m "floor" Set everything lower than arg to arg\&. .in -12m .ZI 12m "mul" Multiply values by arg\&. .in -12m .ZI 12m "add" Add arg to values\&. .in -12m .ZI 12m "power" Raise values to power arg\&. .in -12m .ZI 12m "exp" Raise arg (\fIe\fP if omitted) to value\&. .in -12m .ZI 12m "log" Take log in base arg (\fIe\fP if omitted)\&. .in -12m .ZI 12m "neglog" Take minus log in base arg (\fIe\fP if omitted)\&. .in -12m .ZI 12m "rand" Keep arc with probablity arg\&. .in -12m .ZI 12m "scale" Divide values by arg\&. .in -12m .ZI 12m "abs" Replace value by its absolute value\&. .in -12m .ZI 12m "acos" Take acos of value\&. .in -12m .ZI 12m "#knn" k-Nearest Neighbour reduction with \fCk=arg\fP (intersect lists)\&. .in -12m .ZI 12m "#knnj" As \fC#knn\fP above, but join selected neighbour lists\&. .in -12m .ZI 12m "#ceilnb" Cap number of neighbours at arg at most\&. .in -12m .ZI 12m "#ils" Inverted log-weight similarity (no argument)\&. .in -12m .ZI 12m "#mcl" Cluster with inflation=arg, yields induced graph\&. .in -12m .ZI 12m "#add" Convert two arcs to one edge using addition\&. .in -12m .ZI 12m "#min" Convert two arcs to one edge using minimum\&. .in -12m .ZI 12m "#max" Convert two arcs to one edge using maximum\&. .in -12m .ZI 12m "#mul" Convert two arcs to one edge using multiplication\&. .in -12m .ZI 12m "#rev" Encode graph in reverse direction\&. .in -12m .ZI 12m "#tp" Same as above in matrix speak (\fIt\fPrans\fIp\fPose)\&. .in -12m .ZI 12m "#selfrm" Remove loops\&. .in -12m .ZI 12m "#selfmax" Set loop value to maximum value\&. .in -12m .ZI 12m "#tug" Perturb edge weights with factor arg\&. .in -12m .ZI 12m "#shrug" Randomly perturb edge weights with factor arg\&. .in -12m .ZI 12m "#step" Use the k-step relation, where \fCk=arg\fP\&. .in -12m .ZI 12m "#thread" Set thread pool size to arg\&. .in -12m .ZI 12m "#arcmax" Only keep largest arc between two nodes\&. .in -12m .ZI 12m "#arcsub" Replace G by G - G^T\&. .in -12m .ZI 12m "#symmcl" As \fC#mcl\fP, use symmetrised graph for clustering\&. .in -12m \fBNOTE\fP .br \fBmcl(1)\fP accepts \fB--abc-neg-log\fP and \fB--abc-neg-log10\fP to specify log transformations\&. Similarly, \fBmcxload(1)\fP accepts \fB--stream-log\fP, \fB--stream-neg-log\fP, and \fB--stream-neg-log10\fP\&. The reason is that probabilities are sometimes encoded below the precision dictated by the IEEE (32 bit) float specification\&. This poses a problem as the mcl applications encode values by default as floats, and the transformation specifications are always applied to the mcl encoding\&. The options just mentioned are applied after a value has been read from an input stream and \fIbefore\fP it is converted to the native encoding\&. .SH SEE ALSO \fBmcxassemble(1)\fP, and \fBmclfamily(7)\fP for an overview of all the documentation and the utilities in the mcl family\&. .SH AUTHOR Stijn van Dongen\&.