diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 618d892..8f63b07 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,11 @@ + + +<<<<<<< Updated upstream <<<<<<< Updated upstream @@ -9,6 +13,9 @@ ======= +>>>>>>> Stashed changes +======= + >>>>>>> Stashed changes +<<<<<<< Updated upstream <<<<<<< Updated upstream @@ -130,6 +138,8 @@ ======= +>>>>>>> Stashed changes +======= >>>>>>> Stashed changes diff --git a/liftoff/__init__.py b/liftoff/__init__.py index 4a9b978..4574cc8 100644 --- a/liftoff/__init__.py +++ b/liftoff/__init__.py @@ -1 +1 @@ -__version__ = '1.6.2' +__version__ = '1.6.3' diff --git a/liftoff/run_liftoff.py b/liftoff/run_liftoff.py index 550d477..fbaad95 100644 --- a/liftoff/run_liftoff.py +++ b/liftoff/run_liftoff.py @@ -109,7 +109,7 @@ def parse_args(arglist): "target and " "reference; by default F=0.0") - parser.add_argument('-V', '--version', help='show program version', action='version', version='v1.6.2') + parser.add_argument('-V', '--version', help='show program version', action='version', version='v1.6.3') parser.add_argument( '-p', default=1, type=int, metavar='P', help='use p parallel processes to accelerate alignment; by default p=1' ) diff --git a/liftoff/write_new_gff.py b/liftoff/write_new_gff.py index 0f76658..f5339d5 100644 --- a/liftoff/write_new_gff.py +++ b/liftoff/write_new_gff.py @@ -1,18 +1,19 @@ from liftoff import liftoff_utils, __version__ import sys + def write_header(f, out_type): - f.write("# " + " ".join(sys.argv) + "\n") - f.write("# Liftoff v" + __version__ + "\n") if out_type == 'gff3': f.write('##gff-version 3' + "\n") + f.write("# Liftoff v" + __version__ + "\n") + f.write("# " + " ".join(sys.argv) + "\n") def write_new_gff(lifted_features, args, feature_db): if args.o != 'stdout': f = open(args.o, 'w') else: - f = "stdout" + f = sys.stdout out_type = feature_db.dialect['fmt'] write_header(f, out_type) parents = liftoff_utils.get_parent_list(lifted_features) @@ -77,53 +78,56 @@ def write_feature(children, outfile, child_features, parent_dict, output_type): for child in children: write_line(child, outfile, output_type) if child.id in parent_dict: - new_children = parent_dict[child.id] + new_children = parent_dict[child.id ] write_feature(new_children, outfile, child_features, parent_dict, output_type) return def write_line(feature, out_file, output_type): - if output_type == 'gff3': - line = make_gff_line(feature) + if feature.attributes["extra_copy_number"][0]!='0': + attr_dict = edit_copy_ids(feature) else: - line = make_gtf_line(feature) - if out_file == "stdout": - print(line) + attr_dict = feature.attributes + if output_type == 'gff3': + line = make_gff_line(attr_dict, feature) else: - out_file.write(line) - out_file.write("\n") + line = make_gtf_line(attr_dict, feature) + out_file.write(line) + out_file.write("\n") -def make_gff_line(feature): - edit_copy_ids(feature) - attributes_str = "ID=" + feature.attributes["ID"][0] + ";" #make ID the first printed attribute - for attr in feature.attributes: +def make_gff_line(attr_dict, feature): + attributes_str = "ID=" + attr_dict["ID"][0] + ";" #make ID the first printed attribute + for attr in attr_dict: if attr != "copy_id": value_str = "" - for value in feature.attributes[attr]: - value_str += value + "," + for value in attr_dict[attr]: + value_str += value + "," if attr != "ID": attributes_str += (attr + "=" + value_str[:-1] + ";") return feature.seqid + "\t" + feature.source + "\t" + feature.featuretype + "\t" + str(feature.start) + \ "\t" + str(feature.end) + "\t" + "." + "\t" + feature.strand + "\t" + "." + "\t" + attributes_str[:-1] def edit_copy_ids(feature): + new_attr_dict = feature.attributes.copy() copy_num = feature.attributes["extra_copy_number"][0] - if copy_num != '0': - feature.attributes["ID"] = [feature.attributes["ID"][0]+ "_" + copy_num] - if "Parent" in feature.attributes: - feature.attributes["Parent"] = [feature.attributes["Parent"][0] + "_" + copy_num] - if "gene_id" in feature.attributes: - feature.attributes["gene_id"] = [feature.attributes["gene_id"][0] + "_" + copy_num] + for attr in feature.attributes: + if attr[-3:] == "_id": + new_attr_dict[attr] = [feature.attributes[attr][0] + "_" + copy_num] + elif attr == 'ID': + new_attr_dict["ID"] = [feature.attributes["ID"][0]+ "_" + copy_num] + elif attr == "Parent": + new_attr_dict["Parent"] = [feature.attributes["Parent"][0] + "_" + copy_num] + return new_attr_dict -def make_gtf_line(feature): +def make_gtf_line(attr_dict, feature): attributes_str = "" - for attr in feature.attributes: + for attr in attr_dict: if attr != "copy_id": - if len(feature.attributes[attr]) >0: + if len(attr_dict[attr]) >0: value_str = "" - for value in feature.attributes[attr]: + for value in attr_dict[attr]: value_str += value + "," attributes_str += (attr + " " + '"' + value_str[:-1] + '"' + "; ") return feature.seqid + "\t" + feature.source + "\t" + feature.featuretype + "\t" + str(feature.start) + \ diff --git a/setup.py b/setup.py index 8492ce2..f0a587c 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setuptools.setup( name="Liftoff", - version="1.6.2", + version="1.6.3", author="Alaina Shumate", author_email="ashumat2@jhmi.edu", description="A gene annotation mapping tool",