-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert.js
77 lines (65 loc) · 2.41 KB
/
convert.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const fs = require('fs');
const csv = require('csv-parser');
const readlineSync = require('readline-sync');
const filename = 'MyHeritage_raw_dna_data.csv';
const headers = ['rsid', 'chromosome', 'position', 'genotype'];
function readCSVData(filename) {
return new Promise((resolve, reject) => {
const data = [];
fs.createReadStream(filename)
.pipe(csv({ headers, skipComments: true }))
.on('data', (row) => {
data.push(row);
})
.on('end', () => {
resolve(data);
})
.on('error', (error) => {
reject(error);
});
});
}
async function convertData() {
try {
const data = await readCSVData(filename);
const currentDateTime = new Date().toLocaleString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
});
const comments = `# This data file generated by 23andMe at: ${currentDateTime}
#
# Below is a text version of your data. Fields are TAB-separated
# Each line corresponds to a single SNP. For each SNP, we provide its identifier
# (an rsid or an internal id), its location on the reference human genome, and the
# genotype call oriented with respect to the plus strand on the human reference sequence.
# We are using reference human assembly build 37 (also known as Annotation Release 104).
# Note that it is possible that data downloaded at different times may be different due to ongoing
# improvements in our ability to call genotypes. More information about these changes can be found at:
# https://www.23andme.com/you/download/revisions/
#
# More information on reference human assembly build 37 (aka Annotation Release 104):
# http://www.ncbi.nlm.nih.gov/mapview/map_search.cgi?taxid=9606
#
# rsid chromosome position genotypeJ`;
const firstname =
readlineSync.question("What is your first name? [Joseph] :") || 'Joseph';
const lastname =
readlineSync.question("What is your last name? [Anson] :") || 'Anson';
const outputFilename = `genome_${firstname}_${lastname}_Full_${currentDateTime.replace(
/\W+/g,
''
)}.txt`;
const csv = data
.map(e => Object.values(e).join(" "))
.join("\n");
fs.writeFileSync(outputFilename, comments + "\n" + csv);
console.log('Done :)')
} catch (error) {
console.error('Error occurred:', error);
}
}
convertData();