|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdata.networks.ProteinNetwork
public class ProteinNetwork
Represents a network of binary protein interactions. For each edge an edge weight as well as edge annotations as key/value pairs can be stored. This class is one of the central objects in this library and provides high- performance accession and manipulation methods. Below you find some basic information and examples for these networks:
Edges in the network
There are two possibilities on how to create an edge between two proteins
in the network. (1) You can assign a numeric weight to the edge using setEdge(int, int, float)
. This weight is used by all scoring functions
delivered with this library. (2) Alternativly you can assign a set of
key/value pairs to an edge which allows you to store virtually any kind of
information for an edge.
Notes:
Undirected and directed networks
By default networks are undirected, but can can create directed networks
using the constructor ProteinNetwork(boolean)
. For undirected
networks the edges (a,b)
and (b,a)
are identical and only
stored once.
The directedness of a network affects different functionalities, e.g. neighbor detection or network searching. Further information are provided with the documentations of the functions.
Iterating over networks
There are different ways of iterating over all edges of a network.
Basically the different methods provide different convenience/efficency
tradeoffs. For the examples below we assume that there is an existing
network object called net
.
iterator()
function:
for (NetworkEdge edge : net) { // do something with 'edge' }Note: This method is very easy to use but for each edge a
NetworkEdge
object has to be created which might lead to efficiency
problems for large networks.
getEdgesAsPairs()
which returns a list of all proteins in the network
which share an edge. You will have to query for weights and annotations
yourself:for (ProteinPair pair : net.getInteractingPairs()) { float weight = net.getEdge(pair.getProtein1(), pair.getProtein2()); // if not Float.isNaN(weight): there is a weight associated with this edge Mapannotations = net.getAnnotations(pair.getProtein1(), pair.getProtein2()); // if annotations.size() > 0: there are annotations associated with this edge }
getEdgesArray()
. It returns an array which alternatingly contains
both partners of each edge:
int[] edges = net.getEdgesArray(); for (int i=0; i<edges.length; i+=2) { int protein1 = edges[i]; int protein2 = edges[i+1]; // protein1 and protein2 have an edge }
Constructor Summary | |
---|---|
ProteinNetwork()
Creates an empty undirected network. |
|
ProteinNetwork(boolean directed)
Creates an empty network. |
Method Summary | |
---|---|
void |
breadthFirstSearch(int start,
NetworkSearchCallback callback)
Performs a breadth-first search one the network. |
ProteinNetwork |
combineWith(ProteinNetwork other,
CombinationRules rules)
Combines two network using a given combination rules . |
ProteinNetwork |
copy()
Create a copy of the network. |
boolean |
deleteEdge(int prot1,
int prot2)
Deletes an edge from the network along with all of its annotations. |
void |
depthFirstSearch(int start,
NetworkSearchCallback callback)
Performs a depth-first search one the network. |
PurificationData |
derivePurificationData(boolean poolBaits)
Creates a purification data object from a directed network. |
boolean |
equals(Object obj)
Returns true if and only if obj is also of type ProteinNetwork, both network have the same directedness and all edge weights and annotations of the networks are identical |
boolean |
equalScores(ProteinNetwork compare)
Checks whether two networks are equal regardings their edge weights |
Set<String> |
getAnnotationKeys()
Returns a set of all distinct annotation keys used in the network. |
ProteinNetwork |
getCutOffNetwork(float cutOff)
Returns a network containing only edges with a weight greater or equal than a given cutoff value. |
ProteinNetwork |
getCutOffNetwork(float cutOff,
boolean cutBelow)
Returns a network containing only edges with a weight above or below a given cutoff value. |
Collection<NetworkEdge> |
getDirectedNeighbors(int protein,
boolean fromProtein)
Returns all incident edges of a given direction from a directed network. |
float |
getEdge(int prot1,
int prot2)
Returns the weight of an edge between two given proteins. |
Object |
getEdgeAnnotation(int prot1,
int prot2,
String key)
Retrieves an annotation from a given edge. |
Map<String,Object> |
getEdgeAnnotations(int prot1,
int prot2)
Returns all annotations associated with a given edge. |
int |
getEdgeCount()
Returns the number of edges in this network. |
int[] |
getEdgesArray()
Returns an array containing all edges of the network. |
Collection<ProteinPair> |
getEdgesAsPairs()
Returns a list of all proteins in the network which have and edge. |
ProteinNetwork |
getFilteredNetwork(BooleanExpression statement)
Filters the network using a given boolean expression. |
int[] |
getNeighborArray(int protein)
Returns an array of proteins which contains all neighbors in the network of a given protein. |
Collection<NetworkEdge> |
getNeighbors(int protein)
Returns all incident edges for a given protein in the network. |
int |
getNodeCount()
Returns the number of nodes in this network. |
Set<Integer> |
getNodes()
Get list of proteins in this network. |
Set<Integer> |
getProteins()
Returns the set of proteins which are contained as nodes in this network |
boolean |
hasEdge(int prot1,
int prot2)
Checks whether there is an edge in the network between two given proteins. |
boolean |
isDirected()
Returns if the network is a directed network |
Iterator<NetworkEdge> |
iterator()
Returns an iterator over all edges of the network. |
static void |
main(String[] args)
|
ProteinNetwork |
randomizeByRewiring()
Randomizes a network by rewiring. |
ProteinNetwork |
randomizeByRewiring(int rewirings)
Randomizes a network by rewiring. |
ProteinNetwork |
restrictToProteins(ProteinSet proteins,
boolean fullCoverage)
Returns a new network object which contains only those edges where one or both adjacent proteins are contained in a given set of proteins. |
ProteinNetwork |
restrictToProteins(Set<Integer> proteinIDs,
boolean fullCoverage)
Returns a new network object which contains only those edges where one or both adjacent proteins are contained in a given set of proteins. |
void |
scalarMultiplication(float factor)
Multiplies all existing edge weights of the network with a given value. |
void |
setEdge(int prot1,
int prot2)
Sets an edge between two given proteins to a standard weight of 1.0. |
void |
setEdge(int prot1,
int prot2,
float weight)
Sets a weighted edge between two given proteins. |
void |
setEdgeAnnotation(int prot1,
int prot2,
String key,
Object value)
Labels an edge between two proteins with a given key/value pair. |
void |
setEdgeAnnotations(int prot1,
int prot2,
Map<String,Object> annotations)
Labels an edge in the network with a given set of annotations. |
void |
setFullEdge(NetworkEdge edge)
Takes an existing NetworkEdge object and inserts the edge
into this network. |
void |
setIterateEdgesTwice(boolean iterateTwice)
For undirected networks this function determines the iterator behaviour. |
ProteinNetwork |
undirectedCopy()
Create an explicitly undirected copy of the network. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ProteinNetwork()
public ProteinNetwork(boolean directed)
directed
- specifies if this will be a directed or an undirected networkMethod Detail |
---|
public boolean hasEdge(int prot1, int prot2)
prot1
- first proteinprot2
- second protein
true
if there is an edge between the two proteinspublic float getEdge(int prot1, int prot2)
Float.NaN
prot1
- first proteinprot2
- second protein
Float.NaN
if no weighted edge
exists between those proteins in the networkpublic void setEdge(int prot1, int prot2, float weight) throws ProCopeException
prot1
- first proteinprot2
- second proteinweight
- weight to assign to the edge
ProCopeException
- if weight == Float.NaN
public void setFullEdge(NetworkEdge edge)
NetworkEdge
object and inserts the edge
into this network.
edge
- network edge to be insertedpublic void setEdge(int prot1, int prot2)
prot1
- first proteinprot2
- second proteinpublic void setEdgeAnnotation(int prot1, int prot2, String key, Object value) throws ProCopeException
Note: An edge does not have to be created using setEdge in order to add an annotation. Adding an annotation will also create a new edge in the network.
prot1
- first proteinprot2
- second proteinkey
- key of the annotationvalue
- value of the annotation
ProCopeException
- if value
is not an
Integer
, Float
, String
or
List
public void setEdgeAnnotations(int prot1, int prot2, Map<String,Object> annotations) throws ProCopeException
Note: An edge does not have to be created using setEdge in order to add an annotation. Adding an annotation will also create a new edge in the network.
prot1
- first proteinprot2
- second proteinannotations
- map of key=>value pairs to add to the edge,
already existing annotations with identical keys will
be overwritten
ProCopeException
- if one or more of the values is
not an Integer
, Float
, String
or
List
public Object getEdgeAnnotation(int prot1, int prot2, String key)
prot1
- first proteinprot2
- second proteinkey
- the key for which the value will be read
Integer
, Float
, String
or
List
or null
if there is no value
associated with this keypublic boolean deleteEdge(int prot1, int prot2)
prot1
- first proteinprot2
- second protein
true
if the edge existed and was deleted, false
if no such edge exists in the networkpublic Collection<ProteinPair> getEdgesAsPairs()
iterating over a network
ProteinPair
representing the
adjacency list of the network.public int[] getNeighborArray(int protein)
protein
- protein for which the neighbors will be retrieved
public int[] getEdgesArray()
n
there are
n/2
edges in the network. The array alternatingly contains the
first and second protein of each edge.
See above for examples on iterating over a
network
public Map<String,Object> getEdgeAnnotations(int prot1, int prot2)
prot1
- first proteinprot2
- second protein
Map
of key/value pairs associated with this
edge, all values are of type Integer
, Float
,
String
or List
public Collection<NetworkEdge> getNeighbors(int protein)
edge.getSource() ==
protein
. For directed networks of course edge.getSource()
will
always be the actual source of the directed edge.
protein
- protein to retrieve neighbors for
network edges
incident with
the given proteinpublic Collection<NetworkEdge> getDirectedNeighbors(int protein, boolean fromProtein)
fromProtein==true
it will only return edges where protein
is the source protein, for fromProtein==false
only
those edges where protein
is the target will be returned.
The function should not be called for undirected networks and will
output a warning on stderr
if you do so.
protein
- protein for which neighbors will be retrieved from the
networkfromProtein
- get directed edges where protein
is the
source (fromProtein==true
) or the target (fromProtein==false
)
public Set<Integer> getProteins()
getProteins
in interface ProteinSet
public int getEdgeCount()
public int getNodeCount()
getProteins().size()
.
public Set<String> getAnnotationKeys()
public ProteinNetwork restrictToProteins(ProteinSet proteins, boolean fullCoverage)
proteins
- set of proteins to which this network will be restrictedfullCoverage
- if true
then both proteins of an edge have
to be in the restriction set, if false
then
one protein is sufficient
public ProteinNetwork restrictToProteins(Set<Integer> proteinIDs, boolean fullCoverage)
proteinIDs
set should be a quickly searchable Set
implementation like HashSet
.
proteinIDs
- set of proteins to which this network will be restrictedfullCoverage
- if true
then both proteins of an edge have
to be in the restriction set, if false
then
one protein is sufficient
public boolean isDirected()
true
if this is a directed network, false
otherweisepublic ProteinNetwork getFilteredNetwork(BooleanExpression statement)
@weight
in the expression.
statement
- boolean expression used for edge evaluation
BooleanExpression
public Set<Integer> getNodes()
getProteins()
public void setIterateEdgesTwice(boolean iterateTwice)
iterator()
this value
sets if each undirected edge will appear just once, or if it will
appear twice in each iteration with both neighbors acting as source one
time and as target the second time.
If iterating once the protein with the smaller internal ID will be the source of the edge.
Note: This setting has no effect on directed networks and will
output a warning on stderr
if called on such a network.
By default this value is set to false
.
iterateTwice
- public Iterator<NetworkEdge> iterator()
setIterateEdgesTwice(boolean)
setting and the iterating over a network
section above.
iterator
in interface Iterable<NetworkEdge>
public boolean equalScores(ProteinNetwork compare)
compare
- other network for comparison
true
if and only if both networks have the same edges
and all of these edges have the same weightpublic boolean equals(Object obj)
equals
in class Object
public void depthFirstSearch(int start, NetworkSearchCallback callback)
NetworkSearchCallback
for more information.
start
- the protein node where to start the searchcallback
- callback object to which all nodes passed in the search
are reportedpublic void breadthFirstSearch(int start, NetworkSearchCallback callback)
NetworkSearchCallback
for more information.
start
- the protein node where to start the searchcallback
- callback object to which all nodes passed in the search
are reportedpublic ProteinNetwork combineWith(ProteinNetwork other, CombinationRules rules)
combination rules
.
If one network is directed and the other one undirected the result will be undirected
For more information check out the CombinationRules
API docs.
other
- the network this one to be combined withrules
- combination rules
public ProteinNetwork getCutOffNetwork(float cutOff)
cutOff
- the cutoff value
public ProteinNetwork getCutOffNetwork(float cutOff, boolean cutBelow)
cutOff
- the cutoff valuecutBelow
- true
to cut weights below the threshold, false
to cut weights above the threshold.
public ProteinNetwork copy()
public ProteinNetwork undirectedCopy()
For undirected networks this function is the same as copy()
public void scalarMultiplication(float factor)
factor
- multiplication factorpublic ProteinNetwork randomizeByRewiring()
(a,b)
and (c,d)
are selected such that a != b
!= c != d
. These 4 nodes are rewired to create two new edges (a,d)
and (c,b)
.
This function will do 10 times as many rewirings as there are edges in the network.
public ProteinNetwork randomizeByRewiring(int rewirings)
(a,b)
and (c,d)
are selected such that a != b
!= c != d
. These 4 nodes are rewired to create two new edges (a,d)
and (c,b)
.
rewirings
- number of rewirings which will be performed
public PurificationData derivePurificationData(boolean poolBaits) throws ProCopeException
If poolBaits==true
then one PurificationExperiment
for each source protein will be created. With poolBaits==false
each single edge will be treated as one purification experiment.
Note: poolBaits==false
might cause very large and memory-
intense PurificationData
object
poolBaits
- if true
one PurificationExperiment
is
created per bait, otherwise each edge is treated as a single
experiment.
PurificationExperiment
object derived from the network
ProCopeException
- if the network is undirectedpublic static void main(String[] args) throws IOException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |