trimal icon indicating copy to clipboard operation
trimal copied to clipboard

readAl / trimAl creates an empty file when trying to output a non-aligned format/alignment to an aligned-format.

Open Vicfero opened this issue 8 years ago • 1 comments

Both programs output an empty file when given a non-aligned file / alignment (ex: dataset/example.007.AA.only_seqs) and asked to save in a alignment-format (clustal, phylip, etc)

The program warns about this problem, but the check is done in functions 'alignmentXToFile' when the file has been created. The problem seems to be on function "alignment::saveAlignment(char *destFile)" on "alignment.cpp", line 607-673:

bool alignment::saveAlignment(char *destFile) {

  ofstream file;

  if(sequences == NULL)
    return false;

  if((residNumber == 0)  || (sequenNumber == 0)) {
    cerr << endl << "WARNING: Output alignment has not been generated. "
      << "It is empty." << endl << endl;
    return true;
  }

  /* File open and correct open check */
  file.open(destFile);
  if(!file) return false;

  /* Depending on the output format, we call to the appropiate function */
  switch(oformat) {
    case 1:
      alignmentClustalToFile(file);
      break;
    case 3:
      alignmentNBRF_PirToFile(file);
      break;
    case 8:
      alignmentFastaToFile(file);
      break;
    case 11:
      alignmentPhylip3_2ToFile(file);
      break;
    case 12:
      alignmentPhylipToFile(file);
      break;
    case 13:
      alignmentPhylip_PamlToFile(file);
      break;
    case 17:
      alignmentNexusToFile(file);
      break;
    case 21: case 22:
      alignmentMegaToFile(file);
      break;
    case 99:
      getSequences(file);
      break;
    case 100:
      alignmentColourHTML(file);
      break;
    default:
      return false;
  }

  /* Close the output file */
  file.close();

  /* All is OK, return true */
  return true;
}

The warning of this problem:

ERROR: Sequences are not aligned. Format (X) not compatible with unaligned sequences.

Is done after opening the ofstream, thus, making an empty file.

Vicfero avatar Aug 04 '17 10:08 Vicfero

Please, @Vicfero check which formats require sequences to be aligned.

scapella avatar Aug 10 '17 14:08 scapella