-
Notifications
You must be signed in to change notification settings - Fork 0
/
corrected_effect_on_assembly.js
129 lines (106 loc) · 4.31 KB
/
corrected_effect_on_assembly.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const fs = require('fs');
const sh = require('shelljs');
const in_all_id =process.argv[2];
const in_raw_reads_assembly_dir = process.argv[3];
const in_corrected_reads_assembly_dir = process.argv[4];
const ids = fs.readFileSync(in_all_id).toString().split('\n').slice(0, -1);
for (id of ids ){
//console.log(id);
let raw_reads_contigs_file = sh.ls(in_raw_reads_assembly_dir + "/" + "Contigs_1_" + id + "_chloro.fasta");
//console.log(raw_reads_contigs_file);
let raw_reads_assembly_file = sh.ls(in_raw_reads_assembly_dir + "/" + "Option_1_" + id + "_chloro.fasta");
let raw_reads_Circularized_file = sh.ls(in_raw_reads_assembly_dir + "/" + "Circularized_assembly_1_" + id + "_chloro.fasta");
let corrected_reads_contigs_file = sh.ls(in_corrected_reads_assembly_dir + "/" + "Contigs_1_" + id + "_chloro.fasta");
let corrected_reads_assembly_file = sh.ls(in_corrected_reads_assembly_dir + "/" + "Option_1_" + id + "_chloro.fasta");
let corrected_reads_Circularized_file = sh.ls(in_corrected_reads_assembly_dir + "/" + "Circularized_assembly_1_" + id + "_chloro.fasta");
//console.log(id + "\t" + raw_reads_contigs_file[0]);
let output = id;
if (raw_reads_contigs_file[0]){
//console.log(id + "\t" + read_fasta(raw_reads_contigs_file[0]));
let seqLensArray = read_fasta(raw_reads_contigs_file[0]);
if (seqLensArray.length > 0){
output += "\t" + seqLensArray.length + "\t" + seqLensArray.join(',');
}else{
output += "\t" + "NA" + "\t" + "NA";
}
//console.log(seqid_length[0] + seqid_length[1]);
}else{
output += "\t" + "NA" + "\t" + "NA";
}
if (raw_reads_assembly_file[0]){
//console.log(id + "\t" + read_fasta(raw_reads_contigs_file[0]));
let seqLensArray = read_fasta(raw_reads_assembly_file[0]);
if (seqLensArray.length > 0){
output += "\t" + seqLensArray.length + "\t" + seqLensArray.join(',');
}else{
output += "\t" + "NA" + "\t" + "NA";
}
//console.log(seqid_length[0] + seqid_length[1]);
}else{
output += "\t" + "NA" + "\t" + "NA";
}
if (raw_reads_Circularized_file[0]){
//console.log(id + "\t" + read_fasta(raw_reads_contigs_file[0]));
let seqLensArray = read_fasta(raw_reads_Circularized_file[0]);
if (seqLensArray.length > 0){
output += "\t" + seqLensArray.length + "\t" + seqLensArray.join(',');
}else{
output += "\t" + "NA" + "\t" + "NA";
}
//console.log(seqid_length[0] + seqid_length[1]);
}else{
output += "\t" + "NA" + "\t" + "NA";
}
if (corrected_reads_contigs_file[0]){
//console.log(id + "\t" + read_fasta(raw_reads_contigs_file[0]));
let seqLensArray = read_fasta(corrected_reads_contigs_file[0]);
if (seqLensArray.length > 0){
output += "\t" + seqLensArray.length + "\t" + seqLensArray.join(',');
}else{
output += "\t" + "NA" + "\t" + "NA";
}
//console.log(seqid_length[0] + seqid_length[1]);
}else{
output += "\t" + "NA" + "\t" + "NA";
}
if (corrected_reads_assembly_file[0]){
//console.log(id + "\t" + read_fasta(raw_reads_contigs_file[0]));
let seqLensArray = read_fasta(corrected_reads_assembly_file[0]);
if (seqLensArray.length > 0){
output += "\t" + seqLensArray.length + "\t" + seqLensArray.join(',');
}else{
output += "\t" + "NA" + "\t" + "NA";
}
//console.log(seqid_length[0] + seqid_length[1]);
}else{
output += "\t" + "NA" + "\t" + "NA";
}
if (corrected_reads_Circularized_file[0]){
//console.log(id + "\t" + read_fasta(raw_reads_contigs_file[0]));
let seqLensArray = read_fasta(corrected_reads_Circularized_file[0]);
if (seqLensArray.length > 0){
output += "\t" + seqLensArray.length + "\t" + seqLensArray.join(',');
}else{
output += "\t" + "NA" + "\t" + "NA";
}
//console.log(seqid_length[0] + seqid_length[1]);
}else{
output += "\t" + "NA" + "\t" + "NA";
}
console.log(output);
}
function read_fasta(inFastaFile){
let faLines = fs.readFileSync(inFastaFile).toString().split(">");
let seqLens = [];
for(let i=1; i<faLines.length; i++){
//console.log(lines[i]);
let id = faLines[i].split("\n")[0].split(/\s+/)[0];
//console.log(id);
let seq = faLines[i].split("\n").slice(1).join('');
//console.log(id + "\t" + seq.length);
//totalLength += seq.length;
seqLens.push(seq.length);
//seqDict[id] = seq.length;
}
return seqLens;
}