.CSV file naming by 'Sample Name' field

Hello,

I'm using Report Builder for MassHunter and generating a .csv file for the unknowns analysis and the file name is the Method.csv for each file inside a new folder for each sample.

I would like the .csv file to be named the sample name from the 'Sample Name' field.

May I have some guidance on how to set that up?

Thank you.

Parents
  • All of my .csv files are named for the method.

    I went to the linux server command line and

     

    >ls | while read file; do newfile=`echo $file | awk -F"," 'NR==5 {print $2 ".csv"}' ElementLimited.csv`; echo $newfile; mv $file $newfile; done;

    to rename the files, but this is extra work.

    I want the MassHunter unknowns analysis to save the .csv-file as 'sample name.csv'

     

    Any help?

Reply
  • All of my .csv files are named for the method.

    I went to the linux server command line and

     

    >ls | while read file; do newfile=`echo $file | awk -F"," 'NR==5 {print $2 ".csv"}' ElementLimited.csv`; echo $newfile; mv $file $newfile; done;

    to rename the files, but this is extra work.

    I want the MassHunter unknowns analysis to save the .csv-file as 'sample name.csv'

     

    Any help?

Children
  • Hi ,

    What version of quant/UA are you using? This can be found in the Help->About menu.

    Which Report Builder template are you using, or if you have customized a template, which template did you base your current template on?

    Which Report mode are you using? Batch or Single Sample? If you run in Batch mode there will be one report file containing the results for all samples with the same name as the report template. If you run in Single Sample mode then each sample's file will start with the name of the template and then use the data file name for the suffix, like this

     

    It is possible to add a Post Process in the Report Method Editor that can automatically move these files to another location using a batch file. It may be possible to perform other manipulations as well. Let me know how you are making the report files and we can go from there. 

  • I'm using MassHunter Workstation Quantitative Analysis Unknowns Analysis Version 10.1

     

     

     

    I started with LSRNonTarget_Details.template.xml and edited it to my needs & saved as ElementLimited.template.xml

    I'm reporting in single sample mode.

    my post-process is performed as server admin from the cmd line on a Linux server

    cd /to the directory of the UnknownsReports for the current project

     

    #FROM PARENT DIRECTORY rename all ElementLimited.csv to 'LIMS SAMPLE Number.csv'  ALL AT ONCE

    >for d in ./*/ ; do (cd "$d" &&  ls | while read file; do newfile=`echo $file | awk -F"," 'NR==5 {print  $2 ".csv"}' ElementLimited.csv`; echo $newfile;  mv $file $newfile; done;); done

     

    #FROM PARENT DIRECTORY copy *.csv files to parent directory

    >cp */.csv '%PARENT DIRECTORY TYPED OUT%'

    If these above post-process steps are more easily performed using a Microsoft Batch file and performed within Masshunter Unknowns Analysis, that would be great.

     

     

     

    EDIT-removed lines from email response

  • ,

    Report post processing utilizes batch files. There are some default shipping files in the following location

     

    D:\MassHunter\Scripts\Quant\Report

     

    While these are in the Quant folder they can be used for either Quant or UA reporting.

     

    As a test for this I modified some code I found at StackOverflow and combined it with one of the shipping .bat files as follows. (I have attached this as a .txt file. Download and rename to .bat)

     

    REM ================================================================================================
    REM Program:       RenameCSV_SampleName.Bat
    REM Description: Rename reports generated in .csv format to the text found after 'Sample Name,' entry in file.
    REM Requires:       "$(DestinationFilePath)" Argument entered in the Post Process Editing Window, including quotes
    REM Note:       This does not check to see if Sample Name would be a valid Windows file name or if there are duplicate sample names.
    REM Note:       This is only intended as an exmample of what can be done with Post Processing batch files. Please modify and test appropiately.
    REM Log:      PostReportProcess.log is generated to record the status of the process 
    REM Scope:      This is intended for use in Single Sample mode
    REM ================================================================================================


    @setlocal enableextensions enabledelayedexpansion
    @echo on

    set dir=%~dp1

    echo Current directory is: !dir!

    cd /d %dir%

    echo %date% %time% >PostReportProcess.log
    for %%i in (*.csv) do (
      for /f "tokens=2 delims=," %%j in ('findstr /B /I "Sample Name," "%%i"') do (
        ren "%%i" "%%j.temp_txt"
      )
    ) >>PostReportProcess.log 2<&1

    ren *.temp_txt *.csv

    endlocal

    REM pause

     

    This will change directory to the current reporting path and rename all .csv files in that directory to be whatever is found after the text 'Sample Name,' in the file. As noted this does no error checking, either for valid or duplicate file names, and I have only done limited testing. Modify and test accordingly.

     

    Copy or create this batch file in the default report scripting folder shown above.

     

    To utilize the Post Process in your Reporting method, first expand the window so that the entire row can be seen. The Post Process drop down is the very last column on the Templates tab. To create or edit a Post Process, click on the button in the lower right hand corner.

     

     

    Then choose to create a New Post Process and set it up like this

     

    After clicking OK you will have this Task name as a choice in the Post Process drop down. 

     

    Now when the reporting method is run, after the files are created they will be renamed. For the demo files I was working with this is the result.

    You can add any other batch commands you want, such as moving or copying the resulting reports to a network drive, or whatever other tasks you may wish to perform. 

    RenameCSV_SampleName.txt.zip
Was this helpful?