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 sequences_to_features.py #54

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
63 changes: 48 additions & 15 deletions sequences_to_features/sequences_to_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,9 @@ def __create_sequence_annotation(cls, parent_definition, child_definition, orien
return seq_anno

def __process_feature_matches(self, target_doc, target_definition, feature_matches, orientation, target_length,
rc_factor=0, copy_definitions=True, complete_matches=False):
rc_factor=0, copy_definitions=True, complete_matches=False, output_matches=False):
output_match_list = []

for feature_match in feature_matches:
temp_start = feature_match[1]//2 + 1
temp_end = (feature_match[2] + 1)//2
Expand Down Expand Up @@ -880,9 +882,25 @@ def __process_feature_matches(self, target_doc, target_definition, feature_match
feature_doc = self.feature_library.get_document(feature.identity)

FeatureLibrary.copy_component_definition(feature_definition, feature_doc, target_doc)

self.logger.debug('Annotated %s (%s, %s) at [%s, %s] in %s', feature_definition.identity, feature_ID,
feature_role, start, end, target_definition.identity)

if output_matches:
output_match_list.append({'feature_identity': feature_definition.identity,
'feature_ID':feature_ID,
'role': feature_role,
'start': start,
'end': end,
'orientation': orientation,
'target_identity': target_definition.identity})

self.logger.debug('Annotated %s (%s, %s) at [%s, %s] in %s',
feature_definition.identity,
feature_ID,
feature_role,
start,
end,
target_definition.identity)

return output_match_list

def extend_features_by_name(self, target_library, min_target_length, mismatch_threshold, strip_prefixes=[]):
self.logger.info('Extending feature library')
Expand Down Expand Up @@ -1003,8 +1021,9 @@ def annotate_raw_sequences(self, raw_seqs, comp_IDs=[], min_target_length=0, com
return annotated_comps

def annotate(self, target_library, min_target_length, in_place=False, output_library=None, complete_matches=False,
strip_prefixes=[]):
strip_prefixes=[], output_matches=False):
annotated_identities = []
output_match_lists = []

for target in target_library.features:
if self.__has_min_length(target, min_target_length):
Expand Down Expand Up @@ -1049,23 +1068,37 @@ def annotate(self, target_library, min_target_length, in_place=False, output_lib
strip_prefixes=strip_prefixes)

if definition_copy:
self.__process_feature_matches(target_doc, definition_copy, inline_matches,
sbol2.SBOL_ORIENTATION_INLINE, len(target.nucleotides),
copy_definitions=(not output_library or doc_index >= len(output_library.docs)),
complete_matches=complete_matches)
self.__process_feature_matches(target_doc, definition_copy, rc_matches,
sbol2.SBOL_ORIENTATION_REVERSE_COMPLEMENT, len(target.nucleotides), len(target.nucleotides) + 1,
(not output_library or doc_index >= len(output_library.docs)),
complete_matches=complete_matches)
copy_definitions = (not output_library or doc_index >= len(output_library.docs))

output_match_list = self.__process_feature_matches(target_doc,
definition_copy,
inline_matches,
sbol2.SBOL_ORIENTATION_INLINE,
len(target.nucleotides),
copy_definitions=copy_definitions,
complete_matches=complete_matches,
output_matches=output_matches)
output_match_list.extend(self.__process_feature_matches(target_doc,
definition_copy,
rc_matches,
sbol2.SBOL_ORIENTATION_REVERSE_COMPLEMENT,
len(target.nucleotides),
len(target.nucleotides) + 1,
copy_definitions,
complete_matches=complete_matches,
output_matches=output_matches))
output_match_lists.append(output_match_list)

annotated_identities.append(definition_copy.identity)
else:
self.logger.warning('%s was not annotated because its version could not be incremented.',
target.identity)

self.logger.info('Finished annotating %s', target.identity)

return annotated_identities
if output_matches:
return annotated_identities, output_match_lists
else:
return annotated_identities

class FeaturePruner():

Expand Down