42cfb8cd4a22209d8183ffcad97e5ca5e9ae070b
braney
  Fri Sep 4 12:47:47 2026 -0700
chainNetDbLoad: add chainLoadRange, every chain in a range with its blocks

chainLoadIdRange loads one chain by id, and the bigChain reader takes -1 to mean
every chain in the range, but there was no SQL equivalent of the latter.  This is
it: one query for the headers, one for the links, and each link handed to the
chain it belongs to.

The blocks are sorted rather than just reversed.  A bin indexed range query does
not return rows in position order, and anything that walks a chain's blocks
expects them ascending, which is why chainLinkAddResult sorts them too.

refs #38249

diff --git src/hg/inc/chainNetDbLoad.h src/hg/inc/chainNetDbLoad.h
index a34f1347bcb..4f5bca16631 100644
--- src/hg/inc/chainNetDbLoad.h
+++ src/hg/inc/chainNetDbLoad.h
@@ -1,59 +1,64 @@
 /* chainNetDbLoad - This will load a database representation of
  * a net into a chainNet representation.  Also helps database
  * representation of chain into chain. */
 
 /* Copyright (C) 2002 The Regents of the University of California 
  * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */
 
 #ifndef CHAINNETDBLOAD_H
 #define CHAINNETDBLOAD_H
 
 #ifndef JKSQL_H
 #include "jksql.h"
 #endif
 
 #ifndef NETALIGN_H
 #include "netAlign.h"
 #endif
 
 #ifndef CHAINNET_H
 #include "chainNet.h"
 #endif
 
 
 struct cnFill *cnFillFromNetAlign(struct netAlign *na, struct hash *nameHash);
 /* Convert netAlign to cnFill. Name hash is a place to store
  * the strings. */
 
 struct chainNet *chainNetLoadResult(struct sqlResult *sr, int rowOffset);
 /* Given a query result that returns a bunch netAligns, make up
  * a list of chainNets that has the equivalent information. 
  * Note the net->size field is not filled in. */
 
 struct chainNet *chainNetLoadRange(char *database, char *track,
 	char *chrom, int start, int end, char *extraWhere);
 /* Load parts of a net track that intersect range. */
 
 struct chainNet *chainNetLoadChrom(char *database, char *track,
 	char *chrom, char *extraWhere);
 /* Load net on whole chromosome. */
 
+struct chain *chainLoadRange(char *database, char *track, char *chrom, int start, int end);
+/* Load every chain in a range from the database, each carrying the blocks that overlap the
+ * range.  As with chainLoadIdRange the chain header still describes the whole chain, not
+ * just the part in range. */
+
 struct chain *chainLoadIdRangeHub(char *database, char *fileName, char *track, char *chrom, 
 	int start, int end, int id);
 /* Load parts of chain of given ID from bigChain file.  Note the chain header
  * including score, tStart, tEnd, will still reflect the whole chain,
  * not just the part in range.  However only the blocks of the chain
  * overlapping the range will be loaded. */
 
 struct chain *chainLoadIdRange(char *database, char *track, char *chrom, 
 	int start, int end, int id);
 /* Load parts of chain of given ID from database.  Note the chain header
  * including score, tStart, tEnd, will still reflect the whole chain,
  * not just the part in range.  However only the blocks of the chain
  * overlapping the range will be loaded. */
 
 struct chain *chainLoadId(char *database, char *track, char *chrom, int id);
 /* Load chain of given ID from database. */
 
 #endif /* CHAINNETDBLOAD_H */