Skip to content

Commit 19027ec

Browse files
mellypopmcrusch
andauthored
Update loadable refs to read_group refs (#35)
* Update loadable refs to read_group refs * Format query cleanly --------- Co-authored-by: mcrusch <[email protected]>
1 parent 181f36a commit 19027ec

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/main/scripts/add_bam_pair_xenocp.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,22 @@ def add_bam_pair_stp(raptr, sample, target, project, subproject, **kwargs):
8989
formal_name = %s and target_name = %s and project_name = %s and subproject = %s;"""
9090
stp_id = raptr.fetch_item_or_fail(query, (sample, target, project, subproject))
9191

92-
# Get loadables associated with old bam_tpl
92+
# Get read groups associated with old bam_tpl
9393
query = """select bam_tpl_id, bam_id from bam_and_tpl where sample_target_project_id = %s
9494
and bam_status = 'Normal' and legacy = False"""
9595
(bam_tpl_id, bam_id) = raptr.fetch_row_or_fail(query, (stp_id,))
96-
query = """select loadable_id from bam_tpl_loadable where bam_tpl_id = %s;"""
97-
loadable_ids = raptr.fetch_col_or_fail(query, (bam_tpl_id,))
96+
query = """select read_group_id from bam_tpl_read_group where bam_tpl_id = %s;"""
97+
rg_ids = raptr.fetch_col_or_fail(query, (bam_tpl_id,))
9898

9999
# Insert a new bam_tpl with qualifier 'xenocp'
100100
query = """insert into bam_tpl (bam_tpl_id, qualifier, status, sample_target_project_id)
101101
values (nextval('blt_id_seq'), 'xenocp', 'Default', %s) returning bam_tpl_id;"""
102102
bam_tpl_id_xenocp = raptr.fetch_item_or_fail(query, (stp_id,))
103103

104104
# Associate loadables with new bam_tpl.
105-
query = """insert into bam_tpl_loadable values (%s, %s)"""
106-
for lid in loadable_ids:
107-
raptr.execute(query, (bam_tpl_id_xenocp, lid))
105+
query = """insert into bam_tpl_read_group values (%s, %s)"""
106+
for rgid in rg_ids:
107+
raptr.execute(query, (bam_tpl_id_xenocp, rgid))
108108

109109
# Get genome for old bam
110110
query = """select genome_id from bam where bam_id = %s;"""
@@ -124,12 +124,19 @@ def add_bam_pair_stp(raptr, sample, target, project, subproject, **kwargs):
124124
raptr.execute(query, (bam_id_xenocp, bam_tpl_id_xenocp))
125125

126126
# Get read_group_ids and insert into bam_read_group
127-
query = """SELECT read_group_id, pu from read_group inner join (select loadable_id as lid,
128-
project_id as pid, project_name, subproject, target_name from loadable inner join
129-
(select * from sample_target_project_view where
130-
formal_name = %s and target_name = %s and project_name = %s
131-
and subproject = %s) using (sample_target_id))
132-
on loadable_id = lid and project_id = pid where status = 'Normal';"""
127+
query = """select
128+
rg.read_group_id,
129+
rg.pu
130+
from
131+
read_group rg
132+
inner join sample_target_project_view stpv
133+
on rg.sample_target_id = stpv.sample_target_id and rg.project_id = stpv.project_id
134+
where
135+
status = 'Normal'
136+
and formal_name = %s
137+
and target_name = %s
138+
and project_name = %s
139+
and subproject = %s;"""
133140
res = raptr.execute_fetch(query, (sample, target, project, subproject))
134141
query = """insert into bam_read_group (bam_id, read_group_id, rgid)
135142
values (%s, %s, %s);"""

0 commit comments

Comments
 (0)