-
Couldn't load subscription status.
- Fork 36
Fixed CLI errors. #268
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
base: master
Are you sure you want to change the base?
Fixed CLI errors. #268
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,51 @@ | |
|
|
||
|
|
||
|
|
||
| def canonicalize_columns(columns): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "canonicalize" -> "standardize" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make it a function with a single argument. |
||
| """Convert between common column name variants.""" | ||
| canonical_map = { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the dictionary to https://github.com/open2c/pairtools/blob/master/pairtools/lib/pairsam_format.py There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove identities (when key equals the value) |
||
| 'chr1': 'chrom1', | ||
| 'chr2': 'chrom2', | ||
| 'chrom1': 'chrom1', # Ensure identity mapping | ||
| 'chrom2': 'chrom2', | ||
| 'pt': 'pair_type', | ||
| 'pair_type': 'pair_type' | ||
| } | ||
| return [canonical_map.get(col.lower(), col) for col in columns] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. canonical_map.get(col.lower(), col.lower()) |
||
|
|
||
| def get_column_index(column_names, column_spec): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "column_spec" -> "column/col" |
||
| """Get column index with flexible name matching.""" | ||
| if isinstance(column_spec, int): | ||
| if -len(column_names) <= column_spec < len(column_names): | ||
| return column_spec % len(column_names) # Handle negative indices | ||
| raise ValueError(f"Column index {column_spec} out of range") | ||
|
|
||
| if not isinstance(column_spec, (str, int)): | ||
| raise AttributeError(f"Column spec must be string or integer, got {type(column_spec)}") | ||
|
|
||
| # Try direct match first | ||
| try: | ||
| return column_names.index(column_spec) | ||
| except ValueError: | ||
| pass | ||
|
|
||
| # Try canonical name | ||
| canonical = canonicalize_columns([column_spec])[0] | ||
| try: | ||
| return column_names.index(canonical) | ||
| except ValueError: | ||
| pass | ||
|
|
||
| # Try case-insensitive | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the case-insensittive law or explain why it's needed (we have not found the usecase; Open2C mtg 30 June 2025) |
||
| lower_columns = [c.lower() for c in column_names] | ||
| try: | ||
| return lower_columns.index(canonical.lower()) | ||
| except ValueError: | ||
| available = ', '.join(f"'{c}'" for c in column_names) | ||
| raise ValueError( | ||
| f"Column '{column_spec}' not found. Available columns: {available}" | ||
| ) | ||
|
|
||
| def get_header(instream, comment_char=COMMENT_CHAR, ignore_warning=False): | ||
| """Returns a header from the stream and an the reaminder of the stream | ||
| with the actual data. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the names like "col1/col2/cols1" are not descriptive enough, so maybe use "col_c1/col_c2/col_s1" instead: (1) use underscore, (2) preserve the recognizable name that was used before (c1/c2/p1/p2/etc.).