Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Request command line option to abort on file overwrite #276

Closed
hjmjohnson opened this issue Feb 26, 2019 · 2 comments
Closed

ENH: Request command line option to abort on file overwrite #276

hjmjohnson opened this issue Feb 26, 2019 · 2 comments

Comments

@hjmjohnson
Copy link

There are times when the same dcm2niix command may accidentally be run for the same inputs/outputs.

It would be nice if dcm2niix had a command line option to simply abort if the action would result in overwriting an existing file of the same name.

## -w write output behavior ( 0 = write nothing for a file that exists with desired name  1 = overwrite existing file with same name, default 2 = write with new suffix as a new file ) 

dcm2niix -w -b y -z y -f %p_%t_%s -o my_img dcm_dir  #<- Results in a new image written my_img_blah_blah_blah.nii

dcm2niix -w -b y -z y -f %p_%t_%s -o my_img dcm_dir  #<- Results nothing written to disk, but a warning "Filename: my_img_blah_blah_blah.nii, already exists, 

Currently I write the file to a temporary location, use bash to see if the file exists in the final location, and then move or delete the temporary files.

Thank you for your consideration.

@neurolabusc
Copy link
Collaborator

neurolabusc commented Feb 27, 2019

@hjmjohnson

Can you test the latest developmental commit? It includes the feature you request.

-w : write behavior for name conflicts (0,1,2, default 2: 0=skip duplicates, 1=overwrite, 2=add suffix)

I do have a few comments:

  • The overwrite option will delete all pre-existing matching files with the extensions [.nii,.nii.gz, .nrrd, .nhdr, .raw.gz, .json, .bval, .bvec]. In other words, if a T1 scan overwrites a DWI scan we want to make sure that we not only overwrite the NIfTI image but also eliminate the DWI's associated bval/bvec files.
  • Note that the command impacts file overwrites both within and between calls to dcm2niix. In other words, consider a study where a T1, T2 and fMRI scan are all acquired in the same session. Running the command "dcm2niix -f %t ~/myDir" does not disambiguate between these different images, since they have the same study time. If this is done with the default dcm2niix -f %t -w 2 ~/myDir then the user will get three images 20081029124138.nii, 20081029124138a.nii, 20081029124138b.nii. However, running dcm2niix -f %t -w 0 ~/myDir or dcm2niix -f %t -w 1 ~/myDir will only create a single image as output (albeit warnings are generated). Clearly, the user should be requesting a better file name, e.g. dcm2niix -f %t_%s -w 0 ~/myDir disambiguates between the different image series. For a beginning user, it may be unclear why only one image was created. Therefore, this is a pretty advanced option with potential for unintended consequences.

@hjmjohnson
Copy link
Author

@neurolabusc Thank you for this. I'll test during my next data migration over the next month.

yarikoptic added a commit to neurodebian/dcm2niix that referenced this issue May 6, 2020
* tag 'v1.0.20190410': (52 commits)
  Update dcm_qa submodule.
  Prevent MSVC compilation warnings
  Siemens PASL 3D BIDS tags (http://adni.loni.usc.edu/wp-content/uploads/2010/05/ADNI3_Basic_Siemens_Skyra_E11.pdf)
  Reduce Microsoft Visual Studio 14 warnings (rordenlab#288)
  Use fgets not getline (rordenlab#288)
  Fixes (rordenlab#286; rordenlab#287)
  Added missing space (coding standard).
  Supported dicom tag Accession Number (0008,0050). Struct TDICOMdata extended with accessionNumber property, modified dicom loader and supported exporting accession number into json file and using it as filename with %g modifier.
  Terminate when corrupted DICOM detected (rordenlab#283)
  Keep more characters for institution address (VR is ST)
  "dcm2niix -v" returns version (rordenlab#280)
  NRRD export supports oldmin/oldmax (http://teem.sourceforge.net/nrrd/format.html#oldmin)
  Assume 1.2.840.10008.1.2 if transfer syntax is empty
  Option to modify overwrite behavior (rordenlab#276)
  XA11 classic DICOM uses private tags for DWI (rordenlab#274)
  Detect Philips when manufacturer (0008,0070) has been erased (rordenlab#267)
  Detect discrepancies in PAR/REC slice thicknesses (rordenlab#273)
  New "-x i" option (https://www.nitrc.org/forum/forum.php?thread_id=9324&forum_id=4703)
  bvecs for Philips DWI using  0019,10bb, 0019,10bc
  Adjust negative MosaicRefAcqTimes (rordenlab#271)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants