about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--domagi/domagi.py17
-rw-r--r--test-data/expected-output/test1-extract-node-1.gfa4
-rw-r--r--test-data/expected-output/test1-extract-node-2.gfa4
-rw-r--r--test-data/expected-output/test1-extract-node-3.gfa4
-rw-r--r--test-data/expected-output/test1-extract-path-7-10.gfa4
-rw-r--r--test-data/expected-output/test1-extract-path-7-8.gfa4
-rw-r--r--test-data/expected-output/test1-extract-path-7-9.gfa4
-rw-r--r--test-data/expected-output/test1-extract-path-8-10.gfa2
-rw-r--r--test-data/expected-output/test1-extract-path-8-9.gfa2
9 files changed, 28 insertions, 17 deletions
diff --git a/domagi/domagi.py b/domagi/domagi.py
index 20f5837..72f9d73 100644
--- a/domagi/domagi.py
+++ b/domagi/domagi.py
@@ -258,20 +258,31 @@ def extract(con, outfile, segment_name, path_range, steps, threads, progress):
     SELECT from_segment, from_orientation, to_segment, to_orientation
     FROM selected_segment
     INNER JOIN link ON from_segment=selected_segment.id;
-    
+
+    CREATE TEMPORARY TABLE path_first_start AS
+      SELECT path_id, MIN(start) AS first_start
+      FROM selected_segment
+      INNER JOIN path_segment ON path_segment.segment_id=selected_segment.id
+      GROUP BY path_id;
+
     INSERT INTO subset_db.path_segment
-    SELECT path_id, segment_id, segment_orientation, start, "end"
+    -- There are no gaps in the path segments. So, it's enough to subtract
+    -- first_start from the path segment coordinates.
+    SELECT path_segment.path_id, segment_id, segment_orientation, start-first_start, "end"-first_start
     FROM selected_segment
     INNER JOIN path_segment ON path_segment.segment_id=selected_segment.id
+    INNER JOIN path_first_start ON path_first_start.path_id=path_segment.path_id
     -- Re-order similar to post-import.sql for optimal access.
     ORDER BY path_id, start, "end";
     
     INSERT INTO subset_db.path
-    SELECT id, ANY_VALUE(name)
+    SELECT id, ANY_VALUE(name) || ':' || MIN(start)+ANY_VALUE(first_start) || '-' || MAX("end")+ANY_VALUE(first_start)
     FROM subset_db.path_segment
     INNER JOIN path ON subset_db.path_segment.path_id=path.id
+    INNER JOIN path_first_start ON path_first_start.path_id=path.id
     GROUP BY id;
 
+    DROP TABLE path_first_start;
     DROP TABLE selected_segment;
     """)
 
diff --git a/test-data/expected-output/test1-extract-node-1.gfa b/test-data/expected-output/test1-extract-node-1.gfa
index 3beb269..9c2c36f 100644
--- a/test-data/expected-output/test1-extract-node-1.gfa
+++ b/test-data/expected-output/test1-extract-node-1.gfa
@@ -8,5 +8,5 @@ L	9	+	10	+	0M
 L	9	+	11	+	0M
 S	10	A
 S	11	T
-P	x	8+,9+,11+	*
-P	y	7+,9+,10+	*
+P	x:13-34	8+,9+,11+	*
+P	y:13-34	7+,9+,10+	*
diff --git a/test-data/expected-output/test1-extract-node-2.gfa b/test-data/expected-output/test1-extract-node-2.gfa
index 876dd44..9bcc91d 100644
--- a/test-data/expected-output/test1-extract-node-2.gfa
+++ b/test-data/expected-output/test1-extract-node-2.gfa
@@ -14,5 +14,5 @@ L	10	+	12	+	0M
 S	11	T
 L	11	+	12	+	0M
 S	12	ATAT
-P	x	6+,8+,9+,11+,12+	*
-P	y	6+,7+,9+,10+,12+	*
+P	x:10-38	6+,8+,9+,11+,12+	*
+P	y:10-38	6+,7+,9+,10+,12+	*
diff --git a/test-data/expected-output/test1-extract-node-3.gfa b/test-data/expected-output/test1-extract-node-3.gfa
index 0d58053..0a0113f 100644
--- a/test-data/expected-output/test1-extract-node-3.gfa
+++ b/test-data/expected-output/test1-extract-node-3.gfa
@@ -22,5 +22,5 @@ L	12	+	13	+	0M
 L	12	+	14	+	0M
 S	13	A
 S	14	T
-P	x	5+,6+,8+,9+,11+,12+,14+	*
-P	y	4+,6+,7+,9+,10+,12+,13+	*
+P	x:9-39	5+,6+,8+,9+,11+,12+,14+	*
+P	y:9-39	4+,6+,7+,9+,10+,12+,13+	*
diff --git a/test-data/expected-output/test1-extract-path-7-10.gfa b/test-data/expected-output/test1-extract-path-7-10.gfa
index 327c140..e01c715 100644
--- a/test-data/expected-output/test1-extract-path-7-10.gfa
+++ b/test-data/expected-output/test1-extract-path-7-10.gfa
@@ -4,5 +4,5 @@ L	1	+	3	+	0M
 S	3	G
 L	3	+	5	+	0M
 S	5	C
-P	x	1+,3+,5+	*
-P	y	1+	*
+P	x:0-10	1+,3+,5+	*
+P	y:0-8	1+	*
diff --git a/test-data/expected-output/test1-extract-path-7-8.gfa b/test-data/expected-output/test1-extract-path-7-8.gfa
index 6ac10e2..aea4b13 100644
--- a/test-data/expected-output/test1-extract-path-7-8.gfa
+++ b/test-data/expected-output/test1-extract-path-7-8.gfa
@@ -1,4 +1,4 @@
 H	VN:Z:1.0
 S	1	CAAATAAG
-P	x	1+	*
-P	y	1+	*
+P	x:0-8	1+	*
+P	y:0-8	1+	*
diff --git a/test-data/expected-output/test1-extract-path-7-9.gfa b/test-data/expected-output/test1-extract-path-7-9.gfa
index d013efd..005ddaa 100644
--- a/test-data/expected-output/test1-extract-path-7-9.gfa
+++ b/test-data/expected-output/test1-extract-path-7-9.gfa
@@ -2,5 +2,5 @@ H	VN:Z:1.0
 S	1	CAAATAAG
 L	1	+	3	+	0M
 S	3	G
-P	x	1+,3+	*
-P	y	1+	*
+P	x:0-9	1+,3+	*
+P	y:0-8	1+	*
diff --git a/test-data/expected-output/test1-extract-path-8-10.gfa b/test-data/expected-output/test1-extract-path-8-10.gfa
index 703d856..a5d3421 100644
--- a/test-data/expected-output/test1-extract-path-8-10.gfa
+++ b/test-data/expected-output/test1-extract-path-8-10.gfa
@@ -2,4 +2,4 @@ H	VN:Z:1.0
 S	3	G
 L	3	+	5	+	0M
 S	5	C
-P	x	3+,5+	*
+P	x:8-10	3+,5+	*
diff --git a/test-data/expected-output/test1-extract-path-8-9.gfa b/test-data/expected-output/test1-extract-path-8-9.gfa
index 243a879..808e3fa 100644
--- a/test-data/expected-output/test1-extract-path-8-9.gfa
+++ b/test-data/expected-output/test1-extract-path-8-9.gfa
@@ -1,3 +1,3 @@
 H	VN:Z:1.0
 S	3	G
-P	x	3+	*
+P	x:8-9	3+	*