Address performance issue #1077
This commit is contained in:
parent
c98be3dbd6
commit
047aea9707
|
|
@ -140,10 +140,10 @@ public class LowWeightChainPruner<V extends BaseVertex, E extends BaseEdge> {
|
|||
|
||||
// must be after since we can add duplicate starts in the above finding algorithm
|
||||
final List<Path<V, E>> linearChains = new LinkedList<>();
|
||||
final PathBuilder<V, E> builder = new PathBuilder<>(graph, 100);
|
||||
for ( final V chainStart : chainStarts ) {
|
||||
for ( final E outEdge : graph.outgoingEdgesOf(chainStart) ) {
|
||||
// these chains are composed of the starts + their next vertices
|
||||
linearChains.add(extendLinearChain(new Path<>(new Path<>(chainStart, graph), outEdge)));
|
||||
linearChains.add(extendLinearChain(builder.start(chainStart).addEdge(outEdge)).make());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,28 +152,29 @@ public class LowWeightChainPruner<V extends BaseVertex, E extends BaseEdge> {
|
|||
|
||||
/**
|
||||
* Extend path while the last vertex has in and out degrees of 1 or 0
|
||||
* @param path the path to extend
|
||||
* @param builder the path builder already started
|
||||
* @return a fully extended linear path
|
||||
*/
|
||||
protected final Path<V,E> extendLinearChain(final Path<V, E> path) {
|
||||
final V last = path.getLastVertex();
|
||||
final Set<E> outEdges = path.getGraph().outgoingEdgesOf(last);
|
||||
|
||||
final int outDegree = outEdges.size();
|
||||
final int inDegree = path.getGraph().inDegreeOf(last);
|
||||
|
||||
if ( outDegree != 1 || inDegree > 1 ) {
|
||||
// out next vertex has multiple outgoing edges, so we are done with the linear path
|
||||
return path;
|
||||
} else {
|
||||
final V next = path.getGraph().getEdgeTarget(outEdges.iterator().next());
|
||||
if ( path.containsVertex(next) ) {
|
||||
// we are done if the path contains a cycle
|
||||
return path;
|
||||
} else {
|
||||
// we now know that last has outdegree == 1, so we keep extending the chain
|
||||
return extendLinearChain(new Path<>(path, outEdges.iterator().next()));
|
||||
protected final PathBuilder<V, E> extendLinearChain(final PathBuilder<V, E> builder) {
|
||||
final BaseGraph<V, E> graph = builder.getGraph();
|
||||
V last = builder.lastVertex();
|
||||
while (true) {
|
||||
final Set<E> outEdges = graph.outgoingEdgesOf(last);
|
||||
final int outDegree = outEdges.size();
|
||||
final int inDegree = graph.inDegreeOf(last);
|
||||
if ( outDegree != 1 || inDegree > 1 )
|
||||
break;
|
||||
else {
|
||||
final E edge = outEdges.iterator().next();
|
||||
final V next = graph.getEdgeTarget(edge);
|
||||
if (builder.containsVertex(next))
|
||||
break;
|
||||
else {
|
||||
builder.addEdge(edge);
|
||||
last = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,10 +72,7 @@ public class Path<T extends BaseVertex, E extends BaseEdge> {
|
|||
|
||||
// the last vertex seen in the path
|
||||
protected final T lastVertex;
|
||||
|
||||
// the list of edges comprising the path
|
||||
private Set<E> edgesAsSet = null;
|
||||
protected final ArrayList<E> edgesInOrder;
|
||||
protected final List<E> edgesInOrder;
|
||||
|
||||
// the scores for the path
|
||||
protected final int totalScore;
|
||||
|
|
@ -94,13 +91,22 @@ public class Path<T extends BaseVertex, E extends BaseEdge> {
|
|||
if ( ! graph.containsVertex(initialVertex) ) throw new IllegalArgumentException("Vertex " + initialVertex + " must be part of graph " + graph);
|
||||
|
||||
lastVertex = initialVertex;
|
||||
edgesInOrder = new ArrayList<>(0);
|
||||
edgesInOrder = Collections.emptyList();
|
||||
totalScore = 0;
|
||||
this.graph = graph;
|
||||
}
|
||||
|
||||
protected Path(final BaseGraph<T, E> graph, final List<E> edges, final T lastVertex, final int totalScore) {
|
||||
this.graph = graph;
|
||||
edgesInOrder = edges;
|
||||
this.lastVertex = lastVertex;
|
||||
this.totalScore = totalScore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for testing that creates a path through vertices in graph
|
||||
*
|
||||
* @deprecated use {@link PathBuilder}.
|
||||
*/
|
||||
protected static <T extends BaseVertex, E extends BaseEdge> Path<T,E> makePath(final List<T> vertices, final BaseGraph<T, E> graph) {
|
||||
Path<T,E> path = new Path<T,E>(vertices.get(0), graph);
|
||||
|
|
@ -119,7 +125,6 @@ public class Path<T extends BaseVertex, E extends BaseEdge> {
|
|||
protected Path(final Path<T,E> p) {
|
||||
this.edgesInOrder = p.edgesInOrder;
|
||||
this.lastVertex = p.lastVertex;
|
||||
this.edgesAsSet = p.edgesAsSet;
|
||||
this.totalScore = p.totalScore;
|
||||
this.graph = p.graph;
|
||||
}
|
||||
|
|
@ -178,42 +183,7 @@ public class Path<T extends BaseVertex, E extends BaseEdge> {
|
|||
totalScore = p.totalScore + edge.getMultiplicity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the collection of edges leaving the last vertex of this path
|
||||
* @return a non-null collection
|
||||
*/
|
||||
public Collection<E> getOutgoingEdgesOfLastVertex() {
|
||||
return getGraph().outgoingEdgesOf(getLastVertex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this path contain the given edge
|
||||
* @param edge the given edge to test
|
||||
* @return true if the edge is found in this path
|
||||
*/
|
||||
public boolean containsEdge( final E edge ) {
|
||||
if( edge == null ) { throw new IllegalArgumentException("Attempting to test null edge."); }
|
||||
if ( edgesInOrder.isEmpty() ) return false;
|
||||
|
||||
// initialize contains cache if necessary
|
||||
if ( edgesAsSet == null ) edgesAsSet = new HashSet<E>(edgesInOrder);
|
||||
return edgesAsSet.contains(edge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this path contain the given vertex?
|
||||
*
|
||||
* @param v a non-null vertex
|
||||
* @return true if v occurs within this path, false otherwise
|
||||
*/
|
||||
public boolean containsVertex(final T v) {
|
||||
if ( v == null ) throw new IllegalArgumentException("Vertex cannot be null");
|
||||
|
||||
// TODO -- warning this is expensive. Need to do vertex caching
|
||||
return getVertices().contains(v);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Checks whether a given path is a suffix of this path.
|
||||
*
|
||||
* @param other the path to compare against.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
* By downloading the PROGRAM you agree to the following terms of use:
|
||||
*
|
||||
* BROAD INSTITUTE
|
||||
* SOFTWARE LICENSE AGREEMENT
|
||||
* FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY
|
||||
*
|
||||
* This Agreement is made between the Broad Institute, Inc. with a principal address at 415 Main Street, Cambridge, MA 02142 (“BROAD”) and the LICENSEE and is effective at the date the downloading is completed (“EFFECTIVE DATE”).
|
||||
*
|
||||
* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and
|
||||
* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions.
|
||||
* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows:
|
||||
*
|
||||
* 1. DEFINITIONS
|
||||
* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK3 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute.org/gatk on the EFFECTIVE DATE.
|
||||
*
|
||||
* 2. LICENSE
|
||||
* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. LICENSEE hereby automatically grants to BROAD a non-exclusive, royalty-free, irrevocable license to any LICENSEE bug fixes or modifications to the PROGRAM with unlimited rights to sublicense and/or distribute. LICENSEE agrees to provide any such modifications and bug fixes to BROAD promptly upon their creation.
|
||||
* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement.
|
||||
* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement.
|
||||
* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM.
|
||||
*
|
||||
* 3. PHONE-HOME FEATURE
|
||||
* LICENSEE expressly acknowledges that the PROGRAM contains an embedded automatic reporting system (“PHONE-HOME”) which is enabled by default upon download. Unless LICENSEE requests disablement of PHONE-HOME, LICENSEE agrees that BROAD may collect limited information transmitted by PHONE-HOME regarding LICENSEE and its use of the PROGRAM. Such information shall include LICENSEE’S user identification, version number of the PROGRAM and tools being run, mode of analysis employed, and any error reports generated during run-time. Collection of such information is used by BROAD solely to monitor usage rates, fulfill reporting requirements to BROAD funding agencies, drive improvements to the PROGRAM, and facilitate adjustments to PROGRAM-related documentation.
|
||||
*
|
||||
* 4. OWNERSHIP OF INTELLECTUAL PROPERTY
|
||||
* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication.
|
||||
* Copyright 2012-2014 Broad Institute, Inc.
|
||||
* Notice of attribution: The GATK3 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc.
|
||||
* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes.
|
||||
*
|
||||
* 5. INDEMNIFICATION
|
||||
* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement.
|
||||
*
|
||||
* 6. NO REPRESENTATIONS OR WARRANTIES
|
||||
* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME.
|
||||
* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
|
||||
*
|
||||
* 7. ASSIGNMENT
|
||||
* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void.
|
||||
*
|
||||
* 8. MISCELLANEOUS
|
||||
* 8.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries.
|
||||
* 8.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes.
|
||||
* 8.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4.
|
||||
* 8.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt.
|
||||
* 8.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter.
|
||||
* 8.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement.
|
||||
* 8.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles.
|
||||
*/
|
||||
package org.broadinstitute.gatk.tools.walkers.haplotypecaller.graphs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Path builder.
|
||||
* <p>
|
||||
* Allows the creation of graph path is a efficiently (linear given the length of the path).
|
||||
* </p>
|
||||
*
|
||||
* @author Valentin Ruano-Rubio <valentin@broadinstitute.org>
|
||||
*/
|
||||
public final class PathBuilder<V extends BaseVertex, E extends BaseEdge> {
|
||||
|
||||
private final BaseGraph<V, E> graph;
|
||||
private Set<V> vertices;
|
||||
|
||||
private List<E> edges;
|
||||
private V lastVertex;
|
||||
private boolean needToFork;
|
||||
private final int estimatedPathLength;
|
||||
private int totalScore;
|
||||
|
||||
/**
|
||||
* Creates a path builder given the underlying graph and the expected path length.
|
||||
*
|
||||
* <p>
|
||||
* The path length estimate does not need to be accurate.
|
||||
* </p>
|
||||
* @param graph the target graph.
|
||||
* @param estimatedPathLength the expected path length.
|
||||
*/
|
||||
public PathBuilder(final BaseGraph<V, E> graph, final int estimatedPathLength) {
|
||||
if (graph == null) throw new IllegalArgumentException("the graph cannot be null");
|
||||
if (estimatedPathLength < 0) throw new IllegalArgumentException("the length estimate cannot be null");
|
||||
this.estimatedPathLength = estimatedPathLength;
|
||||
this.graph = graph;
|
||||
lastVertex = null;
|
||||
vertices = new LinkedHashSet<>(estimatedPathLength + 1);
|
||||
edges = new ArrayList<>(estimatedPathLength);
|
||||
needToFork = false;
|
||||
totalScore = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new path given the first vertex in the path.
|
||||
*
|
||||
*
|
||||
* @param vertex the path start vertex.
|
||||
* @return this builder.
|
||||
*/
|
||||
public PathBuilder<V, E> start(final V vertex) {
|
||||
if (vertex == null) throw new IllegalArgumentException("the vertex cannot be null");
|
||||
if (!graph.containsVertex(vertex)) throw new IllegalArgumentException("the vertex must belong to the builder graph");
|
||||
forkIfNeededAndClear();
|
||||
lastVertex = vertex;
|
||||
vertices.add(vertex);
|
||||
totalScore = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends the current path through an edge.
|
||||
* <p>
|
||||
* The edge provided must have the last vertex in the path as the source vertex.
|
||||
* </p>
|
||||
* @param extension the extension edge.
|
||||
* @return this builder.
|
||||
*/
|
||||
public PathBuilder<V, E> addEdge(final E extension) {
|
||||
if (lastVertex == null) throw new IllegalStateException("the path has not been started");
|
||||
if (extension == null) throw new IllegalArgumentException("the input extension edge cannot be null");
|
||||
final V source = graph.getEdgeSource(extension);
|
||||
if (source != lastVertex) throw new IllegalArgumentException("the extension edge source is not the last vertex");
|
||||
final V target = graph.getEdgeTarget(extension);
|
||||
forkIfNeeded();
|
||||
vertices.add(target);
|
||||
edges.add(extension);
|
||||
totalScore += extension.getMultiplicity();
|
||||
lastVertex = target;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the {@link Path} object that represents the current path.
|
||||
* <p>
|
||||
* Later changes in the builder won't affect the path returned.
|
||||
* </p>
|
||||
*
|
||||
* @return never {@code null}.
|
||||
*/
|
||||
public Path<V, E> make() {
|
||||
if (lastVertex == null) throw new IllegalStateException("no path was started");
|
||||
forkIfNeeded();
|
||||
needToFork = true;
|
||||
return new Path(graph, edges, lastVertex, totalScore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forks the current builder state.
|
||||
* <p>
|
||||
* After a path is made, we need to clone the collection in the builder if any further edition takes place.
|
||||
* </p>
|
||||
*/
|
||||
private void forkIfNeeded() {
|
||||
if (needToFork) {
|
||||
vertices = new LinkedHashSet<>(vertices);
|
||||
edges = new ArrayList<>(edges);
|
||||
needToFork = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void forkIfNeededAndClear() {
|
||||
if (needToFork) {
|
||||
vertices = new LinkedHashSet<>(Math.max(vertices.size(), estimatedPathLength));
|
||||
edges = new ArrayList<>(Math.max(edges.size(), estimatedPathLength));
|
||||
lastVertex = null;
|
||||
totalScore = 0;
|
||||
needToFork = false;
|
||||
} else {
|
||||
vertices.clear();
|
||||
edges.clear();
|
||||
totalScore = 0;
|
||||
lastVertex = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the underlying graph.
|
||||
* @return never {@code null}.
|
||||
*/
|
||||
public BaseGraph<V, E> getGraph() {
|
||||
return graph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last vertex in the path.
|
||||
*
|
||||
* @return never {@code null}.
|
||||
* @throws IllegalStateException if no path was started.
|
||||
*/
|
||||
public V lastVertex() {
|
||||
if (lastVertex == null) throw new IllegalStateException("no path was started");
|
||||
return lastVertex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the current path contains a vertex.
|
||||
*
|
||||
* @param vertex the query vertex.
|
||||
* @return {@code true} iff the current path contains the input vertex.
|
||||
*/
|
||||
public boolean containsVertex(final V vertex) {
|
||||
if (vertex == null) throw new IllegalArgumentException();
|
||||
return vertices.contains(vertex);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* By downloading the PROGRAM you agree to the following terms of use:
|
||||
*
|
||||
* BROAD INSTITUTE
|
||||
* SOFTWARE LICENSE AGREEMENT
|
||||
* FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY
|
||||
*
|
||||
* This Agreement is made between the Broad Institute, Inc. with a principal address at 415 Main Street, Cambridge, MA 02142 (“BROAD”) and the LICENSEE and is effective at the date the downloading is completed (“EFFECTIVE DATE”).
|
||||
*
|
||||
* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and
|
||||
* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions.
|
||||
* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows:
|
||||
*
|
||||
* 1. DEFINITIONS
|
||||
* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK3 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute.org/gatk on the EFFECTIVE DATE.
|
||||
*
|
||||
* 2. LICENSE
|
||||
* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. LICENSEE hereby automatically grants to BROAD a non-exclusive, royalty-free, irrevocable license to any LICENSEE bug fixes or modifications to the PROGRAM with unlimited rights to sublicense and/or distribute. LICENSEE agrees to provide any such modifications and bug fixes to BROAD promptly upon their creation.
|
||||
* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement.
|
||||
* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement.
|
||||
* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM.
|
||||
*
|
||||
* 3. PHONE-HOME FEATURE
|
||||
* LICENSEE expressly acknowledges that the PROGRAM contains an embedded automatic reporting system (“PHONE-HOME”) which is enabled by default upon download. Unless LICENSEE requests disablement of PHONE-HOME, LICENSEE agrees that BROAD may collect limited information transmitted by PHONE-HOME regarding LICENSEE and its use of the PROGRAM. Such information shall include LICENSEE’S user identification, version number of the PROGRAM and tools being run, mode of analysis employed, and any error reports generated during run-time. Collection of such information is used by BROAD solely to monitor usage rates, fulfill reporting requirements to BROAD funding agencies, drive improvements to the PROGRAM, and facilitate adjustments to PROGRAM-related documentation.
|
||||
*
|
||||
* 4. OWNERSHIP OF INTELLECTUAL PROPERTY
|
||||
* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication.
|
||||
* Copyright 2012-2014 Broad Institute, Inc.
|
||||
* Notice of attribution: The GATK3 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc.
|
||||
* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes.
|
||||
*
|
||||
* 5. INDEMNIFICATION
|
||||
* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement.
|
||||
*
|
||||
* 6. NO REPRESENTATIONS OR WARRANTIES
|
||||
* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME.
|
||||
* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
|
||||
*
|
||||
* 7. ASSIGNMENT
|
||||
* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void.
|
||||
*
|
||||
* 8. MISCELLANEOUS
|
||||
* 8.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries.
|
||||
* 8.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes.
|
||||
* 8.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4.
|
||||
* 8.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt.
|
||||
* 8.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter.
|
||||
* 8.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement.
|
||||
* 8.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles.
|
||||
*/
|
||||
package org.broadinstitute.gatk.tools.walkers.haplotypecaller.graphs;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PathBuilder}
|
||||
*
|
||||
* @author Valentin Ruano-Rubio <valentin@broadinstitute.org>
|
||||
*/
|
||||
public class PathBuilderUnitTest {
|
||||
|
||||
private static final SeqGraph TEST_GRAPH;
|
||||
|
||||
static {
|
||||
TEST_GRAPH = new SeqGraph(3);
|
||||
final SeqVertex head = new SeqVertex("AAA");
|
||||
final SeqVertex allele1 = new SeqVertex("A");
|
||||
final SeqVertex allele2 = new SeqVertex("T");
|
||||
final SeqVertex tail = new SeqVertex("TTT");
|
||||
TEST_GRAPH.addVertices(head, allele1, allele2, tail);
|
||||
TEST_GRAPH.addEdge(head, allele1, new BaseEdge(true, 10));
|
||||
TEST_GRAPH.addEdge(head, allele2, new BaseEdge(false, 20));
|
||||
TEST_GRAPH.addEdge(allele1, tail, new BaseEdge(true, 30));
|
||||
TEST_GRAPH.addEdge(allele2, tail, new BaseEdge(false, 40));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathBuilderCreationAndGetGraph() {
|
||||
final PathBuilder<SeqVertex, BaseEdge> builder = new PathBuilder<>(TEST_GRAPH, 3);
|
||||
Assert.assertSame(builder.getGraph(), TEST_GRAPH);
|
||||
try {
|
||||
builder.lastVertex();
|
||||
} catch (final IllegalStateException ex) {
|
||||
// expected exception because we have not started a path yet.
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testPathBuilderCreationAndGetGraph")
|
||||
public void testStartAndLastVertex() {
|
||||
final PathBuilder<SeqVertex, BaseEdge> builder = new PathBuilder<>(TEST_GRAPH, 3);
|
||||
final SeqVertex start = TEST_GRAPH.getReferenceSourceVertex();
|
||||
Assert.assertSame(builder.start(start), builder);
|
||||
Assert.assertSame(builder.lastVertex(), start);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testStartAndLastVertex")
|
||||
public void testReferencePathCreation() {
|
||||
final PathBuilder<SeqVertex, BaseEdge> builder = new PathBuilder<>(TEST_GRAPH, 3);
|
||||
final SeqVertex start = TEST_GRAPH.getReferenceSourceVertex();
|
||||
final Set<SeqVertex> verticesSoFar = new HashSet<>();
|
||||
builder.start(start);
|
||||
verticesSoFar.add(start);
|
||||
SeqVertex last = start;
|
||||
int score = 0;
|
||||
final List<BaseEdge> edgeList = new ArrayList<>();
|
||||
while (true) {
|
||||
final SeqVertex next = TEST_GRAPH.getNextReferenceVertex(last);
|
||||
if (next == null)
|
||||
break;
|
||||
final BaseEdge edge = TEST_GRAPH.getEdge(last, next);
|
||||
score += edge.getMultiplicity();
|
||||
edgeList.add(edge);
|
||||
Assert.assertSame(builder.addEdge(edge), builder);
|
||||
last = next;
|
||||
verticesSoFar.add(next);
|
||||
Assert.assertEquals(builder.lastVertex(), last);
|
||||
for (final SeqVertex v: verticesSoFar)
|
||||
Assert.assertTrue(builder.containsVertex(v));
|
||||
for (final SeqVertex v: TEST_GRAPH.vertexSet())
|
||||
if (!verticesSoFar.contains(v))
|
||||
Assert.assertFalse(builder.containsVertex(v));
|
||||
}
|
||||
final Path<SeqVertex, BaseEdge> path = builder.make();
|
||||
Assert.assertNotNull(path);
|
||||
Assert.assertEquals(path.totalScore, score);
|
||||
Assert.assertEquals(path.edgesInOrder,edgeList);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue