Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bam insert statement to include new required data #33

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/main/scripts/add_bam_pair_xenocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def add_bam_pair_stp(raptr, sample, target, project, subproject, **kwargs):
None
"""
# Get stp ID
query = """select sample_target_project_id from sample_target_project_view where
query = """select sample_target_project_id from sample_target_project_view where
formal_name = %s and target_name = %s and project_name = %s and subproject = %s;"""
stp_id = raptr.fetch_item_or_fail(query, (sample, target, project, subproject))

Expand All @@ -109,19 +109,25 @@ def add_bam_pair_stp(raptr, sample, target, project, subproject, **kwargs):
# Get genome for old bam
query = """select genome_id from bam where bam_id = %s;"""
genome_id = raptr.fetch_item_or_fail(query, (bam_id,))

# Get anls type named xenocp
query = """select anls_type_id from raptr.anls_type where name='%s'"""
anls_type_id = raptr.fetch_item_or_fail(query, ('xenocp',))

# Add a new bam
query = """insert into bam (bam_id, bam_tpl_id, status, notes, genome_id)
values (nextval('blt_id_seq'), %s, 'Normal', NULL, %s) returning bam_id;"""
bam_id_xenocp = raptr.fetch_item_or_fail(query, (bam_tpl_id_xenocp, genome_id))
query = """insert into bam (bam_id, bam_tpl_id, status, notes, genome_id, anls_type_id, source_bam_id)
values (nextval('blt_id_seq'), %s, 'Normal', NULL, %s, %s, %s) returning bam_id;"""
mcrusch marked this conversation as resolved.
Show resolved Hide resolved
bam_id_xenocp = raptr.fetch_item_or_fail(query, (bam_tpl_id_xenocp, genome_id, anls_type_id, bam_id))

# Update primary_bam_id of bam_tpl with the qualifier
query = """update bam_tpl set primary_bam_id = %s where bam_tpl_id = %s;"""
raptr.execute(query, (bam_id_xenocp, bam_tpl_id_xenocp))

# Get read_group_ids and insert into bam_read_group
query = """SELECT read_group_id, pu from read_group inner join (select loadable_id as lid,
query = """SELECT read_group_id, pu from read_group inner join (select loadable_id as lid,
project_id as pid, project_name, subproject, target_name from loadable inner join
(select * from sample_target_project_view where
formal_name = %s and target_name = %s and project_name = %s
formal_name = %s and target_name = %s and project_name = %s
and subproject = %s) using (sample_target_id))
on loadable_id = lid and project_id = pid where status = 'Normal';"""
res = raptr.execute_fetch(query, (sample, target, project, subproject))
Expand Down Expand Up @@ -150,7 +156,7 @@ def add_bam_pair_bam_id(raptr, bam_id, **kwargs):
None
"""
query = """select formal_name, target_name, project_name, subproject from sample_target_project_view inner join
(select sample_target_project_id from bam_and_tpl where bam_id = %s and bam_status = 'Normal'
(select sample_target_project_id from bam_and_tpl where bam_id = %s and bam_status = 'Normal'
and legacy = false)
using (sample_target_project_id);"""
(sample, target, project, subproject) = raptr.fetch_row_or_fail(query, (bam_id,))
Expand Down