-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4f8cdb
commit 7f8c57b
Showing
18 changed files
with
450 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
import click | ||
import os | ||
import csv | ||
|
||
@click.command() | ||
@click.option("-n", "--sample-name", default="", help="Sample Name.") | ||
@click.option("-o", "--output-csv", default="", help="output csv file") | ||
@click.option("-s", "--sep", default="\t", help="csv file separator") | ||
@click.argument("input_csv", nargs=-1) | ||
def reformat_csv(sample_name, output_csv, input_csv, sep): | ||
|
||
for csvfile in input_csv: | ||
with open(csvfile, "r", encoding="utf8") as in_file: | ||
csvreader = csv.DictReader(in_file, delimiter=sep) | ||
header = csvreader.fieldnames | ||
header[0] = "sampleid" | ||
|
||
rows = [] | ||
for row in csvreader: | ||
row[header[0]] = sample_name | ||
rows.append(row) | ||
|
||
with open(output_csv, "w") as file: | ||
writer = csv.DictWriter(file, fieldnames=header, delimiter=sep) | ||
writer.writeheader() | ||
writer.writerows(rows) | ||
|
||
if __name__ == "__main__": | ||
reformat_csv() |
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
Oops, something went wrong.