Skip to content

Commit

Permalink
Merge pull request #3 from Australian-Structural-Biology-Computing/up…
Browse files Browse the repository at this point in the history
…date-fasta-creation

fix(fasta): Removed space from FASTA header file
  • Loading branch information
nbtm-sh authored Nov 1, 2024
2 parents 4bf73a8 + 7634823 commit af0df6d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions create_samplesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@ def read_fasta(fp, read_data=False, single_line=True):
lines = fasta_fp.readlines()
logger.debug(f"Fasta content {lines}")

temp_sample_object = None

for fasta_line in lines:
if re.search("^\>( ?).*$", fasta_line):
fasta_samples.append(Sample(fasta_line[1:].strip(), fp, None))
# This is to add support for fixed-width fasta files
if temp_sample_object is not None:
fasta_samples.append(temp_sample_object)
temp_sample_object = Sample(fasta_line[1:].strip(), fp, None)
if single_line:
break
else:
temp_sample_object.data += fasta_line.strip()

fasta_fp.close()
logger.debug(f"Number of samples in {fp}: {len(fasta_samples)}")
Expand All @@ -51,7 +58,7 @@ def file_name(sample_id, prefix='manual_entry', suffix='af2', delim='-', extensi
return ''.join([prefix, delim, sample_id, delim, suffix, '.', extension])

def make_fasta(aa_seq, sample_name, fp, header='>'):
fp.write(f"{header} {sample_name}\n{aa_seq}")
fp.write(f"{header}{sample_name}\n{aa_seq}")
fp.flush()

def create_csv(data, header_seq, header_fasta, fp):
Expand Down

0 comments on commit af0df6d

Please sign in to comment.