Skip to content

Commit

Permalink
doesn't add empty seqs to fasta files and alwyas writes intermediate …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
averissimo committed May 19, 2016
1 parent 3768eb6 commit 4d09641
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/blast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ def load_blastdb_item(db, items = nil)
true
end

def get_nt_seq_from_blastdb(seq_id, db, start_idx, end_idx, frame)
def get_nt_seq_from_blastdb(seq_id, db, start_idx, end_idx, _frame)
output = ''
start_idx = Integer(start_idx)
end_idx = Integer(end_idx)
# frame has been discontinued as there are cases where
# it does not hold true with start_idx and stop_idx
frame = Integer(frame)
# frame = Integer(frame)
begin
load_blastdb_item(db)
output = @blastdb_cache[db][seq_id]
Expand Down
45 changes: 30 additions & 15 deletions src/results_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,25 @@ def add_info(keys, values, new_col_key, new_col_val, file_origin = nil)
end
end

def write_deleted(row)
def write_deleted(row = nil)
if @deleted.nil?
@deleted = open_2_write(@output_dir, Reporting::FILE_DISCARDED)
write_headers(@deleted)
end
write(@deleted, row)
write(@deleted, row) unless row.nil?
end

def write_headers(fid)
fid.write header.join("\t")
fid.write header_meaning.join("\t")
end

def write_redundant(row)
def write_redundant(row = nil)
if @redundant.nil?
@redundant = open_2_write(@output_dir, Reporting::FILE_REDUNDANT)
write_headers(@redundant)
end
write(@redundant, row)
write(@redundant, row) unless row.nil?
end

def write(fid, row)
Expand Down Expand Up @@ -238,6 +238,10 @@ def write_trimmed(parent_path, filename)
end

def write_results(parent_path, filename, cols)
# write empty files if necessary
write_redundant
write_deleted
#
CSV.open(File.join(parent_path, filename),
'wb',
col_sep: "\t") do |csv|
Expand Down Expand Up @@ -275,7 +279,7 @@ def write_fasta_each(fasta_db, type, origin, filename, fasta_files)
origin.to_s + '_' + fasta_db.to_s + '_' + filename),
'wb',
col_sep: "\t") do |fid|
fid.write fasta_files[fasta_db][type][origin].join("\n")
fid.write fasta_files[fasta_db][type][origin].join('')
end
logger.info "Finished writing #{origin}-#{filename}."
end
Expand All @@ -294,19 +298,30 @@ def gather_fasta
#
#
#
#byebug if line['sseqid'] == 'comp3298_c0_seq1'
custom_seqid = ">#{line['sseqid']}-#{line['db']}-#{line['qseqid']}"
fasta_files[line['db']][:nt][:aligned] << custom_seqid
fasta_files[line['db']][:aa][:aligned] << custom_seqid
seqid = "#{line['sseqid']}-#{line['db']}-#{line['qseqid']}"
#
#
nt_a_l = line['nt_aligned_longest_orf']
fasta_files[line['db']][:nt][:aligned] << \
Bio::Sequence.auto(nt_a_l)
.output(:fasta, header: seqid) if nt_a_l.length > 0
#
aa_a_l = line['aa_aligned_longest_orf']
fasta_files[line['db']][:aa][:aligned] << \
Bio::Sequence.auto(aa_a_l)
.output(:fasta, header: seqid) if aa_a_l.length > 0
#
#
fasta_files[line['db']][:nt][:db] << custom_seqid
fasta_files[line['db']][:aa][:db] << custom_seqid
nt_d_l = line['nt_db_longest_orf']
fasta_files[line['db']][:nt][:db] << \
Bio::Sequence.auto(nt_d_l)
.output(:fasta, header: seqid) if nt_d_l.length > 0
#
fasta_files[line['db']][:nt][:aligned] << line['nt_aligned_longest_orf']
fasta_files[line['db']][:aa][:aligned] << line['aa_aligned_longest_orf']
aa_d_l = line['aa_db_longest_orf']
fasta_files[line['db']][:aa][:db] << \
Bio::Sequence.auto(aa_d_l)
.output(:fasta, header: seqid) if aa_d_l.length > 0
#
fasta_files[line['db']][:nt][:db] << line['nt_db_longest_orf']
fasta_files[line['db']][:aa][:db] << line['aa_db_longest_orf']
end
fasta_files
end
Expand Down

0 comments on commit 4d09641

Please sign in to comment.