-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture column names and Regex column name matching (#135)
* Allow regexp column names * Map column name to field * Regexp column name testing * Store column name tests * Documentation * Changelog * Add a slightly convoluted test * Mutate regex column names while iterating * Use `match?` instead of `=~` as a conditional * typos
- Loading branch information
1 parent
8ae9027
commit f07c39e
Showing
9 changed files
with
194 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
layout: page | ||
title: Capturing Column Names in Mapped Data | ||
permalink: /capturing-column-names/ | ||
--- | ||
|
||
Column names themselves may contain data that should be included in each record. For example VCF files have a column name that is a Lab Number and it should be included on all records. | ||
|
||
In order to store the column name in each record, include the `map_columname_to` key at the column level, with the value being the desired field and rawtext name. | ||
|
||
|
||
Example mapping | ||
|
||
--- | ||
- column: column_one | ||
mappings: | ||
- field: field_one | ||
- column: abc123 | ||
map_columname_to: 'columnname_field' | ||
mappings: | ||
- field: field_two | ||
|
||
Example data: | ||
|
||
``` | ||
"column_one","abc123" | ||
"one","two" | ||
``` | ||
|
||
This would result in: | ||
|
||
``` | ||
{ 'field_one' => 'one', | ||
'columnname_field' => 'abc123', | ||
'field_two' => 'two', | ||
rawtext: { 'column_one' => 'one', 'abc123' => 'two', 'columnname_field' => 'abc123' } } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
layout: page | ||
title: Regular Expression Column Names | ||
permalink: /regexp-column-names/ | ||
--- | ||
|
||
Column names may differ between files, for example a lab number might be used a column name. In order to map the column, the column name can be a regular expression. | ||
|
||
If the regular expression matches the column name in the raw file, the data will be mapped and loaded as expected. | ||
|
||
If the regular expected does not match the column name, a column header error will be raised. | ||
|
||
Example mapping | ||
|
||
--- | ||
- column: /\A[A-Z]+\d{3}\z/i | ||
mappings: | ||
- field: regex_field | ||
- column: two | ||
mappings: | ||
- field: two | ||
|
||
Example data: | ||
|
||
``` | ||
"abc123","two" | ||
"regex_value","string_value" | ||
``` | ||
|
||
This would result in: | ||
|
||
``` | ||
{ 'regex_field' => 'regex_value', 'two' => 'string_value' }, | ||
rawtext: { 'regex_field' => 'regex_value', 'two' => 'string_value' } } | ||
``` | ||
|
||
However, the below data: | ||
|
||
``` | ||
"1234abc","two" | ||
"regex_value,string_value" | ||
``` | ||
|
||
would result in a RuntimeError: 'Header is not valid! unexpected: ["1234abc"]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters