Skip to content

Commit

Permalink
take readlist for plot and metric subtools
Browse files Browse the repository at this point in the history
  • Loading branch information
hiruna72 committed Jan 31, 2024
1 parent 7ae881c commit 8a6cda1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ def run(args):
fout = open(args.output, "w")
if args.read_id != "":
args.plot_limit = 1
if args.read_list != "":
print(f'read_id list file: {args.read_list}')
read_id_list = list(line.strip() for line in open(args.read_list))

use_fasta = 0
if args.file:
Expand Down Expand Up @@ -292,6 +295,8 @@ def run(args):
read_id = paf_record.query_name
if args.read_id != "" and read_id != args.read_id:
continue
if args.read_list != "" and read_id not in read_id_list:
continue
if read_id not in set(sequence_reads.keys()):
raise Exception("Error: read_id {} is not found in {}".format(read_id, args.file))
if 'ss' not in paf_record.tags:
Expand Down Expand Up @@ -455,6 +460,8 @@ def run(args):
continue
if args.read_id != "" and read_id != args.read_id:
continue
if args.read_list != "" and read_id not in read_id_list:
continue
if not sam_record.has_tag("ss"):
raise Exception("Error: ss string is missing for the read_id {} in {}".format(read_id, args.alignment))
ref_seq_len = 0
Expand Down Expand Up @@ -654,6 +661,8 @@ def run(args):
# continue
if args.read_id != "" and read_id != args.read_id:
continue
if args.read_list != "" and read_id not in read_id_list:
continue
if args.plot_reverse is True and paf_record[STRAND] == "+":
continue
if args.plot_reverse is False and paf_record[STRAND] == "-":
Expand Down Expand Up @@ -841,6 +850,7 @@ def argparser():

parser.add_argument('-f', '--file', required=False, type=str, default="", help="fasta/fa/fastq/fq/fq.gz sequence file")
parser.add_argument('-r', '--read_id', required=False, type=str, default="", help="plot the read with read_id")
parser.add_argument('-l', '--read_list', required=False, type=str, default="", help="a file with read_ids to plot")
parser.add_argument('-s', '--slow5', required=False, type=str, default="", help="slow5 file")
parser.add_argument('-a', '--alignment', required=False, type=str, default="", help="for read-signal alignment use PAF\nfor reference-signal alignment use SAM/BAM")
parser.add_argument('--region', required=True, type=str, default="", help="[start-end] 1-based closed interval region to plot. For SAM/BAM eg: chr1:6811428-6811467 or chr1:6,811,428-6,811,467. For PAF eg:100-200.")
Expand Down
10 changes: 10 additions & 0 deletions src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ def run(args):

if args.read_id != "":
args.plot_limit = 1
if args.read_list != "":
print(f'read_id list file: {args.read_list}')
read_id_list = list(line.strip() for line in open(args.read_list))

use_fasta = 0
if args.file:
Expand Down Expand Up @@ -564,6 +567,8 @@ def run(args):
read_id = paf_record.query_name
if args.read_id != "" and read_id != args.read_id:
continue
if args.read_list != "" and read_id not in read_id_list:
continue
if read_id not in set(sequence_reads.keys()):
raise Exception("Error: read_id {} is not found in {}".format(read_id, args.file))
if 'ss' not in paf_record.tags:
Expand Down Expand Up @@ -751,6 +756,8 @@ def run(args):
continue
if args.read_id != "" and read_id != args.read_id:
continue
if args.read_list != "" and read_id not in read_id_list:
continue
if not sam_record.has_tag("ss"):
raise Exception("Error: ss string is missing for the read_id {} in {}".format(read_id, args.alignment))
ref_seq_len = 0
Expand Down Expand Up @@ -955,6 +962,8 @@ def run(args):
# continue
if args.read_id != "" and read_id != args.read_id:
continue
if args.read_list != "" and read_id not in read_id_list:
continue
if args.plot_reverse is True and paf_record[STRAND] == "+":
continue
if args.plot_reverse is False and paf_record[STRAND] == "-":
Expand Down Expand Up @@ -1148,6 +1157,7 @@ def argparser():

parser.add_argument('-f', '--file', required=False, type=str, default="", help="fasta/fa/fastq/fq/fq.gz sequence file")
parser.add_argument('-r', '--read_id', required=False, type=str, default="", help="plot the read with read_id")
parser.add_argument('-l', '--read_list', required=False, type=str, default="", help="a file with read_ids to plot")
parser.add_argument('-s', '--slow5', required=False, type=str, default="", help="slow5 file")
parser.add_argument('-a', '--alignment', required=False, type=str, default="", help="for read-signal alignment use PAF\nfor reference-signal alignment use SAM/BAM")
parser.add_argument('--base_limit', required=False, type=int, help="maximum number of bases to plot")
Expand Down

0 comments on commit 8a6cda1

Please sign in to comment.