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

#54 - CNV off latest master #887

Merged
merged 5 commits into from
Sep 13, 2023
Merged

#54 - CNV off latest master #887

merged 5 commits into from
Sep 13, 2023

Conversation

davmlaw
Copy link
Contributor

@davmlaw davmlaw commented Sep 12, 2023

James to take a look before commit

upload/vcf/vcf_import.py Outdated Show resolved Hide resolved
ref: str
alt: str

def __init__(self, chrom, start, end: int = None, ref: str = None, alt: str = None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the typehint happy it should be

end: Optional[int] = None, ref: Optional[str] = None, alt: Optional[str] = None

as None is not a valid int or str

upload/models/models.py Outdated Show resolved Hide resolved
@davmlaw
Copy link
Contributor Author

davmlaw commented Sep 12, 2023

@TheMadBug - I made changes after your 1st review, if you could go over them again, thanks!

if full_match := VARIANT_PATTERN.fullmatch(clean_str):
def from_string(variant_string: str, regex_pattern=VARIANT_PATTERN):
# This will only ever match standard (non-symbolic variants)
if full_match := regex_pattern.fullmatch(variant_string):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it did it before, but should this thow an exception if the string doesn't match the pattern?
Most of the code that calls VariantCoordinate.from_string() expects that there will be a value returned and if not, the code will generally do undesirable things like put Nones into lists etc.

Copy link
Contributor Author

@davmlaw davmlaw Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, better safe than sorry

@@ -254,21 +254,6 @@ class VariantCoordinate(FormerTuple):
ref: str
alt: str

def __init__(self, chrom, start, end: int = None, ref: str = None, alt: str = None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though TypeHints might be able to pickup on some bad usage of VariantCoordinate, it's common enough that maybe validation in a post_init(): method might be a good start into "fail early" design.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added simple type checking (not sure what else you want - or whether we can do this automatically off type hints

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re off type hints, found this seems designed specifically to ensure a dataclass has all the correct values
https://pypi.org/project/enforce-typing/

(we can introduce that as work after the merge to stop holding the merge back if you'd prefer)

# Below this size, variants are stored with ref/alt sequences. Above this threshold, they become
# structural variants and use symbolic
VARIANT_SYMBOLIC_ALT_SIZE = 1000
VARIANT_SYMBOLIC_ALT_VALID_TYPES = {"<DEL>", "<DUP>", "<INS>", "<CNV>"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the biggest deal, but should all these be constants as they're referred a few times throughout.
They're small and standard enough that I'm not overly concerned if you'd prefer to leave them as strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, did this just running tests

@TheMadBug TheMadBug merged commit 381e222 into master Sep 13, 2023
3 checks passed
@TheMadBug TheMadBug deleted the feature/cnv_final branch September 13, 2023 03:04
TheMadBug pushed a commit that referenced this pull request Sep 13, 2023
* #54 - CNV off latest master

* #54 - Fixes from code review, change "variant_tuple" to variant_coordinate everywhere

* #54 - Fixes from code review

* VariantCoordinate error checking (from code review)

* #54 - code review - move symbolic alleles into constants rather than magic strings everywhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants